The Internet of Things is taking over the world. Every day, more and more objects have some sort of network connection: from coffee makers to security cameras, from air quality sensors to connected cars, there isn’t a single area of our life that won’t be touched by IoT devices in the next decade.Keeping that in my mind, I have created my project on IoT where I have made a temperature monitoring system which will continuously monitoring your space for 24 hours and send you alert if the temperature exceeded the threshold.
Embedded Project VideoHere is the working video of whole project i.e. Temperature Monitoring System
Hardware Setup- Connecting LM35 sensor to Bolt Wifi Module using jumper wires.
- Using Male To Female wire, we connect:
- VCC pin of LM35 is connected to 5v pin of the Bolt Wifi Module
- Output pin is connected to A0 pin of the Bolt Wifi Module
- GND pin is connected to GND pin of the Bolt Wifi Module
Your hardware setup is done. Now you can jump on programming section.
Creating Account on Twilio- Copy and paste this https://www.twilio.com/ in your browser
- Fill up your necessary details and click Start your free trial
- Then you have to provide your number for verification and you are done with account.Note: copy your Trial Number, Account SID and AUTH TOKEN from Dashboard Page
- Download and Install VmWare fromhttps://www.vmware.com/go/downloadworkstation
- Download and Install Ubuntu Server Image on VmWare fromhttp://releases.ubuntu.com/16.04/ubuntu-16.04.6-server-i386.iso
- Now you can start using Ubuntu Virtual Machine by login in your server
- Now we update the packages on Ubuntu Virtual Machine using command:
sudo apt-get -y update
- Install python3 pip using command:
sudo apt install python3-pip
- Install boltiot python library library using pip command:
sudo pip3 install boltiot
Generating API in Boltiot CloudGenerate and copy API Key and Device ID as shown below
- Connect the temperature monitoring system to a power source.
- After login to your Ubuntu server using VmWare and create a configuration file conf.py which will store the credentials of Twilio and Boltiot Cloud.
sudo nano conf.py
- Now save all the credentials in this file
#You can find SID in your Twilio Dashboard
SID = 'AC84ae5eceXXXXXXXXXXXXX6ff711b05'
#You can find AUTH_TOKEN in your Twilio Dashboard
AUTH_TOKEN = 'cd2f5435XXXXXXXXXXXXXb29bbb1'
#FROM_NUMBER, This is the number generated by Twilio.
FROM_NUMBER = '+12XXXXXXX73'
#TO_NUMBER, this is your number
TO_NUMBER = '+9174XXXXXX54'
#You can find API_KEY in your Boltiot Cloud
API_KEY = 'd5745340-XXXXXXXXXXXXXXX-c12dfc9ff1c8'
#You can find DEVICE_ID in your Boltiot Cloud
DEVICE_ID = 'BOLTXXXXX165'
Note: Save your our details.
- Now create one another file temperature_monitor.py using nano command.
sudo nano temperature_monitor.py
The main code is in the temperature_monitor.py file which is used to collect the data from the Bolt and send alert SMS if exceeds the threshold.
Algorithm- START
- Fetch the latest sensor value from the device.
- Check if the sensor value is within the range for normal readings.
- If it is not in range, send the SMS.
- Wait for 10 seconds.
- Repeat from START.
Now we will start writing the code.
import conf, json, time
from boltiot import Sms, Bolt
First, we have import conf file which has all the credentials and json is a python library used for handling all operations on JSON objects.We are importing two objects Sms and Bolt from boltiot library which are used to send SMS and Bolt for accessing data from the device.
Now, we initiaze two variable which stores the maximum and minimum values of threshold limit.
min_limit = 280
max_limit = 560
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. To do so, we need to provide API Key and Device Id.
mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID)
Now to send SMS, we will create an object sms using which we can send alert.
sms = Sms(conf.SID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER)
Since we want to continuously monitor the temperature reading, we will use infinte loop i.e. while True statement. To exit the loop, we will need to forcibly exit the code by holding CTRL + C.
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("Sending SMS through Twilio...")
temp_value = round((100*sensor_value)/1024,2)
print("The Current temperature is " + str(temp_value) + chr(176) + "C")
response = sms.send_sms("The Current temperature is " + str(temp_value) + chr(176) + "C")
except Exception as e:
print ("Error occured: Below are the details")
print (e)
time.sleep(10)
Below is the complete code in one frame
import conf, json, time
from boltiot import Sms, Bolt
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("Sending SMS through Twilio...")
temp_value = round((100*sensor_value)/1024,2)
print("The Current temperature is " + str(temp_value) + chr(176) + "C")
response = sms.send_sms("The Current temperature is " + str(temp_value) + chr(176) + "C")
except Exception as e:
print ("Error occured: Below are the details")
print (e)
time.sleep(10)
OutputWe have written the code for temperature monitoring. Now lets run the code using command:
sudo python3 temperature_monitor.py
After every 10 seconds, the program will print the readings from the device.
Comments