When it's cloudy outside, and I have to go somewhere I usually take an umbrella with me. However if it doesn't rain, the umbrella feels like a burden when I'm walking and I like to carry only the essentials with me. With the help of Bolt IoT, I have been able to create a device that will let me know if I have to carry my umbrella or not.
What does it do?This device mainly consists of a push button, a LED, a buzzer and of course my Bolt IoT module. When the button is pushed, I programmed the module to check today's forecast with the help of a real-time weather API. If it is going to rain, the buzzer will go off, warning us that it will rain. If not, the LED will switch on for a few seconds, indicating that we need not take our umbrella today. Now we can take our umbrella only when required. :)
ProcedureConnections
NOTE: At the time of writing this, I was not able to use fritzing.org to make the circuit diagrams. So I hope the images below are enough to recreate this project.
- First, connect the push button to the mini breadboard. Connect one pin to GPIO Pin 0 and the other to 3v3 pin of the Bolt WiFi Module.
- Next, connect one end of the resistor to the end connected to GPIO 0 and the other end to GND as shown in the image.
- Then, connect the negative leg of the LED(the shorter one) to GND and connect the positive leg(the longer one) to GPIO pin 1.
- Finally, connect the negative leg of the buzzer to GND and the positive leg to GPIO pin 3.
Connect the Bolt WiFi module to a power source with the help of the micro USB cable.
Before writing the Code....
To obtain your Bolt API Key and Bolt Device Name, connect your Bolt Device to the Bolt Cloud according to the instructions given at https://cloud.boltiot.com/. Below I have attached images of the Bolt Cloud page.
The Bolt Device ID has been highlighted.
Go to the API section of the website to obtain your API key.
Click on the eye icon to make your API key visible.
Code Explanation
NOTE: For the code, I created a Digital Ocean Droplet and accessed my server with the help of PuTTY.
Make sure you have installed the following python libraries before continuing with this project.
sudo apt-get update
sudo pip3 install boltiot
sudo pip3 install pyOpenSSL ndg-httpsclient pyasnl
sudo pip3 install 'requests[security]'
To create the Python code file, type
sudo nano umbrella.py
Refer to the code at the bottom of this web page.
The code can be divided into 3 major parts:
- First, we check if the button has been pushed. For this we do an digitalRead on GPIO pin 0. The response is in JSON format with 2 classes: success and value. We use json.loads to return an object from a string representing a JSON object.
- Next, if the button is pushed we call a function that checks today's forecast. To check the current forecast I used a free weather API called Dark Sky API. You're required to create an account i.e. you will get a unique API Key(insert this in the [Your API KEY] block of the URL variable). Click here for more details.
- Finally, if the check_weather() function returns "rain" then the LED function is called. Otherwise the buzzer function is called.
For more information on the data that can be accessed through Dark Sky API visit https://darksky.net/dev/docs.
ExecutionAfter saving the umbrella.py file, to run the file, type
sudo python3 umbrella.py
Now push the button to trigger the check_weather() function. You might have to push the button for sometime to trigger the function. Depending on the Dark Sky API URL you used, the LED will light up if its not going to rain or the buzzer will go off if there is rain in the forecast.
Final thoughtsI hope this project can inspire others to create their own IoT projects. I am still a beginner when it comes to IoT but Bolt IoT has given me the confidence to create whatever I want. Please let me know if I have made any mistakes or of any changes I could make to this project. :)
Comments