Ganapriya S
Published © LGPL

TEMPERATURE ALERT - INNOVATIVE IoT DEVICE

To build a bolt module that detects temperature and if any anomaly in readings, send the mail, SMS, alarm through buzzer and LED as an alert.

AdvancedFull instructions provided3 hours527
TEMPERATURE ALERT - INNOVATIVE IoT DEVICE

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
Amazing Wi-Fi Module
×1
Temperature Sensor
Temperature Sensor
LM35 is used as temperature sensor in this project
×1
Buzzer
Buzzer
To make an effect of alarm
×1
LED (generic)
LED (generic)
To alert the surrounding people of the critical situation
×1
Jumper wires (generic)
Jumper wires (generic)
It works as its name suggests it connects LED,buzzer, LM35 to the bolt IoT module
×1
Resistor 330 ohm
Resistor 330 ohm
To prevent the heavy current flow towards LED
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
Everyone of us is familiar about this
×1
Breadboard (generic)
Breadboard (generic)
To connect all the connections of devices without soldering
×1

Software apps and online services

Mailgun
App used to sent mail through code running in a server
Linux Operating System
This will provide us a server to run our code
Bolt IoT Android App
Bolt IoT Android App
Bolt Cloud
Bolt IoT Bolt Cloud
App enable connection between Wi-Fi module and bolt cloud
SMS Messaging API
Twilio SMS Messaging API
As similar as mailgun, but used to sent SMS through code running in a server

Hand tools and fabrication machines

Laptop or PC
Android phone with good internet connection
Refrigerator
Similar to cooling chambers in pharmaceutical industry

Story

Read more

Schematics

CONNECTIONS

Method of connection

HARDWARE COMPONENTS

CONNECTED CIRCUIT

PROCEDURE

pdf form of this project

Code

POLYNOMIAL REGRESSION

JavaScript
To do temperature prediction for next 20 minutes
setChartLibrary('google-chart');
setChartTitle('Polynomial Regression-Temperature monitor');
setChartType('predictionGraph');
setAxisName('Time','Temperature(Celsius)')
mul(0.0977)
setAnimation(true);
setCrosshair(true);
plotChart('time_stamp','sensor');

CREDENTIALS

Python
Store all the credentials related to maligun ,twilio ,bolt device id ,bolt API key,mul_factor and frame size.
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'
MAILGUN_API_KEY='This is the private API key which you can find on your Maligun Dashboard'
SANDBOX_URL='You can find this on your Maligun Dashboard’
RECEPIENT_EMAIL='Enter your Email ID Here'
SENDER_EMAIL='This would be test@your SANDBOX_URL'
FRAME_SIZE=10
MUL_FACTOR=6

TEMPERATURE AND ANOMALY DETECTION

Python
To define threshold limit of temperature and to calculate Z-score analysis.
import conf,json,time,math,statistics
from boltiot import Sms,Bolt,Email
def compute(history_data,frame_size,factor):
    if len(history_data)<frame_size:
        return None
    if len(history_data)>frame_size:
        del history_data[0:len(history_data)-frame_size]
        Mn=statistics.mean(history_data)
        variance=0
        for data in history_data:
            variance+=math.pow((data-Mn),2)
        Zn=factor*math.sqrt(variance/frame_size)
        High_bound=history_data[frame_size-1]+Zn
        Low_bound=history_data[frame_size-1]-Zn
        return [High_bound,Low_bound]
history_data=[]
min=20.48
max=46.08
mybolt=Bolt(conf.API_KEY,conf.DEVICE_ID)
sms=Sms(conf.SID,conf.AUTH_TOKEN,conf.TO_NUMBER,conf.FROM_NUMBER)
mailer=Email(conf.MAILGUN_API_KEY,conf.SANDBOX_URL,conf.SENDER_EMAIL,conf.RECEPIENT_EMAIL)
while True:
    print("===========================================================================================================")
    print("Reading sensor value")
    response=mybolt.analogRead('A0')
    data=json.loads(response)
    if data['success']!=1:
        print("There was an error while retriving the data.")
        print("This is the error:"+data['value'])
        time.sleep(10)
        continue
    try:
        sensor_value=int(data['value'])
    except Exception as e:
        print("There was an error while parsing the response:",e)
        continue
    value=sensor_value/10.24
    print("THE CURRENT TEMPERATURE:"+str(value))
    try:
        if sensor_value>max or sensor_value<min:
            mybolt.digitalWrite('0','HIGH')
            print("TEMPERATURE CROSSED THE LIMIT")
            response1=sms.send_sms("TEMPERATURE CROSSED THE LIMIT.THE CURRENT TEMPERATURE IS "+str(value))
            response2=mailer.send_email("ALERT!","TEMPERATURE CROSSED THE LIMIT.THE CURRENT TEMPERATURE IS "+str(value))
            print(response2)
            print("Status of SMS at Twilio is:"+str(response1.status))
            response_text=json.loads(response2.text)
            print("Response received from Mailgun is:"+str(response_text['message']))
            time.sleep(10)
            mybolt.digitalWrite('0','LOW')
    except Exception as e:
        print("Error occured:Below are the details")
        print(e)
        time.sleep(10)
        continue
    bound=compute(history_data,conf.FRAME_SIZE,conf.MUL_FACTOR)
    print("-----------------------------------------------------------------------------------------------------------")
    if not bound:
        count=conf.FRAME_SIZE-len(history_data)
        print("Not enough data to compute Z-score.Need",count,"more data points")
        history_data.append(int(data['value']))
        time.sleep(10)
        continue
    try:
        if sensor_value> bound[0]  or sensor_value<bound[1]:
            mybolt.digitalWrite('0','HIGH')
            print("Alert! Someone opened the door")
            response1=sms.send_sms("ALERT! SOMEONE OPENED THE DOOR")
            print("Status of SMS at Twilio is:"+str(response1.status))
            response2=mailer.send_email("ALERT!","SOMEONE OPENED THE DOOR")
            response_text=json.loads(response2.text)
            print("This is the response for mail "+str(response_text['message']))
            time.sleep(10)
            mybolt.digitalWrite('0','LOW')
        history_data.append(sensor_value)
    except Exception as e:
        print("Error",e)
    time.sleep(10)

Credits

Ganapriya S
1 project • 0 followers

Comments