Hiba Fatima
Published © GPL3+

Smart Safe Box

A safe box made from Bolt Wi-Fi module, an LDR and a buzzer; which when opened starts buzzing and also sends a message and a SMS.

BeginnerFull instructions provided1 hour989
Smart Safe Box

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
Breadboard (generic)
Breadboard (generic)
×1
LDR, 5 Mohm
LDR, 5 Mohm
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Buzzer
Buzzer
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
USB-A to Mini-USB Cable
USB-A to Mini-USB Cable
×1
Cardboard Box
×1

Software apps and online services

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

Story

Read more

Schematics

Connections

Code

conf.py

Python
bolt_api_key="This is your Bolt Cloud account API key"
device_id="BOLTXXXX"
telegram_chat_id="@XXXX"
telegram_bot_id="botXXXX"
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'

telegram_alert.py

Python
To obtain LDR values and send Twilio SMS and Telegram message when the sensor value crossed a threshold value set by you
import requests                 # for making HTTP requests
import json                     # library for handling JSON data
import time                     # module for sleep operation

from boltiot import Bolt,Sms    # importing Bolt and Sms from boltiot module
import conf                     # config file

mybolt = Bolt(conf.bolt_api_key, conf.device_id)
sms = Sms(conf.SID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER)



def get_sensor_value_from_pin(pin):
    """Returns the sensor 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
        sensor_value = int(data["value"])
        return sensor_value
    except Exception as e:
        print("Something went wrong when returning the sensor value")
        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(
            "GET",
            url,
            params=data
        )
        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
    sensor_value = get_sensor_value_from_pin("A0")    
    print("The current sensor value is:", sensor_value)
    
    # Step 2
    if sensor_value == -999:
        print("Request was unsuccessfull. Skipping.")
        time.sleep(10)
        continue
    
    # Step 3
    if sensor_value >= 900:
        response=mybolt.digitalWrite('0','HIGH')
        print(response)
        print("sensor value has exceeded threshold")
        tw_response = sms.send_sms("Alert! someone has opened the box")
        print("Response received from Twilio is: " + str(tw_response))
        print("Status of SMS at Twilio is :" + str(tw_response.status))
        print("Sensor value has exceeded threshold")
        message = "Alert! someone has opened the box"
        telegram_status = send_telegram_message(message)
        print("This is the Telegram status:", telegram_status)

    

Buzzer off

HTML
To disable the buzzer from our phone
<!DOCTYPE html>
<html>
    <head>
        <title>Bolt IoT Platform</title>
        <script type="text/javascript" src="https://cloud.boltiot.com/static/js/boltCommands.js"></script>
        <script>
        setKey('{{ApiKey}}','{{Name}}');
        </script>
    </head>
    <body>
        <h1>Click OFF to disable Buzzer</h1>
        <center>
        <button onclick="digitalWrite(0, 'LOW');">OFF</button>
        </center>
    </body>
</html>

Credits

Hiba Fatima

Hiba Fatima

1 project • 0 followers

Comments