B.Thushar
Published

IOT based temperature monitoring system

Temperature monitoring of the room, graphical prediction of temperature data with time and also carrying z-score analysis.

BeginnerFull instructions provided2 hours837
IOT based temperature monitoring system

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
Temperature Sensor
Temperature Sensor
×1
Breadboard (generic)
Breadboard (generic)
×1
LED (generic)
LED (generic)
×1
Buzzer
Buzzer
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×3
Male/Male Jumper Wires
×2

Software apps and online services

Bolt Cloud
Bolt IoT Bolt Cloud
Snappy Ubuntu Core
Snappy Ubuntu Core
VMware workstation
Mailgun

Story

Read more

Schematics

temperature_monitor_circuit_diagram

Circuit connections

Code

code

Python
import email_conf
import json, time, math, statistics
from boltiot import Email, Bolt

max_limit = 600
min_limit = 300

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((Var) / (frame_size))
    High_bound = history_data[(frame_size)-1]+Zn
    Low_bound = history_data[(frame_size)-1]-Zn
    return [High_bound,Low_bound]
    
def buzzer_action(pin, value):
    response = mybolt.digitalWrite(pin, value)
    
mybolt = Bolt(email_conf.API,email_conf.DEVICE_ID)
mailer = Email(email_conf.MAILGUN, email_conf.SANDBOX, email_conf.SENDER_EMAIL, email_conf.RECIPIENT_EMAIL)
history_data=[]

while True:
    print("Collecting sensor value")
    response = mybolt.analogRead('A0')
    data = json.loads(response)
    print("Sensor value " +str(data['value']))
    try:
        sensor_value = int(data['value'])
        if sensor_value>max_limit or sensor_value<min_limit:
           buzzer_action('1','HIGH')
           buzzer_action('4','LOW')
           print("Making request to Mailgun to send an email")
           cel_value = sensor_value*0.097
           response = mailer.send_email("Alert: Temprature exceeded threshold limit.", "The Current temperature is " +str(cel_value)+ "degree Celsius" )
           response_text = json.loads(response.text)
           print("Response received from Mailgun is: " +str(response_text['message']))
           buzzer_action('1','LOW')
    except Exception as e:
        print ("There was an error while parsing the response")
        print (e)
    time.sleep(10)

    bound = compute(history_data,email_conf.FRAME_SIZE,email_conf.MUL_FACTOR)
    if not bound:
        required_data_count=int(email_conf.FRAME_SIZE)-len(history_data)
        print("Not enough data to compute Z-score. Need ",required_data_count," more data points")
        history_data.append(int(data['value']))
        time.sleep(10)
        continue
    try:
        if sensor_value>bound[0] :
             buzzer_action('1','HIGH')
             buzzer_action('4','LOW')
             print ("The Door is open. Sending an Email.")
             response = mailer.send_email("Alert","Someone had opened the door")
             print("This is the response ",response)
             buzzer_action('1','LOW')
        history_data.append(sensor_value);
    except Exception as e:
          print ("Error occured",e)
    time.sleep(10)

Polynomial regression

JavaScript
setChartLibrary('google_chart');
setChartTitle('Pharma Monitor');
setChartType('predictionGraph');
setAxisName('Time','Temp');
mul(0.097);
plotChart('time_stamp','temp');

email_conf.py

Python
MAILGUN_API_KEY = 'This is the private API key which you can find on your Mailgun Dashboard' 
SANDBOX_URL= 'You can find this on your Mailgun Dashboard' 
SENDER_EMAIL = 'This would be test@your SANDBOX_URL'
RECIPIENT_EMAIL = 'Enter your Email ID Here'
API_KEY = 'This is your Bolt Cloud account API key'
DEVICE_ID = 'This is the ID of your Bolt device
FRAME_SIZE=10
MUL_FACTOR=6

Credits

B.Thushar

B.Thushar

1 project • 0 followers

Comments