This project focuses on developing home security solution using lasers and live alert service. The security setup can only be passed (without triggering alert) using the Bolt IOT Android app and then entering the correct password. The project works using the combination of Bolt IOT module and Arduino along with Twilio providing the messaging service. Alert is triggered in the following cases:
- When correct password is entered and the person is enabled to pass.
- When wrong password is entered and a warning is issued.
- When someone tries to pass without entering the correct password.
Such a setup can be deployed across hallways and behind the doors so that in case an intruder tries to enter, the alert is triggered.
- 3.1 Components
i. Light Dependent Resistor (LDR)
A photoresistor (acronymed LDR for Light Decreasing Resistance, or light-dependent resistor, or photo-con
ductive cell) is a passive component that decreases resistance with respect to receiving luminosity (light) on the component's sensitive surface. The resistance of a photoresistor decreases with increase in incident light intensity; in other words, it exhibits photoconductivity. A photoresistor can be applied in light-sensitive detector circuits and light-activated and dark-activated switching circuits acting as a resistance semiconductor. In the dark, a photoresistor can have a resistance as high as several megaohms (MΩ), while in the light, a photoresistor can have a resistance as low as a few hundred ohms.
ii. Piezo buzzer
Piezo buzzers contain a piezo electric vibration plate (also known as a piezo element) within a moulded case. Sound is emitted when a voltage is applied and the piezo element inside the case vibrates.
iii. Laser
A laser is a device that emits light through a process of optical amplification based on the stimulated emission of electromagnetic radiation. The term "laser" originated as an acronym for "light amplification by stimulated emission of radiation".
iv. 4x4 matrix keypad
Matrix keypads are the kind of keypads you see on cell phones, calculators, microwaves ovens, door locks, etc. They’re practically everywhere.However, in DIY electronics, they are a great way to let users interact with your project and are often needed to navigate menus, punch in passwords and control robots
- 3.2 Connections with Arduino and Bolt IOT module
>> Connect TX pin of the Bolt module to the Rx pin (pin 0) of Arduino and the RX pin of the Bolt module to the TX pin (pin 1) of Arduino. Also connect the 5V pin and the GND pin of Bolt module to the respective pins on Arduino.
>>For the 4x4 matrix keypad, connect pins R1 to C4 to pin 2 to pin 9 on the Arduino and connect the VCC pin (if present) to 5V.
>>Connect the + pin of the piezo buzzer to pin 10 on the Arduino.
>>Connect the LDR to 5V supply in series with a 1k ohms resistor and connect the other end of the resistor to GND. Connect the junction of the LDR and resistor to analog pin A0 on Arduino.
>>Connect pin 11, 12 and 13 on Arduino to pin 1, 2 and 3 on Bolt IOT module.
4. Code component- 4.1 Arduino code
#include <Keypad.h>
String ch="",pwd="123ABCD4"; //Password set as 1234ABCD4
const byte rows=4,cols=4;
char keys[rows][cols]={
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'},
}; //Setting up the key configuration
byte rpin[rows]={2,3,4,5};
byte cpin[cols]={6,7,8,9};
Keypad obj=Keypad(makeKeymap(keys),rpin,cpin,rows,cols); //Creating object for keypad
int ldr=A0,buzz=10,d1=11,d2=12,d3=13,light,key=0,i,k;
String cmd="";
void setup()
{
Serial.begin(9600);
pinMode(ldr,INPUT);
pinMode(buzz,OUTPUT);
pinMode(d1,OUTPUT);
pinMode(d2,OUTPUT);
pinMode(d3,OUTPUT);
}
void loop()
{
digitalWrite(d1,0);
digitalWrite(d2,0);
digitalWrite(d3,0);
if(Serial.available()>0)
{
cmd=Serial.readString(); //Read data sent from the Bolt IOT app
Serial.println(cmd);
}
if(cmd == "1")
{
char temp=obj.getKey(); //Reads the password entered
if(temp != NO_KEY)
{
if(temp != '*')
{
Serial.println(temp);
ch +=temp;
}
else
{
if(ch == pwd)
{
digitalWrite(d1,HIGH); //Sends signal to Bolt module for correct password
Serial.println("Access granted");
delay(10000);
}
else
{
digitalWrite(d2,HIGH); //Sends signal to Bolt module for wrong password
Serial.println("Access Denied");
cmd="0";
delay(10000);
}
}
}
}
light=analogRead(ldr);
if(light<300)
{
digitalWrite(d3,HIGH); //Sends signal to Bolt module for breach
for(i=0;i<10;i++) //Loop for making the buzzer beep
{
digitalWrite(buzz,HIGH);
delay(500);
digitalWrite(buzz,LOW);
delay(500);
}
}
}
The above Arduino code is quiet easy to understand as I have provided the comments in it.
Remember, while uploading the Arduino code to the board, remove the TX and RX pins first and then upload otherwise error will occur. Also while entering the password, press '*' in at last to end the password.
- 4.2 HTML code(User interface design)
<!DOCTYPE html>
<html>
<head>
<title>
Project
</title>
<script type="text/javascript" src="https://cloud.boltiot.com/static/js/boltCommands.js"></script>
<script>
setKey('{{ApiKey}}','{{Name}}');
</script>
</head>
<body onload="serialBegin(9600)">
<div style="background-color:red;height:350px;">
<center>
<br><br><br><br><br><br><br><br>
<button onclick="serialWrite('1')">Door opened</button>
</center>
</div>
<div style="background-color:green;height:350px;">
<center>
<br><br><br><br><br><br><br><br>
<button onclick="serialWrite('0')">Door closed</button>
</center>
</div>
</body>
</html>
The source link provides the definition of of "serialBegin()" and "serialWrite()" to the browser.
- 4.3 Python code
The python coding for this project has been done in Ubuntu (Linux). Before we start coding the main code file in python, we need to make a configuration file which will have the specific keys for each user/device. We will import this file in our main code and use the various attributes. The advantage of this is that each user will only have to change the contents the configuration file to use the product.
The following is the configuration file (named as conf.py):
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. Make sure you are adding +91 in beginning'
api_key = 'This is your Bolt Cloud accout API key'
device_id = 'This is the ID of your Bolt device'
The API key and Device ID of the Bolt module can be determined as follows:
>>Connect your Bolt Device to the Bolt Cloud as per instructions given at https://cloud.boltiot.com/.
>>The following screen will appear after that.The Bolt Device ID is highlighted in yellow.
>>Go to the API section to know the API Key.
<>Creating Twilio account
Step 1: Open https://www.twilio.com/ In browser.
Step 2: Click on Get a Free API Key
button to sign up.
Step 3: Fill all the necessary details in SIGN UP form. Below is the screenshot of filled sign up form.
Step 4: To verify they will ask for your phone number. Choose India as an option in the dropdown and then enter your phone number.
Step 5:Select the 'programmable sms' option.
Step 6:You can view the Account SID and Auth token on this page. The Auth token is not visible by default, you can click on "view" button to make the Auth token visible as shown below. Copy both and save them somewhere securely.
Step 7:Click on Get a number
button.
Step 8:Then a popup will appear. Click on Choose this number
button.
Step 9: Then a popup will appear which will have the final number. Copy this number and save to notepad for future references.
**CompletePython code
import conf
from boltiot import Sms, Bolt
import json, time
mybolt = Bolt(conf.api_key, conf.device_id)
sms = Sms(conf.sid, conf.auth_token, conf.to_no, conf.from_no)
while True:
print ("Reading value from Arduino")
resp1 = mybolt.digitalRead('1')
d1 = json.loads(resp1)
resp2 = mybolt.digitalRead('2')
d2 = json.loads(resp2)
resp3 = mybolt.digitalRead('3')
d3 = json.loads(resp3)
print("D1 value is: " + str(d1['value']))
print("D2 value is: " + str(d2['value']))
print("D3 value is: " + str(d3['value']))
try:
sens1 = int(d1['value'])
sens2 = int(d2['value'])
sens3 = int(d3['value'])
if sens3 == 1 :
print("Making request to Twilio to send a SMS")
response = sms.send_sms("Breach!!!! Someone has entered forcefully.")
print("Response received from Twilio is: " + str(response))
print("Status of SMS at Twilio is :" + str(response.status))
elif sens2 == 1 :
print("Making request to Twilio to send a SMS")
response = sms.send_sms("Someone is trying to open the door.")
print("Response received from Twilio is: " + str(response))
print("Status of SMS at Twilio is :" + str(response.status))
elif sens1 == 1 :
print("Making request to Twilio to send a SMS")
response = sms.send_sms("The door is opened. You can enter now.")
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)
In the above python code, d1, d2 and d3 are the values of inputs received by the Bolt IOT module from the Arduino.
5. Points to rememberi. While uploading the Arduino code to the board, remove the TX and RX pins first and then upload otherwise error will occur.
ii. While entering the password, press '*' in at last to end the password.
iii. Once you have entered, remember to press "Door closed" button on the Bolt IOT Android app.
Comments