I wanted to make an inexpensive home security and automation system with the following goals:
- Home security system controlled by the internet or a 4x3 keypad
- Use 433MHz Door/window sensors to trigger an alarm
- Use 433MHz wireless switches to control home lighting
- Actions on alarm trigger - Siren and send out an email/tweet
- Future enhancements - Laser trip wires!
Update 1: I added 2 webcams to the system and any motion now triggers an alarm as well.
Update 2: Check out phase 2 of the project here, which adds internet controlled outlet switches.
Update 3: Check out phase 3 of the project here, which adds a wireless siren + a demo video of the system.
Update 4: I swapped the 433Mhz receiver for a much better one based on reader Kris's feedback. Updated original post below.
Update 5: The information from all the phases of this project have been consolidated and written up as an instructable here: http://www.instructables.com/id/DIY-Home-Security-Automation-using-a-Raspberry-Pi/
System Overview:
For Phase 1 - I plan on enabling the home security functionality. Phase 2 will be the home automation (wireless light control etc.) and additional security features like webcam motion detection and potentially laser trip wires.
Hardware:
I picked up an inexpensive set of 433MHz transmitter-
receiver modules ($2.77) and 433Mhz door/window sensors ($12.99) from Ebay (links below)
433MHz Tx-Rx pair (set of 2)
I am now using a 433MHz receiver ($5.99) suggested by Kris (Thanks!) which is much better than the one originally recommended. Link for that item is here:
Updated module - 433MHz super heterodyne receiver
433MHz Door/Window Sensors (set of 4)
For the input interface I picked up a 4x3 membrane keypad available on the
Adafruit website ($3.95)
I have 2 webcams that I use for this project:
- An inexpensive USB webcam connected to the Pi directly
- A Tenvis JPT3815W IP Webcam connected to my home internet.
Software:
433 MHz RF communication on Pi:
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-adding-433-to-your-raspberry-pi
A couple of points to note here:
- The outputs of the receiver are 5V TTL and I wasn't so pleased connecting them directly to 3.3 V tolerant Pi inputs.So I used a simple voltage divider circuit (220 ohm/440 ohm) to drop the voltage to something around 3.3 V.
- The receiver from Ebay does not come with an antenna. This threw me off initially because I wasn't receiving any code unless my transmitter was few inches away from the receiver. The recommended length for an antenna for this module is a 172mm long one (1/4 wavelength).
- I modified RFSniffer.cpp to write to a file, if the code matched my 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 > trigger.txt");
}
}
Run a "make" in the RPi_utils directory to create an updated executable.
You will need to install WebIOPi for the web interface.
You will also need motion to detect movement using any webcam. Check out my previous post here to see how to set this up.
Python code for rest of the software can be found on github:
https://github.com/tkmaker/RaspberryPiHomeAlarm
A shout out to
Chris Crumpacker for enabling the 4x3 keypad code on the Pi. Thanks!
You can modify the passcode to arm/disarm the system from the keypad via
keypad.py
You need to modify
intruder_mail.sh with your email settings. You can also customize your email subject/message in this script.
Code overview:
There are 2 main scripts of importance -
- control.py - Calls keypad.py and alarm.py. Arms/Disarms the system based on web/keypad interface.
- alarm.py - Monitors the system status and if armed, checks for triggers before sounding an alarm.
Setup:
I have the RF receiver hooked up to my Pi (rev B) with data input on GPIO 21.
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
17 22
- Pin 1 on the keypad is COL 2 - GPIO
22 10
Update: I had to change the GPIO being used here since GPIO 17 will be used by the RF transmitter (see post for phase 3) to send a code to the RF siren.
Green LED is on GPIO 7
The 2 webcams are monitored as 2 different threads via the motion software. You can check out this post
here to see how to set that up.
I have modified /etc/motion/motion.conf to write to trigger.txt on motion detection.
# Command to be
executed when a motion frame is detected (default: none)
on_motion_detected
sudo echo -n 1 > /home/pi/trush_workdir/scripts/homealarm/trigger.txt
I also have it set up to upload images and videos to my Google drive (see my previous
post for details)
Start control.py as a webiopi process:
sudo python control.py -m webiopi -d 8085
You can use any port of choice above. I used 8085.
You should see an interface like this once you go to your Pi IP address:8085
If you pull the website up on a touchscreen phone connected to your home internet, you can press the arm/disarm buttons to activate/de-active the system. The rest of the buttons are not enabled yet.
You can also enter the passcode (default 123) on your keypad to arm/disarm your system.
To test out the system -
Arm it via the web interface or keypad - The terminal should show the status here
Trigger a fake intrusion via the door sensor - Look for the alarm triggered message. The LED will blink 20 times and an email will be sent out
- Disarm and arm again
- Trigger a fake intrusion by moving in front of the webcam - Look for the alarm triggered message. The LED will blink 20 times and an email will be sent out
For now, the alarm action doesn't include a siren - I plan to add this as part of phase 2 as well.
Please feel free to leave your questions and comments Any suggestions to improve or enhance the system are welcome.