In today's era, IoT is booming at a huge rate. So, why should we waste our money on expensive products for the security of our home? We should take the use of IoT here and make the reliable and cost-effective security device which will inform us any intrusion via messages and alert our neighbours. We will control our security device by Google Assistant. Enjoy outside of your house and feel secure for your home!!
Follow the steps below to make your own security device.
STEP 1: Hardware SetupThe complete circuit diagram for the security device is shown in the image below. The schematic was created using Fritzing.
how does the IR module work ? it is easy to understand its working.The basic concept of an Infrared Sensor is to transmit an infrared signal, this infrared signal bounces from the surface of an object and the signal is received at the infrared receiver. So, When the object is near to the sensor(in our case that is door) it will send 1024 reading to module and when the object is out of its range it will read less than 1024.You can adjust the range of infrared sensor by changing its resistance through potentiometer.
STEP 2: Getting the Bolt API and Device IDLog in to your Bolt Cloud account: cloud.boltiot.com.
Now click on on 'API' tab.
First of all, click on the Enable in the generate key section.after that click on the 'Generate API KEY' and note your API key.
Now click on device for device ID.
Your Bolt ID will look like 'BOLTXXXXXXX'.
STEP 3: URL for GPIO Control CommandFor switching the security device ON/OFF, the Bolt module in our device will receive a corresponding command from the Google Assistant. The Google Assistant communicate with the Bolt module via IFTTT, so we're required to have a URL for make the communication possible. I will later tell you how to use this URL in the upcoming sections.
Click here for Bolt Cloud, then go to Docs Tab -> API Documentation -> GPIO Commands API -> Write Digital Output, to understand how to create a API command link to turn on or turn off a pin of the Bolt.
The structure of the command is:
https://cloud.boltiot.com/remote/API_KEY/digitalWrite?pin=PIN_NUMBER&state=HIGH/LOW&deviceName=DEVICE_ID
The parameters that you need to replace are: API_KEY: You can get it from API tab on cloud dashboard. PIN_NUMBER: in our case pin number will be 1.HIGH/LOW: This value indicates if you want to turn that pin HIGH or LOW.
STEP 4: Creating Two Applets in IFTTTWe have to make applets in ifttt.One for switching on the alarm and second is for switching off the alarm.So firstly we are creating applet for switching on the device via Googleassistant.
Go to IFTTT to create a new applet by clicking here.
Login using your Gmail account. Make sure you use same account which you'll be using on your mobile to interact with Google Assistant.
Click on '+This' to create the trigger.
Choose Google Assistant -> Say Specific Phrase
Type the phrase you want to trigger the action.It will ask for three different phrase(2 optional ). Make sure to specify the trigger command in different ways. For example, I used:
a) Switch on the alarm.
b) On the security device.
c) On the device.
After filling all this in, click on the Create trigger.
Click on '+That'.
Select Webhooks and then make a web request .Webhooks will make a API request to our Bolt module and accordingly the GPIO pin will turn HIGH or LOW.
Enter the API URL you got in the previous Step. Make sure that you change the API key and device name.Set pin number to be 1.
Method will be GET.
Content type will be application/json.
Here is how your screen will look:
Click on the 'Create action' and then click on the 'Finish'. That's it !
Repeat step 4 also to also switch OFF the security device. Remember to change the state from HIGH to LOW in this case. Pin number will remain same.
STEP 5: Create Your Twilio AccountNow we are using the Twilio web service APIs to receive messages whenever an intrusion occurs.
Below are the steps for creating your 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: Click on "Products" as shown on the screen below.
Step 6: Now enable the SMS services by clicking on two checkboxes for programmable SMS and phone numbers as shown below.
Now click on the continue button in the bottom of the screen.
Step 7: Next you will need to give a name for your project. I have given the name as My Project. Click on "Continue" once you have entered the project name.
Step 8: Click on "Skip this step" when it asks you to Invite a Teammate.
Step 9: Your project should be created at this point. Click on "Project Info" to view the account credentials which is required for your projects.
Step 10: 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 11: From the drop-down menu, choose "Programmable SMS." Now click on Get Started
button to generate phone number.
Step 12: Click on Get a number
button.
Step 13: Then a popup will appear. Click on Choose this number
button.
Step 14: Then a popup will appear which will have the final number. Copy this number and save to notepad for future references.
That's it. You have successfully created the account on Twilio.
STEP 6: Preparing the Python EnvironmentMake sure you already installed Python on your computer. I have installed Python in my ubuntu server using virtual machine.
if you want to install a ubuntu server using virtual machine, follow the steps below.
- Download VMWare.
- Install VMWare.
- Download Ubuntu server image.
- Install Ubuntu server image on VMWare.
The links to the software are provided below.
VMWare download link: https://my.vmware.com/web/vmware/free#desktop_end_user_computing/vmware_workstation_player/12_0
Ubuntu sever ISO link: http://releases.ubuntu.com/16.04/ubuntu-16.04.6-server-i386.iso
Now set up the Bolt Python library in your terminal.
Step 1: Update the packages on Ubuntu.
Execute the command below so that the packages on Ubuntu are updated to the latest version.
sudo apt-get -y update
Step 2: Install python3 pip3.
pip3 is a package manager for python3 used to install and manage packages and python libraries. It is system independent.
Install pip3 using the following command,
sudo apt install python3-pip
Step 3: Install Bolt IoT library using pip.
Now we will install the boltiot python library on your Ubuntu server.
Type the below command in terminal to install boltiot python library.
sudo pip3 install boltiot
Now we are done with Bolt IoT Python library installation.
STEP 7: Python Code for Your DeviceNow make a folder with name 'security' in your terminal. Then enter to your folder. Make a configuration file. To make this file type:
sudo nano conf.py
in this file, we will store our API KEY, DEVICE ID, SSID (you will find this in your twilio dashboard), AUTH_TOKEN (you will find this in your twilio dashboard), From_number (you will find this in your Twilio dashboard), To_number (enter the number which you have verified on Twilio. This number willl receive messages whenever there is intrusion in your home).
Below is the image of my configuration file:
Now exit from this file and make a new file.Called this file as google_alert.Write down the code in your file same as written in my file.Note: set your sleep time accordingly so that you will not hit API boltcloud 20 times in a minute.
Now after writing this code save your file.
You are all done!
Device WorkingPower up your bolt module through any powerbank or your android mobile charger and connect your Bolt module to wifi though the Bolt app. (For more details on how to set up your Bolt module, click here). Make sure your laptop is connected to internet.
After this, write 'sudo python3 google_alert.py' in your command line. Your code will execute and command line will show you the result. By default the device is off. So in order to switch your device ON, use Google Assistant and say the phrase. (Make sure you have provided to your bolt device properly). Wait for 3-4 seconds so that sensor collect atleast two value and program store those values in history_data[].
Watch my video, which shows how the device will work for any intrusion in home.
Comments