RAVIDEEP SINGH
Published

Temp Monitoring System with Bolt IoT for Refrigerators

LM35 sensor is used for sensing the temp inside refrigerator. If there is an anomaly in temp, i.e. door is opened, It will send an SMS.

IntermediateFull instructions provided4 hours1,190
Temp Monitoring System with Bolt IoT for Refrigerators

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×3
USB-A to B Cable
USB-A to B Cable
×1
Temperature Sensor
Temperature Sensor
×1

Software apps and online services

SMS Messaging API
Twilio SMS Messaging API
Snappy Ubuntu Core
Snappy Ubuntu Core

Story

Read more

Schematics

Temp monitoring device

This device would be able to read the temperature from it's surroundings.

Code

conf.py

Python
This file is used to save ID's, tokens, phone numbers,frame size etc. that will be used to send SMS and calculate Z score.
SSID = 'You can find SSID 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 Twilio Dashboard'
TO_NUMBER = 'This is your number. Make sure you are adding +91 in beginning'API_KEY = 'This is your Bolt Cloud account API key'
DEVICE_ID = 'This is the ID of your Bolt device'
FRAME_SIZE = 3
MUL_FACTOR = 6

anomaly_detection.py

Python
This is the main code which will calculate Z score, see for anomaly and will send the SMS alerting the user
import conf, json, time, math, statistics
from boltiot import Sms, Bolt
  
def compute_bounds(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]
  
mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID)
sms = Sms(conf.SSID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER)
history_data=[]
  
while True:
   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(5)
       continue
   sensor_value1 = int(data['value'])
   sensor_value1 = sensor_value1/10.24
   print ("The current Temparature of your Refrigarator is "+ str(sensor_value1)+" degree celsious. And the Sensor Value is "+data['value'])
   sensor_value=0
   try:
       sensor_value = int(data['value'])
   except e:
       print("There was an error while parsing the response: ",e)
       continue
   bound = compute_bounds(history_data,conf.FRAME_SIZE,conf.MUL_FACTOR)
   if not bound:
       required_data_count=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(5)
       continue
   try:
       if sensor_value > bound[0] :
           sensor_value1 = sensor_value/10.24
           print ("The Temparature level has been INCREASED suddenly.Sending SMS")
           response = sms.send_sms("Someone Opened the fridge door. The Current temperature is " + str(sensor_value1)+ " degree celsious")
           print("This is the response for SMS ",response)
       history_data.append(sensor_value);
   except Exception as e:
       print ("Error",e)
   time.sleep(5)

Credits

RAVIDEEP SINGH

RAVIDEEP SINGH

1 project • 0 followers

Comments