INTRODUCTION
Hi guys, every landlord and tenant have one or the other problem. Most of the owners have a guidline in which late entry is prohibited. But most of the tenants especially bachelors don't follow this and escape from this.
Now through this project, I would like to extend my support to both sides.
The landlords get a high hand because they get an alarm as well as the light alert.When this bolt wifi module is fixed in the parking lot, the ldr detects the headlight that is being sparked on it and gives an alert.Not only the housemates, but unauthorized parking can also be prohibited through this.This way it can be used in other departments too to avoid illegal parking.Here, the landlord gets an upperhand.
Entering the compound after informing the landlord is acceptable.But the problem is turning the parking lot light on throughtout the night is impossible and have a lot of wastage of electricity.So once the latecomer is reached, the landlord gets an alert message and he can switch on the necessary lights through his mobile.This way it helps the tenant too.Landlord also saves a lot of energy through this.
So both problems get a valid solution, I believe.
Firstlet's see what I have done.
STEP 1: SO LET'S STEP IN THROUGH THE CONNECTIONSUsing a breadboard is recommended here.
Insert one lead of the LDR into the Bolt Module's 3v3 Pin.Insert other lead of the LDR into the A0 pin.
Insert one leg of the 10k Ohm resistor into the GND pin.Insert the other leg of the resistor also into the A0 pin.
Plug the longer end of the LED into any of the GPIO pin(here, 1) of Bolt WiFi module shorter end to the ground pin (GND), and power on the Bolt WiFi module.
Now for the alarm part just replace the LED with the buzzer(I connected one leg to pin 0). To connect the buzzer you can use the male to female wire.
Lastly, we connect the Bolt WiFi module to the PC/laptop via a USB cable.Connect the bolt wifi module to the bolt cloud using bolt smartphone app.
Here the wires connected to bolt module are: brown to 3v3 pin, purple to GND, white to 0, yellow to A0, black to 1.
The Device ID can be found on your Cloud Dashboard and will be something like BOLTXXXXX where XXXXX are numbers.
The API key can be found from https://cloud.boltiot.com/api_credentials.Note both of them.
Since LED is a digital output device, we will need to get a Digital Write command that can be sent to Bolt over the Internet to switch on the LED.
The documentation section of bolt cloud states that GPIO command for the necessary operation of led and the buffer is as follows:
https://cloud.boltiot.com/remote/API_KEY/digitalWrite?pin=PIN_NUMBER&state=HIGH/LOW&deviceName=DEVICE_ID
https://cloud.boltiot.com/remote/d39d0e4b-538f-48e4-be28-01898634cfb4/digitalWrite?pin=1&state=HIGH&deviceName=BOLT291577
- this command will give 3.3 volts on pin 0
- browser output: {"success": "1", "value": "1"}
https://cloud.boltiot.com/remote/d39d0e4b-538f-48e4-be28-01898634cfb4/digitalWrite?pin=1&state=LOW&deviceName=BOLT291577
- this command will give 0 volts on pin 0
- browser output: {"success": "1", "value": "1"}
Similarly, for the action of buzzer the following commands can be used for turning on and off it respectively.
https://cloud.boltiot.com/remote/d39d0e4b-538f-48e4-be28-01898634cfb4/digitalWrite?pin=0&state=HIGH&deviceName=BOLT291577
https://cloud.boltiot.com/remote/d39d0e4b-538f-48e4-be28-01898634cfb4/digitalWrite?pin=0&state=LOW&deviceName=BOLT291577
The pin number that I have entered will vary depending on the pin in which you have connected the led and the buzzer.
STEP 4: NEW APPLET USING IFTTTAn applet is triggered by changes that occur within other web services such as Gmail,Facebook,Telegram,Instagram, etc...
We are using google assistant and webhooks here.
- Create an account on IFTTT to continue by clicking this link https://ifttt.com/.
- Click on '+This' to create the trigger.
- After this, search google assistant in the tab as a service.
- You will be given 4 options, out of which select "Say a simple phrase".
Here l'm creating a trigger for the buzzer at first.So type the word/sentence that helps you in triggering the desired action.You can add more number of phrases as optional.Type the desired response too.
- Click "Create trigger".
- Now click "+That"
- Select Webhooks as the next service.
- Click "Make a web request".
- Paste the url that we have quoted at the first step that was for switching on the buzzer.Here the method is GET and the content type is application/json.Then click "Create action".Then click on "Finish".
Repeat the same steps for turning off the buzzer, and for controlling the led.You must change only the phrase that is required for creating the trigger.
Stepsto turn OFF thebuzzer and led
Now do the same process for a command to switch of the LED. Here you will change the state to LOW i.e. state=LOW in your code. Here is a sample of the code. Also, add a suitable phrase to switch off the buzzer and led.
https://cloud.boltiot.com/remote/d39d0e4b-538f-48e4-be28-01898634cfb4/digitalWrite?pin=0&state=LOW&deviceName=BOLT291577
https://cloud.boltiot.com/remote/d39d0e4b-538f-48e4-be28-01898634cfb4/digitalWrite?pin=1&state=LOW&deviceName=BOLT291577
GNow wake your Android phone by saying "OK Google" and say the phrase you had set while creating the trigger to see the magic happen.
STEP5:TWILIO SETUP FOR SENDING MESSAGE
If you have not already done so, create an account on Twilio, click here to go to their signup page. If you already have an Twilio account, sign in to Twilio otherwise do the below steps.It is avsilble in the bolt training session https://trainings.boltiot.com/courses/429176/lectures/6656680.
- Fill all the necessary details in SIGN UP form. Below is the screenshot of filled sign up form.
- To verify they will ask for your phone number. Choose India as an option in the dropdown and then enter your phone number.
- Click on "Products" as shown on the screen below,
- Now enable the SMS services by clicking on two checkboxes for Programmable SMS and Phone Numbers as shown below.
Once you have done this, scroll to the bottom of the screen and click on "Continue".
- Now, 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.
- Click on "Skip this step" when it asks you to Invite a Teammate.
- Your project should be created at this point. Click on "Project Info" to view the account credentials which is required for your projects.
- 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.
- From the drop-down menu, choose "Programmable SMS". Now click on
Get Started
button to generate phone number.
- Click on
Get a number
button.
- Then a popup will appear. Click on
Choose this number
button.
- 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. In the next lesson, we will use Bolt Python library to create our own SMS Alert system.
The following steps can be easily understood through this link.
STEP 6: Sending an SMS when light intensity Crosses ThresholdConnect the light monitoring circuit as we have done earlier.
After successful login in the putty or in ubuntu terminal, create a file named conf.py
which will store all the credentials related to Twilio. To create a new file type sudo nano conf.py
in the terminal. After that write below code to save all the credentials in a single file.
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'
Now create one more file named light.py
. To do so you have to type sudo nano light.py
in the terminal. Now we will write main code to collect the data from the Bolt and send SMS if it crosses the threshold.On receiving the message, he/she can use the google assistant app to switch on the led/give an alert through buzzer. The main code is given below:
- In the code, we first have to import our conf file which has all the credentials. The python json and time libraries are also imported in the same line. Since we have saved our conf file with the.py extension, we can directly import it.
- Now we will import Bolt python library which will let us fetch the data stored in Bolt Cloud. To send the SMS, the Sms library is also imported.
- Now, we are importing two objects. First one is SMS which will be used to send SMS alerts and the other one is Bolt which is used for accessing data from your Bolt device like the temperature reading.
- Now we will initialize a variable, maximum threshold value. You can initialize required maximum integer limits to them.
- This would send an alert if the light intensity reading goes above the maximum limit similar to the alerts on a Pharmaceutical company's manufacturing line.
- Now to fetch the data from Bolt Cloud, we will create an object called 'mybolt' using which you can access the data on your Bolt.
- For the Bolt Cloud to identify your device, you will need to provide the API key and the Device ID when creating the mybolt object.
- Now to send an SMS, we will create an object of the same.
- Since we want to continuously monitor the temperature reading, we will enclose our logic to fetch, compare and send the SMS inside an infinite loop using the `while True:` statement. An infinite loop is a special loop which executes its code continuously since its exit condition is never going to be valid. To exit the loop, we will need to forcibly exit the code by holding CTRL + C.
- The code continuously fetches the light value using `analogRead` function. Since the sensor is connected to A0 pin of the Bolt, we will execute the analogRead() function on the pin A0.
- The response from the Bolt Cloud using the analogRead() function is in a JSON format, so we will need to load the JSON data sent by the cloud using Python's json library.
- The light value is inside a field labelled as "value" in the response. We can access the JSON values using the statement `sensor_value = int(data['value'])`. This line also converts the sensor reading to integer data type for comparing the temperature range.
- The next line of code checks if the temperature reading is above the maximum limit or below the minimum limit. If it exceeds, then the SMS will be sent.
- The SMS to be sent will contain the text "The Current ldr sensor value is" followed by the sensor value.
- The response from Twilio will be stored inside the `response` variable.
- Once the temperature reading has been sent, we will need to wait for 10 seconds to get the next reading. For this, we will put the program to sleep once every loop iteration.
- The statement `time.sleep(10)` puts the program execution on hold for 10 seconds. This means that the program would not execute for a period of 10 seconds.
STEP7:FINALLYDONE
So run this code in the terminal.Once the intensity of light crosses the threshold you will get a message from your twilio account to your mobile.This is an alert to the owner.Now if he/she wishes to turn on the light he can use the google assistant.This helps them since the lights can be turned on only when needed.This will not trouble the tenant if he had informed the owner earlier.Similarly if any person without any access to the premise/ without the permission tries to enter the house, the owner can give an alert to the nearby people through a buzzer.
The twilio message looks like the one below.
Wish you a good luck.
Comments