Vignesh R
Published © GPL3+

Capstone

This project can be used to send an alert when the temperature crosses the threshold and also does a z-score analysis to find any anomaly.

BeginnerFull instructions provided1.3 hours631
Capstone

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1
Male/Male Jumper Wires
×3
LM35 temperature sensor
×1

Software apps and online services

Bolt IoT Android App
Bolt IoT Android App
Bolt Cloud
Bolt IoT Bolt Cloud
Mailgun
To send alert through mail
Python IDLE

Story

Read more

Schematics

Circuit connections

Code

Polynomail regression

JavaScript
It is used to predict future data
setChartLibrary('google-chart');
setChartType('predictionGraph');
setChartTitle('Temperature in fridge');
setAxisName('Time','Temperature');
setCrosshair(true);
mul(1/10.24);
plotChart('time_stamp','temp');

Python code for mail alert and Z-score analysis

Python
#email alert code based on threshold modified with z-score analysis
import time,json,conf,statistics
from boltiot import Bolt,Email
cons_threshold=[5,10]    #add lowest and highest value
mybolt=Bolt(conf.BOLT_API_KEY,conf.DEVICE_ID)
mailer=Email(conf.MAILGUN_API_KEY,conf.SANDBOX_URL,conf.FROM_EMAIL,conf.TO_EMAIL)
def get_threshold_value(history_data,mul_factor,ran):
    if len(history_data)<ran:
        print("Not enough data to calculate the thresholds.",ran-len(history_data),"more data point(s) required")
        return None
    if len(history_data)>ran:
        del history_data[0:len(history_data)-ran]
    Mn=statistics.mean(history_data)
    sum=0
    for i in history_data:
        sum+=(i-Mn)**2
    sum/=ran
    Zn=mul_factor*(sum**(1/2))
    threshold=[history_data[len(history_data)-1]-Zn,history_data[len(history_data)-1]+Zn]
    return threshold
history_data=[]
while True:
    responce=mybolt.analogRead('A0')
    sensor_value=json.loads(responce)
    temp=float(sensor_value['value'])/10.24
    threshold=get_threshold_value(history_data,conf.MUL_FACTOR,conf.RANGE)
    print(temp)
    if threshold!=None:
        if temp>threshold[1]:
            print("Someone opened the fridge")
    if temp<cons_threshold[0]:
        responce=mailer.send_email("ALERT","The temperature is very low, the temperature is "+str(temp)+" deg Celsius")
        responce_text=json.loads(responce.text)
        print("Responce from MailGun is:",responce_text['message'])
    if temp>cons_threshold[1]:
        responce=mailer.send_email("ALERT","The temperature is very high, the temperature is "+str(temp)+" deg Celsius")
        responce_text=json.loads(responce.text)
        print("Responce from MailGun is:",responce_text['message'])
    history_data.append(temp)
    time.sleep(10)

Credits

Vignesh R

Vignesh R

1 project • 1 follower

Comments