Kaushik. T.S
Published © MIT

INTRUDER ALERT USING BOLT IoT AND ARDUINO

An intruder alert system made with Bolt IoT cloud, arduino, HCSR04.It senses the difference in distance and sends the alert message to user.

Intermediate3 hours2,350
INTRUDER ALERT USING BOLT IoT AND ARDUINO

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
Arduino UNO
Arduino UNO
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Buzzer
Buzzer
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

Bolt Cloud
Bolt IoT Bolt Cloud
Arduino IDE
Arduino IDE
SMS Messaging API
Twilio SMS Messaging API
It is necessary to setup this service before starting

Story

Read more

Schematics

Fritzing circuit

Code

Arduino code

C/C++
#define echoPin 2 // attach pin D2 Arduino to pin Echo of HC-SR04
#define trigPin 3 //attach pin D3 Arduino to pin Trig of HC-SR04
#define buzz 8 //Buzzer pin connected to pin 8 of Arduino
const int max_dist=30;//Distance between sensor and door in cm
// defines variables
long duration; // variable for the duration of sound wave travel
int distance; // variable for the distance measurement

void setup() {
  pinMode(buzz, OUTPUT);//Sets the buzz pin as an OUTPUT
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an OUTPUT
  pinMode(echoPin, INPUT); // Sets the echoPin as an INPUT
  Serial.begin(9600); // // Serial Communication is starting with 9600 of baudrate speed
}
void loop() {
  // Clears the trigPin condition
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  // Sets the trigPin HIGH (ACTIVE) for 10 microseconds
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  // Reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);
  // Calculating the distance
  distance = duration * 0.034 / 2; // Speed of sound wave divided by 2 (go and back)
  Serial.print(distance);// Displays the distance on the Serial Monitor and sending to bolt
  if(distance<max_dist)//Comparing with max distance
  digitalWrite(buzz, HIGH);//Buzzer ON
  delay(10000);
}

Alert code

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

minimum_limit = 30 # the distance between wall and sensor

API_KEY = 'your bolt cloud api key'
DEVICE_ID = 'your bolt device id'

# Credentials required to send SMS
SSID = 'your twilo ssid' 
AUTH_TOKEN = 'your twilo auth token' 
FROM_NUMBER = 'number generated by twilo'
TO_NUMBER = 'your number with country code'

mybolt = Bolt(API_KEY, DEVICE_ID) #Create object to fetch data
sms = Sms(SSID, AUTH_TOKEN, TO_NUMBER, FROM_NUMBER) #Create object to send SMS
response = mybolt.serialRead('10')
print(response)

while True: 
    print ("Reading sensor value")
    response = mybolt.serialRead('10') 
    data = json.loads(response) 
    print("Sensor value is: " + str(data['value']))
    try: 
        sensor_value = int(data['value']) 
        if  sensor_value < minimum_limit:
            print("Making request to Twilio to send a SMS")
            response = sms.send_sms("An Intuder has breached your home " +str(sensor_value))
            print("Response received from Twilio is: " + str(response))
            print("Status of SMS at Twilio is :" + str(response.status))
    except Exception as e: 
        print ("Error occured: Below are the details")
        print (e)
    time.sleep(10)

Credits

Kaushik. T.S

Kaushik. T.S

2 projects • 6 followers
Presently I am pursuing BE in Electronics and communications from NIE Institute of technology,Mysuru

Comments