Introduction: DIY Home Security + Automation Using a Raspberry Pi

This instructable should help you set up a DIY home security + automation system that uses 433Mhz door/window sensors, 433 MHz PIR motion sensors and webcams to monitor your home and 433MHz outlets to control lights etc.

The original project was completed in phases and published on my personal blog at http://tkmaker.blogspot.com/2013/11/raspberry-pi-h.... This instructable is aimed at putting all that information together in one place.

Step 1: Hardware Component List

The total hardware cost was approximately $85 (minus the Raspberry Pi)

Step 2: Hardware Setup


1. To increase the range of the transmitter and receiver, solder a 17cm single core wire to the ANT (antenna) connection on the transmitter and receiver.

2. Connect the DATA output of the transmitter to GPIO 17 of the Raspberry Pi (rev B in my case)Connect the DATA output of the transmitter to GPIO 17 of the Raspberry Pi (rev B in my case)

3. The 433MHz receiver output is 5V so use a simple voltage divider circuit (220 ohm/440 ohm) to drop the voltage down to 3.3V. Connect the output of the voltage divider to GPIO 21

4. Connect the VCC/GND pins of the 433MHz Rx/Tx to the Raspberry Pi 5V/GND lines

5. The 4x3 membrane keypad is connected as follows:


• Pin 7 on the keypad is ROW 0- GPIO 18
• Pin 6 on the keypad is ROW 1- GPIO 23
• Pin 5 on the keypad is ROW 2- GPIO 24
• Pin 4 on the keypad is ROW 3- GPIO 25
• Pin 3 on the keypad is COL 0 - GPIO 4
• Pin 2 on the keypad is COL 1 - GPIO 22
• Pin 1 on the keypad is COL 2 - GPIO 10




Step 3: Install Prerequisite Software + Source Code



1. Install WebIOPi from here: http://www.themagpi.com/issue/issue-9/article/web...
2. Install motion for webcam motion detection: sudo apt-get install motion

• For details on how to setup motion, take a look at my post here: http://tkmaker.blogspot.com/2013/11/raspberry-pi-...



3. I found this article on using 433MHz Tx-Rx modules with the raspberry pi. Follow the instructions here to install the 433Utils package. http://ninjablocks.com/blogs/how-to/7506204-addin...

• Run RFSniffer and trigger all the 433MHz door/window/PIR motion sensors that you want to use and note down the received code. This will be used to trigger the alarm in your system.

4. Clone my git repo for the source code from here: https://github.com/tkmaker/RaspberryPiHomeAlarm to any directory

5. Go back to the directory where you installed the code from the ninjablocks website in step #3

  • Modify RFSniffer.cpp to write to trigger.txt in the cloned repo, if the code matches your specific transmitters:

if (value == 0) { printf("Unknown encoding"); } else { printf("Received %i\n", mySwitch.getReceivedValue() ); if (mySwitch.getReceivedValue() == enter your transmitter code here ) { system("sudo echo -n 1 > path_to_git_code/trigger.txt"); } }

• Modify send.cpp line 24 to change the pulse length to 207. The wireless outlet controls had a different pulse length vs the default one. • Run a "make" in the RPi_utils directory to create an updated executable.

6. Modify the following in the directory cloned from git in step #4

config.py -
• Modify the root directory where you have cloned the git repo above based on the variable config['home_alarm_git_dir']
• Modify the directory where you have cloned the 433MHz code from te ninjablocks website mentioned in #3 above based on the variable config['rf433_dir']
• Modify the passcode to arm/disarm the system from the keypad. Default is 123
• Modify the RF outlet codes to switch the outlets on/off. I used 3 switches in this project
• Modify the RF siren enable/disable code
• If you want to use a webcam for motion enable set the variable config['webcam_motion_enable'] = 1

intruder_mail.sh - Modify your destination email via the dest variable . You can also customize your email subject/message in this script. I am using smttp for sending the email. See this post for instructions on how to set it up https://www.raspberrypi.org/forums/viewtopic.php?...




Step 4: Code Flow

The diagrams show the flow of the 2 main scripts used here:



• control.py - High level control script. Checks for the system arm/disarm based on user triggered actions on the webserver or the keypad
• alarm.py - Main script that waits for the system to be armed and triggers the 433 MHz RF Sniffer script. This script waits for transmissions from the door/window sensors or PIR motion sensors and triggers the siren if any of the sensors are triggered.


Step 5: Launch the Script and Test Out the System

  1. Launch the script - webserver_port here is the port of your choice defined in config.py where the web based user interface pictured above will run.
    • sudo python control.py -m webiopi -d webserver_port

  2. Go to the webpage - RaspberryPi_IP_Address:webserver_port
  3. Click on the switch 1/2/3 to verify that the outlets turn on/off
  4. Click on the System Arm switch and wait a minute till the system is fully armed
    • To test out the RF siren and only trigger the flashing lights (without triggering the sound) disconnect the piezo siren using the connector labelled in the image of the siren above.
    • Open/close the doors/windows where you have attached the RF door/window sensors - Verify that the alarm is triggered and you get an email. Disarm the system using the webpage switch or the keypad code.
    • Move in front of the RF PIR sensors and repeat the above experiment.

If everything above checks out, you are good to go!

Home Automation

Participated in the
Home Automation