Home Security System Using PIR

In today’s post, we are going to learn how to make home security system using PIR sensor with the help of odinub.

So let’s get started,

In this project we are interfacing of IFTTT and Adafruit IO which we have already discussed before in our old blog.

We will get notification in our mobile in IFTTT app.

We are using PIR sensor to detect the any activity at door or in house. You can know about PIR sensor from this blog.

Step 1: Interfacing of Adafruit IO and IFTTT

If you want to learn interfacing from scratch you should check this blog because I am not give images of basic things here.

Go to adafruit io website and create your account. After that create a new dashboard. Now after creating a dashboard click on the dashboard you have created and create a new block in it. Create a ‘toggle’ block in it. After that create feed in it.

Now click on the feed you have created. You can see block settings. Give title to it. Set button on text as 1 and button off text as 0. Set test value as 1. We have successfully done work to do in adafruit io.

Now it’s time for IFTTT. Go to IFTTT website and make your account and go to create to make new applet.

It will show you choose service page, choose service ADAFRUIT. After that choose trigger “monitor a feed on adafruit io”.

After that in complete trigger fields choose the feed you have made in adafruit io. Set relationship to “equal to”. Set value to ‘1’.

After that click on that ‘+’ sign and choose service “notification” in it. Choose action as “send rich notification from IFTTT app”.

Set title and message you want to see when there is security alert. You can add link URL and image URL if you want. It is not necessary.

After that click on finish.

We have successfully completed interfacing of ADAFRUIT IO and IFTTT.

Note that your IFTTT  and ADAFRUIT IO have same email addresses in accounts. If you first time do connection of ifttt and adafruit io then you have to give authorization to connect this two services.

Step 2: IFTTT app

Download IFTTT app from playstore(android) or appstore(iphone). Open your account in it. Make sure you have allowed notification for IFTTT app.

Step 3: ADAFRUIT IO library

We have to install adafruit io library in our board. Adafruit-io makes sure you are connected to internet In Odinub. If not then fire below command

Ifup wlan0

If you are getting any error to connect the wifi then visit the link here. Now we are going to install adafruit io library in board. For that fire below command

pip install adafruit-io

After firing this command you will get the below output which is shown in given image.

Step 4: hardware

Hardware Required:

Odinub Board

GPIO Converter (1.27mm to 2.54 mm)

PIR sensor

Jumper Wires

Breadboard


 

 

Pin Connections:

ODINUB

PIR SENSOR

5V

VCC

GND

GND

GPIO 23

OUTPUT

 

 

STEP 4: code

After hardware connection we have to make the code which is work with “project name”. for that we have to make a directory using below command

mkdir <directoryname>

now go to that directory

cd <directoryname>

Now we have written the code in the editor you can use any of your favourite editor. here I am using Nano as editor. Don’t worry I am attaching the code below so can take as reference.

sudo nano <filename.py>

I have given my file name pir.py. write the code I have explained here. After that save file using ctrl x+y enter.

Code explanation:

First of all we will import packages we want in code by doing code given below

Import nubio
Import time
from Adafruit_IO import Client,Feed,Data

We are using gpio 23 as input so we have to declare it in code. We are writing below line to make it input

nubio.pinMode(23,"INPUT")

We have to connect our code with adafruit io to send data. For this we have to declare our adafruit io USERNAME and AIO key. To get username and AIO KEY of your adafruit io account go to your adafruit io dashboard in your light1 feed. At the right top corner you see AIO KEY click on that. You can get your username and AIO KEY from there. As we have mentioned in our voice controlled led blog.

To declare username and AIO key write below command

aio=Client('YOUR USERNAME','YOUR  AIO KEY') 

after this we will take output from PIR sensor. It will give high signal when door is open by someone. To take data from PIR sensor fire below command

a=nubio.digitalRead(23)
print(a)

to send data to adafruit io we use following command. write feed name you have given in adafruit io. I have given feed name "dooropen".

if a==1:
aio.send(‘dooropen’,1)

if high signal come from PIR we send ‘1’ to adafruit io and if adafruit io will get ‘1’ it will trigger IFTTT to send notification on mobile.

Print(“Motion Detected…”)
time.sleep(5)

code part is over now let’s run this code by firing below command.

Python<your_filename.py>

Make sure you place PIR sensor near the door.

To stop running program press ctrl+z.

Developers are always welcomed to share their ideas and projects! Do let us know below if you find this helpful. Thank you.

 

 

 

Code :
Code Title :
Code Language :
python
0 Commenting Overall Comment