Twitter icon
Facebook icon
LinkedIn icon
Google icon
Reddit icon
StumbleUpon icon
Del.icio.us icon

Intruder Notification System Using SMS, Email & Social Media

Added to IoTplaybook or last updated on: 07/06/2019
Intruder Notification System Using SMS, Email & Social Media

Story

Imagine you were not at home and your door was locked suddenly some intruder comes and tries to open the door and enters the room, then he just takes away everything from the house, how would it be if you are informed about someone entering the room immediately, then you can alert immediately and take necessary precautions.

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
 
× 1

 Buy

Buzzer
Buzzer
 
× 1

 Buy from Newark

 Buy from Adafruit

LED (generic)
LED (generic)
 
× 1

 Buy from Newark

 Buy from SparkFun

Breadboard (generic)
Breadboard (generic)
 
× 1

 Buy from Newark

 Buy from SparkFun

PIR Sensor, 7 m
PIR Sensor, 7 m
 
× 1

 Buy

Jumper wires (generic)
Jumper wires (generic)
 
× 1

 Buy from Newark

 Buy from SparkFun

Software apps and online services

Bolt Cloud
Bolt IoT Bolt Cloud
 
   Bolt
SMS Messaging API
Twilio SMS Messaging API
 
   Twilio
 
MailGun
 
   Account
 
Integromat
 
   Integromat
Twitter
Twitter
 
   Login

Why Chosen Bolt as a Platform ?

I have chosen bolt wifi module for this project because I found that out of all the iot platforms we have bolt iot platform has made work very easier and its easy to implement things . I really felt using bolt iot platform its very easy to implement my task .Thank you , Bolt .

Project

This is my first project on Hackster.io so would love to know your feedback and suggestions about this project.

This project is based on the Bolt IoT Platform. You can get a Bolt WiFi Module and Cloud with Lifetime Access on Amazon.

Before we go on to what to do to accomplish this project, I would like to tell You what this Project does...

If an intruder enters the room, our body as it produces some sort of IR radiations, the PIR sensor being sensitive to this radiations outputs 1 indicates some intruder entered your house, then this output 1 glows up The LED and switches on the buzzer for 10 sec and then The owner of the house will get notified through a message and Email and also it will be posted to twitter that "Some intruder has entered the room at TIME " and also to Facebook the same post will be posted so that our family members can also be informed about the intruder's entry into the home.

Information Flow:

 

Here the Python Script checks the output of PIR Sensor sent to the Bolt device from the Bolt Cloud for every 5 sec and if The PIR Sensor outputs 1 then it switches on The LED and BUZZER and put them on for 5 sec and during that time it requests the Twillio API to send message to your phone number and requests the MailGun API to send notification that some intruder entered your room to your E-mail and also posts a tweet on Twitter and post on facebook(this is done by Integromat) notifying our family members about Intruder entrance into the room.

Message:

Email:

Twitter:

 

Facebook:

 

 

Led and Buzzer:

All the above actions have been taken place after I take my hand above the pir sensor which detects some motion and outputs 1 to the bolt wifi module.

This is the working video.

 

Intruder Notification system using Bolt wifi module

 

(Here we can inform even the Police about intruder entrance by replacing the TO_NUMBER with police number in python Script).

Doesn't it sound Interesting ????.....Now Let's know step by step what to do to accomplish our project:

1.Creating an account on the IOT cloud service(if you already have an account you can just skip to the next step)

Step 1: Open www.cloud.boltiot.com on your web browser

 

 

Step 2: Click on "SignUp” and Enter your details and press register

 

 

Step 3: You will be receiving a confirmation mail, confirm your mail by opening your mail and clicking on confirm mail button.

Step 4: After finishing Step-4 you can login to your cloud account and it will be showing the below page.(On clicking Get Started)

 

 

 

2.Linking the Bolt module to the cloud

Step 1: Open the playstore app on your mobile and search for Bolt Iot app and install it.

Step 2: Login using the bolt cloud credentials and Follow the instructions specified by the app, using those instructions Link your Bolt Module to the cloud.

After linking your bolt cloud page would be looking like...

 

 

After linking your bolt device to cloud your bolt app page would be looking like,

 

3. Hardware Setup

Step 1: Take the PIR Sensor and connect its 3 pins to Jumping wires, I will show the circuit how to connect and later also show how will it look after connecting.

 

 

