Having a home security system is crucial for protecting your home and family. As technology advances, DIY voice-activated security systems using Raspberry Pi provide an affordable and customizable option. In this guide, I will walk through the full process of building your own voice-controlled system from start to finish.

Gathering the Necessary Components

The first step is obtaining all of the hardware and software components. Here is what you will need:



Setting Up the Raspberry Pi

With the components ready, it's time to set up the Raspberry Pi. Follow these steps:

Connecting the Components

Next, we need to connect the components to the Raspberry Pi. Here is how to wire it up:

Note: Soldering may be required to connect some components to header pins on the Raspberry Pi.

Installing the Required Software

With the hardware connected, we can now set up the software:

Test importing the libraries in a Python script to verify they are installed correctly.

Coding the Voice Control Functionality

Now for the fun part - coding it up! For voice control, we will:

Here is a code snippet demonstrating the voice control:

import speech_recognition as sr
import pyaudio

MODE_STAY = "arm stay"
MODE_AWAY = "arm away"
DISARM = "disarm"

def ARM_STAY():
print("Armed STAY")

def ARM_AWAY():
print("Armed AWAY")

def DISARM():

r = sr.Recognizer()
m = sr.Microphone()

while True:
with m as source:
audio = r.listen(source)
command = r.recognize_google(audio)
if command == MODE_STAY:
elif command == MODE_AWAY:
elif command == DISARM:

This allows arming and disarming the system by voice!

Adding Motion Detection and Alerts

To complete the security functions, we need to:

The OpenCV library enables processing images from the camera module.

Here is sample code for the motion detection logic:

import sqlite3
import cv2

Configure motion sensor on GPIO4


Database for storing events

DB_NAME = "security.db"

def MOTION_DETECTED(channel):
print("Motion Detected!")
# Capture image from camera module
image = capture_image()
# Save image and event data to database
# Play alert sound

Set pin as input and enable interrupt


The full system combines the voice control, motion detection, and alerting for a DIY home security system!


Building your own voice-controlled home security system with Raspberry Pi is totally doable with basic coding skills and electronics knowledge. The key steps are gathering the components, wiring it up, installing the software, coding the functionality, and testing it out. With some effort, you can have an affordable intelligent security system protecting your home. This project is fun, educational, and practical - give it a try!