Dharmveer Bharti

Secure Lock

Monitor your locker in real time. Get an SMS alert whenever the locker is opened. An IoT based add-on to the security of your commodities.

IntermediateFull instructions provided4 hours3
Secure Lock

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
IR proximity sensor
Male/Female Jumper Wires
Male/Female Jumper Wires
3 wires are needed to connect IR sensor with Bolt WiFi module
Battery bank 5V 10,000mAh
Power banks with higher capacity are preferred.

Software apps and online services

Bolt Cloud
Bolt IoT Bolt Cloud
Bolt IoT Android App
Bolt IoT Android App
SMS Messaging API
Twilio SMS Messaging API

Hand tools and fabrication machines

Tape, Double Sided
Tape, Double Sided


Read more




CSV file initializing program

Run this first to create data.csv
import csv

with open('data.csv',mode='a',newline='') as file:
    writer = csv.writer(file)

Monitoring program

Python script for monitoring door state, saving into file and sending SMS
#conf file stores the credentials of the bolt device and twilio account
#datetime is used to get current system time
#all the records are stored in a file data.csv

import time, json, csv, conf
from datetime import datetime
from boltiot import Bolt, Sms

my_device = Bolt(conf.API_KEY,conf.DEVICE_ID)   #object for bolt device
sms = Sms(conf.SID,conf.AUTH_TOKEN,conf.TO_NUM,conf.FROM_NUM)   #object for sending sms

#setting initial state to 0, i.e. closed
previousState = 0
#'0' means door is closed and '1' means it's open
#current state is obtained each time and matched with previous state
#if they are different, then either the door is opened or is closed

print("Press Ctrl+C to quit")

while True:
        file = open('data.csv','a',newline='')  #opening file to store door open and door close time
        writer = csv.writer(file)
        reading = my_device.digitalRead('1')    #reading from digital pin 1
        data = json.loads(reading)
        currentState = int(data['value'])   #surrent state of door
        current = datetime.now().strftime("%d-%b-%Y %H:%M") #current time of system (dd-Mmm-yyyy HH:MM)

        if previousState==0 and currentState==1:
            #door was closed and now opened
            writer.writerow(["opened",current]) #store door opened time in file
                sms.send_sms("Door recently opened at: " + current) #send sms to phone
            except Exception as e:
                print("Message sending error:",e)
        if previousState==1 and currentState==0:
            #door was open and now closed
            writer.writerow(["closed",current]) #store door closed time in file
        previousState = currentState    #storing the current state
                                        #for comparision in the next iteration of loop
    except Exception as e:
        print("Exception raised: ",e)
        file.close()    #this is required to see update in the file 'data.csv'
    time.sleep(5)   #wait for 5 seconds before next iteration of loop

User Interface webpage

Bolt 'product' code
To access device data from anywhere without linking your device to a 'product', simply set api_key and d_name (lines 26,27) to your device api key and device ID
<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Secure Lock Check</title>
            font-family: sans-serif;
            margin: 0;
            margin-top: 0px;
            margin-left: 2%;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            margin: 10px;
            background-color: #424242;
            color: white;
    <script type="text/javascript">
        var api_key = "{{ApiKey}}";
        var d_name = "{{Name}}";
        var base_url = "https://cloud.boltiot.com/remote/";
        var message = "";
        function digitalRead(pin) {
            var xmlhttp = new XMLHttpRequest();
            xmlhttp.onreadystatechange = function() {
                if (this.readyState == 4 && this.status == 200) {
                    var obj = JSON.parse(xmlhttp.responseText);
                            message = "Door is open!";
                        else if(obj.value=="0")
                            message = "Door is closed.";
                        message = "error in reading, try again";
        function getState()
            var result = document.getElementById("state");
            message = "undefined, try again";
            digitalRead('1');    //reading from pin 1
            setTimeout( () => {result.innerHTML = message;}, 2000);

    <div id="banner"><h3>Secure Lock</h3></div>
    <p>This page lets you know the current state of your locker's door.</p>
    <p>Click the button below to know the live status:</p>
        <button onclick="getState();">Check State</button>
        <div id="state"></div>
    <p id='pin-state'></p>


Dharmveer Bharti

Dharmveer Bharti

0 projects • 0 followers