Connect the output of PIR sensor to the pin '0' of the bolt iot module.

and connect the VCC of PIR Sensor to 5V supply of bolt iot module.

and connect the GND of PIR Sensor to GND of bolt iot module.

Step 2: Take the LED and Buzzer and give them appropriate connections as shown in the figure so that they get switched on when volatge at pin '1' is HIGH and get switched off when voltage at pin '2' is LOW.

The total Circuitry connection is given in the Hardware Connections

 

(Due to lack of proper resources I drew the circuit connection)

4. Creating a Twitter developer account.

Step-1: Create an account on twitter.

Step-2: Apply for the developer access at https://developer.twitter.com/en/apply-for-access.html and Fill in the details with the proper requirement why do you want to create the Twitter account and for what purpose you are going to use it.

 

1 / 6

 

Step-3: After getting access to developer, Then on the top right corner you can find your user handle of twitter, click on it and click on App, Create an App, give the details appropriately and in the website url give https://boltiot.com/ and in description give how this app will be helpful for you for us in our project this app help in.. tweeting to our account timeline every time the pir sensor has detected the intruder.Then After entering the details click on Create an App. Then the page will display as...

 

Go to Keys and tokens and copy all the credential details of API Key, API Secret Key, Access token and Access Secret Token which will be utilized later.

5. Creating an account on Twillio

Twilio is a third-party SMS functionality provider. It is a cloud communications platform as a service (PaaS) company. Twilio allows software developers to programmatically make and receive phone calls and also send and receive text messages using its web service APIs.

Step 1: Open https://www.twilio.com/ in browser.

Step 2: Sign up, choose product as SMS, language as Python and we are building account notification. After filling the details press next and verify your number.

Step 3: After verifying the number you will be redirected to Twillio home page, then

click on products

choose programmable sms, phone numbers by ticking on the radio buttons

click continue

create a project by giving appropriate name

Then after creation of project you can go to dash board

Click on project info

Copy the ACCOUNT SID and AUTH TOKEN to your notepad

Then From the drop-down menu

You can follow the images below and understand clearly.

 

1 / 12

 

choose "Programmable SMS". Now click on Get Started

Then click on Get a Number button to generate phone number. Save that phone number for later use. It is YOUR_NUMBER

 

Similarly create an account on mailgun at https://www.mailgun.com/

(Mailgun is an Email automation service. It has a very powerful set of inbuilt functions for sending emails. Developers can process their email with the help of Mailgun API)

After the verification of mobile number

go to domains

press Add Recipients

then press Invite New Recipients

press the email id and authenticate it

After verification click on the domain name you will be redirected to the following page..

 

 

 

1 / 8

 

save the credentials like MAILGUN_API_KEY, SANDBOX_URL, remember in coding sender mail has to be written as test@SANDBOX_URL.

 

6. Creating a Scenario on Integromat(you may or may not do this step )

Here Integromat will just identify the tweets on Twitter and post the same on to a Facebook page.

Step-1: Create an account on Integromat by clcking the following link https://www.integromat.com and which may cost around $29 for a standard subscription per month.

Step-2: Create scenario on Integromat that detects any tweet on twitter and posts on facebook. For this follow the below steps:

Click on Create New Scenario..

 

Then add Facebook Pages and Twitter by searching in the search bar...and click continue

Click on the question mark and select twitter..

 

Then you get displayed the following:

 

Select Watch Tweet, Click on Add connection and authenticate it with your twitter account then click ok then

click To start From Now on and click ok.

You can find a small bubble on to right of Twitter Module (Add Module) click it and select Facebook pages and select Create a post.It displays the following:

 

Then click on add and authenticate with your facebook account and on page select the page that you have created on Facebook and on message click the Text as shown in below figure

 

After Selecting Text click OK and then save the scenario by clicking the save option at below.

Now After Creating Scenarios go to Scenarios and press ON it would look like

 

 

