Nipun Jyoti Pathak
Published

Multi-Featured Burglar Alarm using Bolt IoT

This is home automation as well as a burglar alarm. You can set up it near your house door to notify you if any burglar enters your house.

IntermediateFull instructions provided1 hour227
Multi-Featured Burglar Alarm using Bolt IoT

Things used in this project

Story

Read more

Schematics

Circuit Diagram of The System

Code

Arduino Code

Arduino
#define trig 7
#define echo 8
#define Buzz 11
#define BoltDigital 4
#define boltWrite 3
int d1, d2, distance, i;
long duration;

void setup() {
  // put your setup code here, to run once:
  pinMode(trig, OUTPUT);
  pinMode(echo, INPUT);
  pinMode(Buzz, OUTPUT);
  pinMode(BoltDigital, OUTPUT);
  pinMode(boltWrite, INPUT);


}


void loop() {
  // put your main code here, to run repeatedly:
  Ultrasonic(trig, echo);
  d2 = distance;
  if(digitalRead(boltWrite) == 1)
  {
    if(d2 <= 20)//if distance is less than 40
    {
      digitalWrite(Buzz, HIGH);//turn the buzzer on
      digitalWrite(BoltDigital, HIGH);
      for(int i=0; i<100; i++) 
      { //do this 255 times
        analogWrite(Buzz, i); //raise the voltage sent out of the pin by 1
        delay(150); //wait 10 milliseconds to repeat 
      }

      for(int i=100; i>0; i--)
      { // do this 255 times
          analogWrite(Buzz, i); //lower the voltage sent out of the pin by 1
          delay(150); //wait 10 milliseconds to repeat
        
      }
    }
    else
    {
      digitalWrite(Buzz, LOW);//turn the buzzer off
      digitalWrite(BoltDigital, LOW);
    }
  }

}

void Ultrasonic(int Trig, int Echo)
{
  digitalWrite(Trig, LOW);
  delayMicroseconds(2);
  digitalWrite(Trig, HIGH);
  delayMicroseconds(10);
  digitalWrite(Trig, LOW);
  duration = pulseIn(Echo, HIGH);
  distance = 0.034 * duration/2;
}

Python Code

Python
from boltiot import Bolt, Sms #Import Sms and Bolt class from boltiot library
import json, time, datetime

SID = 'You can find SID in your Twilio Dashboard' 
AUTH_TOKEN = 'You can find  on your Twilio Dashboard' 
FROM_NUMBER = 'This is the no. generated by Twilio. You can find this on your Twilio Dashboard'
TO_NUMBER = 'This is your number. Make sure you are adding +91 in beginning
API_KEY = 'This is your Bolt Cloud accout API key'
DEVICE_ID = 'This is the ID of your Bolt device'

startingHour = int(input("Starting Hour(enter in 24 hour format): "))
endingHour = int(input("Ending Hour(enter in 24 hour format): "))

bolt = Bolt(API_KEY, DEVICE_ID)
sms = Sms(SID, AUTH_TOKEN, TO_NUMBER, FROM_NUMBER)

while True:
    current_time = datetime.datetime.now()  # Current Time

    try:
        if startingHour < current_time.hour < endingHour:
            lightValue = int(json.loads(bolt.digitalWrite('3', 'HIGH'))['value'])
            print(f"Light ON/OFF state {lightValue}")  # Lights On if the time is between the given range

            buzzValue = int(json.loads(bolt.digitalRead('4'))['value'])
            print(f"Buzzer ON/OFF state: {buzzValue}")  # Buzzer On if the time is between the given range
            time.sleep(10)
            if buzzValue == 1 and lightValue == 1:
                bolt.digitalWrite('0', 'HIGH')
                print("Making request to Twilio to send a SMS")
                response = sms.send_sms("ALERT! Burglar in the House")  # Message to phone if someone enters home at that time
                time.sleep(10)
        else:
            bolt.digitalWrite('3', 'LOW')
            print("System will work from 12am to 6am")  # Print if beyond the given time range
            time.sleep(10)
    except Exception as e:
        print("Error occurred: Below are the details")
        print(e)
    time.sleep(10)

Credits

Nipun Jyoti Pathak

Nipun Jyoti Pathak

2 projects • 1 follower
I am pursuing B.Tech in Electrical Engineering. I am still learning about machine learning, neural networks, IoT and game development.

Comments