Aman Namdev
Published © GPL3+

Voice Controlled Security Device Using Google Assistant

A voice controlled security device that notifies you by sending messages on your phone and alert your neighbour with a sharp tone of buzzer.

IntermediateFull instructions provided878
Voice Controlled Security Device Using Google Assistant

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
Jumper wires (generic)
Jumper wires (generic)
×1
IR sensors
×1
Buzzer, Piezo
Buzzer, Piezo
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1
LED (generic)
LED (generic)
×1
Resistor 10k ohm
Resistor 10k ohm
×1

Software apps and online services

IFTTT google assistance
IFTTT WebHook
Bolt Cloud
Bolt IoT Bolt Cloud
SMS Messaging API
Twilio SMS Messaging API

Story

Read more

Schematics

Hardware connections

Code

This is the main file of your project

Python
import conf,json,time
from boltiot import Bolt,Sms
mybolt = Bolt(conf.API_KEY,conf.DEVICE_ID)
sms=Sms(conf.SSID,conf.AUT_TOKEN,conf.TO_NUMBER,conf.FROM_NUMBER)
history_data=[] # we will take two values of sensor and check if those value meet the conditions
while True :
  response = mybolt.digitalRead('2') # Reading the value on digital pin 2 
  time.sleep(2)    #wait for 2 seconds
  data=json.loads(response) #converting the data into JSON object
  pin_value=int(data['value']) # obtaining the integer value from value field 
  print("value is " ,pin_value)
  if pin_value == 1: # Security device is on!
    mybolt.digital('0','HIGH') # LED will glow which indicate the device is on
	sensor_value = mybolt.analogRead('A0') # IR sensor will start taking the reading
	time.sleep(2)
	sensor_value_data = json.loads(sensor_value)
	data_sensor = int(sensor_value_data['value'])
	history_data.append(data_sensor)
	if len(history_data)< 2: # history_data will contain two values of sensor.history_data[0] will carry the past value and the history_data[1] will store the present value.
	   continue
	if len(history_data) > 2 :
	  del history_data[0]
	if len(history_data)== 2:
	  print("Value of sensor is ",history_data) #Sensor will read 1024 whenever objet is close to it and read less than 1024 if objecct is not its range
	  try :
	   if history_data[1] < 1024 and history_data[0] == 1024 : #Someone has opened the door
	    mybolt.digitalWrite('3','High') # Turning on the buzzer
	    time.sleep(1)
	    sms_data = sms.send_sms("Alert! Someone has opened the door") # Sending the messsage alert to the owner of home
	    print("Response from twilio "+str(sms_data))
	    print("status of message is "+str(sms_data.status))
	   if history_data[1] == 1024 and history_data[0] <1024 :
        mybolt.digitalWrite('3','LOW')
        time.sleep(1)
	  except Exception as e:
       print("The error is",e)  
  if pin_value == 0:
    if history_data :
       del history_data[0:1]
       mybolt.digitalWrite('0','LOW')
       mybolt.digitalWrite('3','LOW')
       print("Device is Switched off")
   time.sleep(5)	   

this is the configuration file in which your all credentials are stored

Python
SSID='TYPE HERE YOUR SSID WHICH YOU CAN FIND IN THE DASHBOARD OF TWILIO'
AUTH_TOKEN='TYPE HERE YOUR AUTH_TOKEN WHICH YOU CAN FIND IN THE DASHBOARD OF TWILIO'
FROM_NUMBER='YOU WILL FIND THI UMBER ON TWILIO DASHBOARD'
TO_NUMBER='TYOE THE NUMBER ON WHICH YOU WILL RECEIVE THE MESSAGES(THE NUMBER SHOULD BE VERIFIED BY TWILIO)'
API_KEY='YOU WILL FIND THIS ON BOLT CLOUD'
DEVICE_ID='YOU WILL FIND THIS ON BOLT CLOUD'

Credits

Aman Namdev

Aman Namdev

8 projects • 2 followers
Smart solutions for complex practical problems.

Comments