(You can refer to tutorials of Integromat on how to create scenarios at link https://www.integromat.com/en/kb/tutorials.html if you have any queries. )

After creation of Scenario it would look like..here you have to select the modules as twitter and Facebook.Please refer the tutorials page to know how to create scenario if you have any queries. (Here you have to create a Facebook page and link it to the Facebook module in the scenario you created )(In this page the intruder notification occurs)

 

Then save it and go to your scenarios and find your scenario and switch it on.

 

7. Getting the Bolt cloud API KEY and BOLT device ID

Step-1: Go to cloud.boltiot.com and sign in into your account

Go to Devices option in Left Vertical Menu Bar...and copy your device id..

 

 

Left side you can find the API on the vertical menu bar. Select it you will be redirected to..

 

Click on Enable

Then Click on the copy Button so as to get your API KEY save it to notepad for later use.

 

That's it now we are just away by one step to complete our project we have to write the python code..

Save your python code by name proj.py

Run it ...(Before Running it you have to switch on the BOLT wifi module)

That's it your Intruder Notification System is Ready. Now Switch on your Bolt Wifi module by powering it up and you can get notified if some intruder enters your room when you are not at home.

Schematics

Hardware Connections for intruder Notification System

 

Code

Code For Intruder Notification System.

Python

 

from boltiot import Sms, Bolt,Email
import json, time,tweepy,datetime
consumer_key = "API Key for Twitter App you created"
consumer_secret = "API Secret for Twitter App you created"
access_token = "Access Token for Twitter App you created"
access_token_secret = "Access Token Secret for Twitter App you created"
SID = 'SID in your Twilio Dashboard' 
AUTH_TOKEN = 'Present on your Twilio Dashboard' 
FROM_NUMBER = 'The number you have been given from Twilio.'
TO_NUMBER = 'This is your number. Make sure you are adding +91 in beginning'
MAILGUN_API_KEY = 'This is the private API key which is present on your Mailgun Dashboard' 
SANDBOX_URL= 'This is present on your Mailgun Dashboard' 
SENDER_EMAIL = 'This would be test@your SANDBOX_URL'
RECIPIENT_EMAIL = 'Enter your Email ID Here'
API_KEY = ' your Bolt Cloud accout API key'
DEVICE_ID = ' ID of your Bolt device' 

mybolt = Bolt(API_KEY, DEVICE_ID)#creating object for Bolt device
mailer = Email(MAILGUN_API_KEY, SANDBOX_URL, SENDER_EMAIL, RECIPIENT_EMAIL)#creating object for accessing API of MAILGUN
sms = Sms(SID, AUTH_TOKEN, TO_NUMBER, FROM_NUMBER)#creating api object of Twillio for sending sms 

config = {
"consumer_key" : consumer_key,
"consumer_secret" : consumer_secret,
"access_token" : access_token,
"access_token_secret" : access_token_secret
    }
def get_api_object(cfg):
    auth =tweepy.OAuthHandler(cfg['consumer_key'],
                                  cfg['consumer_secret'])
    auth.set_access_token(cfg['access_token'],
                              cfg['access_token_secret'])
    return tweepy.API(auth)

api_object = get_api_object(config)#getting api object of twitter app so as to send tweets

while True: 
    print ("Reading sensor value")
    response = mybolt.digitalRead('0')#reading the output of pirsensor connected to pin '0' pf bolt wifi module,we get response in json format
    data = json.loads(response) #converting response into object
    print("Sensor value is: " + data['value'])
    try: 
        sensor_value = int(data['value'])#extracting value of output of pir sensor
        if sensor_value==1:#when o/p of pir sensor is 1
            mybolt.digitalWrite('1','HIGH')#switches on the led and buzzer 
            print('Some intruder has entered the room.Details:'+str(datetime.datetime.now()))
            tweet = "Some intruder has entered the room.Details:"+str(datetime.datetime.now())
            status = api_object.update_status(status=tweet)#tweeting on twitter
            print("Making request to Twilio to send a SMS")
            response = sms.send_sms('Some intruder has entered the room')#sending message
            print("Response received from Twilio is: " + str(response))
            print("Status of SMS at Twilio is :" + str(response.status))#sending email.
            response = mailer.send_email("Alert", 'Some intruder has entered the room')
            response_text = json.loads(response.text)
            print("Response received from Mailgun is: " + str(response_text['message']))
                      
            
    except Exception as e: 
        print ("Error occured: Below are the details")
        print (e)
    time.sleep(5)#waiting for 5 seconds
    mybolt.digitalWrite('1','LOW')#switching off the LED and buzzer.

Credits

sajid ali

 sajid ali

 Contact

Hackster.io

This content is provided by our content partner Hackster.io, an Avnet developer community for learning, programming, and building hardware. Visit them online for more great content like this.

This article was originally published at Hackster.io. It was added to IoTplaybook or last modified on 07/06/2019.