With the advancement in technology, IoT is the "next big thing!" With increased demand of automation and smart appliances at theindustry level as well as at personal home level, IoT is serving the need to make the objects smart.
This project is an evident example of IoT in action. The project deals with the sensing of temperature with the help of LM35 in any industry level, say any
pharmaceutical company where it is important to maintain a particular temperature, if temperature increased by a single degree will lead to a huge loss
so it become an important to moniter the temperature
his project deals with that problem. Whenever the temperature crosses a certain threshold, our Bolt Wifi Module will start its magic. The modules' job is to inform the owner about the anomaly.
In this section we will used sms alert as information center,
1. Hardware componentsWe need the following components to build the whole project:
- Bolt WiFi module
- LM35 Temperature sensor
- 3Jumper wires ( Male to Female ) and 2simple connecting wires(for buzzer)
- USB cable ( mobile charger can also be used )
- Power Source ( power bank can also be used )
- Bread Board
- First, we will connect the Bolt Wifi module to LM35 temperature sensor through jumper wires.
- LM35 has 3 pins, namely VCC, output, GND. So, we'll connect it with Bolt Wifi Module as follows:
VCC pin of the LM35 is connected to 5v of the Bolt Wifi module.(The
brownwire)
Output pin (middleone)is connected to A0 (Analog input pin) of the Bolt Wifi module.(The
red wire)
GND pinLM35 is connected to the GND.(The
orange wire)
- To connect the Buzzer, we'll use simple connecting wires, and connect as follows:
The negative pin(small one) is connected with the GND along with the LM35.
The Positive pin(large pin) is connected to the pin '1' (GPIO).
The hardware configuration will look like this:
We'll be using VMware Ubuntu device on our PC(Windows). You can Download the Virtual Box and Ubuntu Server.
To set up the server, follow the steps as shown in below video:
Step 1: Update the packages on Ubuntu
Execute the command below so that the packages on Ubuntu are updated to the latest version. If you skip this step, you may encounter an error while installing the Boltiot package.
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: Installing 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 boltiot python library installation. In the next section, we will learn how to use the Bolt python library to check the device status and switch off the device.
Step 4: To get bolt API key and device ID, go to Bolt cloud and click in API section you will get API key.
Now go to device section you will get device ID.
Up to this step we were known but now we have to know about a new.
Introduction to TwilioTwilio is a third-party SMS functionality provider. It is a cloud communications platform as a service (PaaS) company. Twilio allows software developers to programmatically make and receive phone calls and also send and receive text messages using its web service APIs.
Please note that SMS delivery via a trial Twilio account is not guaranteed to be instant by Twilio. Also, note that SMS will not be sent to numbers which have DND(Do Not Disturb) turned ON.
Creating an account on TwilioStep 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
After sign in
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.
Once you have done this, scroll to the bottom of the screen and click on "Continue".
Step 7: 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.
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.
Now its time to create SMS alert system:
Step 1: Connect the temperature monitoring circuit as we have done in the previous lesson -Hardware connections for temperature monitor
.
Step 2: Login into the putty by entering the IP address of your digital ocean droplet.
Step 3: After successful login, 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'
Note: You have to replace all the above value with your credentials. You can find the first four value in Twilio dashboard and the last two in Bolt Cloud dashboard
We store all the credentials in a separate file since it is sensitive data which should not be shared with anyone. Hence it is a good practice to avoid using credentials in code directly. After replacing all the values, save the file using CTRL+X.
Step 4: Now create one more file named temp_sms.py
. To do so you have to type sudo nano temp_sms.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.
code for
sudo nano temp_sms.py
while True:
print ("Reading sensor value")
response = mybolt.analogRead('A0')
data = json.loads(response)
print("Sensor value is: " + str(data['value']))
try:
sensor_value = int(data['value'])
if sensor_value > maximum_limit or sensor_value < minimum_limit:
print("Making request to Twilio to send a SMS")
response = sms.send_sms("The Current temperature sensor value is " +str(sensor_value))
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)
The algorithm for the code can be broken down into the following steps -
- Fetch the latest sensor value from the Bolt device.
- Check if the sensor value is in the range specified in our min and max values.
- If it is not in range, send the SMS.
- Wait for 10 seconds.
- Repeat from step 1
- The whole code will look like this
import conf
from boltiot import Sms, Bolt
import json, time
minimum_limit = 300
maximum_limit = 600
mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID)
sms = Sms(conf.SID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER)
while True:
print ("Reading sensor value")
response = mybolt.analogRead('A0')
data = json.loads(response)
print("Sensor value is: " + str(data['value']))
try:
sensor_value = int(data['value'])
if sensor_value > maximum_limit or sensor_value < minimum_limit:
print("Making request to Twilio to send a SMS")
response = sms.send_sms("The Current temperature sensor value is " +str(sensor_value))
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)
Now it's time to test our product!
Comments