sajid ali
Published © LGPL

Intruder Notification System Using SMS, Email & Social Media

If an intruder enters your room, you will be informed about that incident through email, SMS, and social media.

BeginnerFull instructions provided2 hours748
Intruder Notification System Using SMS, Email & Social Media

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
Buzzer
Buzzer
×1
LED (generic)
LED (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
PIR Sensor, 7 m
PIR Sensor, 7 m
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

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

Story

Read more

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

1 project • 4 followers

Comments