1. Component list
- Raspberry Pi board
- Magnetic Door sensor
- PIR sensor
- Relay board or LED
- 10K resisters x2
- 330 ohm resister x1
You can easily find and purchase these components from ebay. Some of the useful links are given below.
- Magnetic Door sensor
http://www.ebay.com/itm/5-x-Door-Window-Magnetic-Plastic-Reed-Contact-Sensor-for-Alarm-100V-/251267630173?pt=AU_Home_Personal_Security&hash=item3a80b7c45d
- Relay board or LED
http://www.ebay.com/itm/1-Channel-12V-Relay-Expansion-Board-Module-High-Level-Triger-for-Arduino-/200965053926?pt=LH_DefaultDomain_0&hash=item2eca735de6
- PIR Sensor
http://www.ebay.com/itm/New-HC-SR501-Infrared-PIR-Motion-Sensor-Module-for-Arduino-Raspberry-pi-/261455286898?pt=LH_DefaultDomain_0&hash=item3cdff31272
2. Overall Idea
This tutorial will discuss about how to implement a low cost but relabel enough home security system by using Raspberry Pi board and GadgetKeeper. The tutorial discuss about following key features. But you can easily extend the concept to monitor lot of devices or different type of environmental changes even.
- Door monitor
- Window monitor
Motion detection and capture images
How this system works
- We have used a simple Magnetic door sensors to monitor the Door and Window status. It simply detect the door or window is "opened" or "closed" and update the state to GadgetKeeper using the REST API. Then the GadgetKeeper sends the email notification to you.Also you can easily mount this type of sensor even on your cupboard or locker to increase the security.
- PIR sensor is detecting the movements in the room using passive IR signals and update the Raspberry PI GPIO when some movement is captured. Our Python script process all these signals and update the GadgetKeeper to send notifications to you. If the camera is connected and enabled on Raspberry Pi, It will capture images and save all the captured images with date and time stamp in a specific image folder to review later.
- You can easily modify the given sample code to capture images on each "Door open" and "Window open" events. At the moment The camera will capture images only when motion is detected.
3. How to prepare the Raspberry Pi and other hardware
Assuming you already have OS installed Raspberry Pi, follow the given instructions below. The basic circuit diagram is given below. Please note that PIR sensor is connected to 5V supply and other 10K pull up resisters are connected to 3.3v supply. This is because of Raspberry Pi GPIO pins operate in 3.3v Logic level. But PIR sensor needs 5v supply to operate and its out put voltage is around 3v when motion is detected. So the PIR sensor out put pin can directly connect to Raspberry Pi GPIO pin without a level shifter circuit.
4. Configure GadgetKeeper
Create the "home-automation" thing first.
Now create the "door_state" , "motion_detect" and "window_state" event as shown below.
Next we need to create "doorOpenAlert" Triggers as shown below.
Click on "Edit Script" button and add the following action script.
Then create the "motionDetectAlert" as shown below.
Then click on "Edit Script" and add the following action script.
finally create the "windowOpenAlert" as shown below and add the given action script below.
5. Install packages and configure the software
Run the following command and install the required package on Raspberry Pi
Now lets create a new directory for our new scripts. Also create a new directory to save images.
Now paste the following code in the home_automation.py file.
create other file called "api_calls.sh" in side the same folder and paste the following code on it.
6. Test the script with GadgetKeeper
Its time to test the script. Double check and make sure all the hardware connections are properly connected. Then run the following command and check the output.
You will see the following output on the terminal. The script will continue monitor all the sensor status and print on the terminal, also update the state to Gadgetkeeper through the REST API.
Then shake your hand in front of the PIR sensor, Suddenly it will detect the movement then fire the camera and capture images.All these images will be saved in side the images folder and the image name will be the date and time stamp. Also this motion signal will update to GadgetKeeper and it will send you a notification e-mail. Not only that The LED connected to GPIO pin 4 will turn ON for 5 seconds. You can connect a relay board to this GPIO output and control a AC lamp or even a siren if required.
7. How to customize the script
You can simply enable or disable any of the sensor in the script. If you only need to monitor the Door but not Window or motion, then simply set the settings in the script as follows
This will only monitor the Door sensor. Simply other sensor signals will be ignored. So you have the full control over the system.
8. TODO
- Upload the captured images to cloud or FTP server
- Extend the system to monitor more sensors
- Enable real time sensor state monitoring through the GadgetKeeper.
- Control the Relay output with the GadgetKeeper to control the house bulbs and other electronic appliances.