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
- Raspberry Pi
- 433 MHz Transmitter/Receiver $2.77- http://www.ebay.com/itm/121117930415?ssPageName=ST...
- Note that I only used the transmitters here. The receivers were of poor quality and the superheterodyne receiver below was the one I landed up using finally. You could only purchase the transmitters to reduce the cost.
- 433 MHz Super Heterodyne Receiver $5.99 - http://www.ebay.com/itm/280936648330?ssPageName=ST...
- 4x3 Membrane Keypad $3.95 - http://www.adafruit.com/products/419
- 433Mhz Piezo Siren $17.91 - http://www.ebay.com/itm/433MHz-Wireless-Strobe-Li...
- The hardware below is what I used for this project - You can always get more of each based on your requirements:
- 4x 433 MHz door/window sensors $12.99 - http://www.ebay.com/itm/190940498983?ssPageName=ST...
- 2x 433 MHz PIR Motion sensors $17.16 - http://www.ebay.com/itm/433Mhz-Wireless-PIR-Motion...
- 3x 433 MHz Remote controlled wall outlets $25 - http://www.dbtechusa.com/#!remote-control-outlet/c...
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
- 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
- Go to the webpage - RaspberryPi_IP_Address:webserver_port
- Click on the switch 1/2/3 to verify that the outlets turn on/off
- 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!

Participated in the
Home Automation
13 Comments
4 years ago
Hi, Thx for sharing your project! I giving it a try. Have a question...Is there support for my ever changing outside IP address? or is it ok for me to go ahead and use like duckdns and if I do this do I have to incorporate this at all into yours or Webiopi code or can I just run it on the pi by itself? Hope the question was clear. I need to be able to use a domain cause my outside ip is always changing.
any help would be appreciated
Thanks
7 years ago on Introduction
Your received data signal is 5V, since you power the receiver from 5V.
Are the GPIO inputs 5V safe?
Reply 6 years ago
You are right - you may blow out the pins @5V -> the voltage from the receiver needs to be brought down to 3.3V. See below for the schematic for doing so with a breadboard.
http://i.imgur.com/IAQNK4Z.jpg
Reply 6 years ago
Here is the image directly:
Reply 6 years ago
Yes you are right. I somehow missed including that. I had it in my original blog post here: http://tkmaker.blogspot.com/2013/11/raspberry-pi-h...
I will fix the instructable. Thanks for pointing it out.
7 years ago on Introduction
Hi,
I'm looking for door sensor that could notify BOTH open / close. Did yours do that?
Reply 7 years ago
These specific ones only send out a code when contact is lost, so only on door/window open action.
7 years ago
What is the effective transmit range of 433MhZ connection you used please?
Reply 7 years ago on Introduction
With a 17cm single core wire antenna attached to the transmitter, I can control outlets that are a 100-200 ft away (through walls). I haven't tested how far they go because it covered the area I wanted. The specs for the hardware say that it should be able to cover ~600ft (probably without any obstructions).
Reply 7 years ago on Introduction
100-200 ft? What sort of walls were they? Even our interior walls are ceiling to floor shiplap on both sides.
Reply 7 years ago
That's right. The walls here are drywall on wood frames so they are not solid through. I have it going through at least 1-2 walls.
7 years ago on Introduction
Nicely done. Thanks for sharing this!
Reply 7 years ago on Introduction
Thanks. Glad to share this.