Vinay Hariya
Published © LGPL

Laser Security System with Bolt IoT and Telegram messaging

Laser Security System for your house / room / vault using Bolt IoT. Also, use Telegram to send messages to the user when security is broken.

BeginnerFull instructions provided3 hours997
Laser Security System with Bolt IoT and Telegram messaging

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
LDR, 5 Mohm
LDR, 5 Mohm
×1
Buzzer, Piezo
Buzzer, Piezo
×1
Resistor 330 ohm
Resistor 330 ohm
×1
Laser Diode, 655 nm
Laser Diode, 655 nm
Since, i didn't have this component., I used a common and readily available keychain laser diode.
×1
Micro-USB to USB Cable (Generic)
Micro-USB to USB Cable (Generic)
×1
Male/Male Jumper Wires
as per requirement
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
as per requirement
×1
Breadboard (generic)
Breadboard (generic)
Any size, preferred 'mini -size'
×1

Software apps and online services

Telegram Messaging App
VMWare
Virtual Server on the laptop
Ubuntu Virtual Server ISO
Direct link to download iso file
Bolt IoT Android App
Bolt IoT Android App
Or you can use the IOS version of the App too

Story

Read more

Schematics

Circuit Connections

(Made on Fritzing)

Code

config.py

Python
This is an important code file since this contains the API and ID of both the Bolt-IoT module and the Telegram Bot. Replace X with the actual information
# Due to privacy issues, the important information is hidden with X
# When writing the code, replace them with your unique info
API_KEY = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"   
DEVICE_ID = "BOLTXXXXXXX"

telegram_chat_id = "@XXX"
telegram_bot_id = "botXXXX"

burglar_alarm.py

Python
This is the main code which connects the server to the Bolt-IoT Module and also to the Telegram Messaging app.
import config                 # config.py has important imformation
import json                   # library for handling JSON data
import time                   # module for sleep operation
import requests               # for making HTTP requests
from boltiot import Bolt      #importing Bolt from boltiot module

myBolt = Bolt(config.API_KEY, config.DEVICE_ID)

def get_LDR_reading():
    pin = "A0"
    try:
        response = myBolt.analogRead(pin)         # Reading data from LDR
        data = json.loads(response)               # Extracting the data from response
        
        if(data["success"] !=1):                  # Failure in Reading
            print("Request to Read Unsuccessful")
            print("\nResponse got --> ",data)
            return -1                             # -1 means failure
        sensor_value = int(data["value"])         # Getting the LDR value
        return sensor_value
    except Exception as e:
        print("Something went wrong while returning value")
        print(e)
        return -1

def send_telegram_message(message):
    url = "https://api.telegram.org/" + config.telegram_bot_id + "/sendMessage"
    data = {"chat_id": config.telegram_chat_id, "text": message}
    
    try:
        response = requests.request ("POST", url, params=data)
        telegram_data = json.loads(response.text)
        return telegram_data["ok"]
    except Exception as e:
        print("Error occured while sending Telegram Message")
        print(e)
        return False

while(True):
    sensor_value = get_LDR_reading()
    print("Reading LDR Sensor Value:: --> ", sensor_value)
    
    if sensor_value == -1 :
        print("\nCould not read. Skipping\n")
        time.sleep(10)
        continue
        
    if sensor_value < 500 :                 # 500 is the threshold value
        print("\nIntruder!!!!!!!\n")
        print("Buzzer Activated\n")
        
        myBolt.digitalWrite(1, "HIGH")      # Activating Buzzer
        message = "Alert! Burglar has entered the premises. Contact the police !"
        telegram_status = send_telegram_message(message)  # Sending Message via Telegram
        print(telegram_staus)
        time.sleep(15)    # Buzzer buzzes for 15 seconds
        myBolt.digitalWrite('1',"LOW")  # Buzzer deactivated
        
        print("Buzzer Deactivated")
        
    else:
        print("\nNo Burglar Yet")
        time.sleep(10) # Since in free account, only limited API calls allowed
 # if pro bolt account, then make time.sleep(1) for more accuracy

Credits

Vinay Hariya

Vinay Hariya

1 project • 0 followers

Comments