Hackster is hosting Hackster Holidays, Ep. 4: Livestream & Giveaway Drawing. Start streaming on Wednesday!Stream Hackster Holidays, Ep. 4 on Wednesday!
Kousic
Published © MIT

Intrusion detection and alert system

Smart intrusion alert system using Bolt IoT with PIR sensor which will send an SMS and Email.

IntermediateFull instructions provided1 hour418
Intrusion detection and alert system

Things used in this project

Hardware components

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

Software apps and online services

Bolt Cloud
Bolt IoT Bolt Cloud
SMS Messaging API
Twilio SMS Messaging API
mailgun.com

Story

Read more

Schematics

Hardware connection for smart intrusion alert system

Code

Code for intruder alert system

Python
from boltiot import Sms, Bolt, Email
import json, time, datetime

SSID = "SSID in your Twilio Dashboard"
AUTH_TOKEN = "Available 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 = "Bolt device ID"

mybolt = Bolt(API_KEY, DEVICE_ID)
mailer = Email(MAILGUN_API_KEY, SANDBOX_URL, SENDER_EMAIL, RECIPIENT_EMAIL)
sms = Sms(SSID, AUTH_TOKEN, TO_NUMBER, FROM_NUMBER)

while True:
        print("Reading sensor value...")
        response = mybolt.digitalRead("0")
        data = json.loads(response)
        print("Sensor value is: " + data["value"])
        try:
                sensor_value = int(data["value"])
                if sensor_value == 1:
                        mybolt.digitalWrite("1", "HIGH")
                        print("Making request to Twilio to send an SMS")
                        response = sms.send_sms("SOME INTRUDER HAS ENTERED THE ROOM")
                        print("Response received from Twilio is: " + str(response))
                        print("Status of SMS at Twilio is: " + str(response.status))
                        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 ocurred. Below are the details")
                print(e)
        time.sleep(10)
        mybolt.digitalWrite("1", "LOW")

Credits

Kousic

Kousic

1 project • 0 followers

Comments