Sahil Goyal
Published © GPL3+

Burglar alert using Bolt IoT

Forget to worry about your valuables in public display (Exhibition) being touched by someone unknown.

IntermediateProtip5 hours3
Burglar alert using Bolt IoT

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
LDR, 5 Mohm
LDR, 5 Mohm
×1
Resistor 330 ohm
Resistor 330 ohm
×1
Buzzer
Buzzer
×1
IR Proximity Sensor
Digilent IR Proximity Sensor
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×10

Software apps and online services

Bolt Cloud
Bolt IoT Bolt Cloud
Bolt IoT Android App
Bolt IoT Android App
Snappy Ubuntu Core
Snappy Ubuntu Core
Telegram

Story

Read more

Schematics

Circuit diagram

Code

Alert sending file

Python
contains all the code to send telegram alert and to beep the buzzer on detection of intruder
import requests                 # for making HTTP requests
import json                     # library for handling JSON data
import time                     # module for sleep operation

from boltiot import Bolt        # importing Bolt from boltiot module
import conf                     # config file

mybolt = Bolt(conf.bolt_api_key, conf.device_id)

def get_intensity_value_from_pin(pin):
    """Returns the intensity value. Returns -999 if request fails"""
    try:
        response = mybolt.analogRead(pin)
        data = json.loads(response)
        if data["success"] != 1:
            print("Request not successfull")
            print("This is the response->", data)
            return -999
        intensity_value = int(data["value"])
        return intensity_value
    except Exception as e:
        print("Something went wrong when returning the intensity value")
        print(e)
        return -999
def get_status_from_pin(pin):
   try:
      response = mybolt.digitalRead(pin)
      data = json.loads(response)
      ir_status = int(data["value"])
      return ir_status
   except Exception as e:
       print("Something went wrong")
       print(e)
       return -999
 
def send_telegram_message(message):
    """Sends message via Telegram"""
    url = "https://api.telegram.org/" + conf.telegram_bot_id + "/sendMessage"
    data = {
        "chat_id": conf.telegram_chat_id,
        "text": message
    }
    try:
        response = requests.request(
            "POST",
            url,
            params=data
        )
        print("This is the Telegram URL")
        print(url)
        print("This is the Telegram response")
        print(response.text)
        telegram_data = json.loads(response.text)
        return telegram_data["ok"]
    except Exception as e:
        print("An error occurred in sending the alert message via Telegram")
        print(e)
        return False


while True:
    # Step 1
    intensity_value = get_intensity_value_from_pin("A0")
    ir_status = get_status_from_pin("2")    
    print("The current intensity value is:", intensity_value)
    print("IR status is:",ir_status)
      
    # Step 2
    if intensity_value == -999:
        print("Request was unsuccessfull. Skipping.")
        time.sleep(10)
        continue

    if ir_status == 1:
       print(" Intruder detected")
       mybolt.digitalWrite('4','HIGH') #buzzer output pin
       message = "Suspicious activity near your valuable."
       telegram_status = send_telegram_message(message)
       print("This is telegram status:", telegram_status)
       time.sleep(5)    # Buzzer buzzes for 5 seconds
       mybolt.digitalWrite('4',"LOW")  # Buzzer deactivated
    
    # Step 3
    elif intensity_value >= conf.threshold:
        print("intensity value has exceeded threshold")
        mybolt.digitalWrite('4','HIGH') #buzzer output pin
        message = "Alert!! Someone has tried to steal your valuable."

        telegram_status = send_telegram_message(message)
        print("This is the Telegram status:", telegram_status)
        time.sleep(5)    # Buzzer buzzes for 5 seconds
        mybolt.digitalWrite('4',"LOW")  # Buzzer deactivated
        

    # Step 4
    time.sleep(10)

Configuration file

Python
contains the API of bolt ant BotID ChatID of telegram
API_KEY = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"   
DEVICE_ID = "BOLTXXXXXXX"

telegram_chat_id = "@XXX"
telegram_bot_id = "botXXXX"
threshold =500

Credits

Sahil Goyal

Sahil Goyal

0 projects • 0 followers

Comments

Add projectSign up / Login