Meghana Vidyadhar
Published

Capstone Project (temperature monitoring)

This Boliot project consists of a temperature monitoring device, that tracks and detects anomalies in using a Machine Learning algorithm

IntermediateProtip4 hours512
Capstone Project (temperature monitoring)

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
LED (generic)
LED (generic)
×1
Buzzer
Buzzer
×1
Jumper wires (generic)
Jumper wires (generic)
×1
LM35
×1
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

Bolt Cloud
Bolt IoT Bolt Cloud
Bolt IoT Android App
Bolt IoT Android App
Ubuntu OS-VPS

Story

Read more

Schematics

Circuit Connection

Here are the circuit connections that can help you through the hardware connections required for the project

Code

Capstone Project

Python
import json,time,math,statistics
from boltiot import Bolt,Sms
import conf
#we are now writing a function to calculate the threshold

def compute_threshold(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=Variance+math.pow((data-Mn),2)
 Zn=conf.MUL_FACTOR*(Variance/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():
 response=mybolt.digitalWrite("0","HIGH")
 data_b=json.loads(response)
 if data_b['success']!=1:
  print('An error has occurred while sending sound alert',data_b['value'])
 else:
  print("Buzzer ON")
def led():
 response=mybolt.digitalWrite("1","HIGH")
 data_c=json.loads(response)
 if data_c['success']!=1:
  print("An error has occured while switching on the LED")
 else:
  print("LED ON")
#to send sms when the temperature increases

mybolt=Bolt(conf.API_KEY,conf.DEVICE_ID)
sms=Sms(conf.SID,conf.AUTH_TOKEN,conf.TO_NUMBER,conf.FROM_NUMBER)
history_data=[]

while True:
 response=mybolt.analogRead("A0") #taking input from the analog-digital pin
 data=json.loads(response) #converting the input to json format
 if data['success']!=1:
  print("There was an error while retrieving the data")
  print("This is the error",data['value'])
  time.sleep(10)

 print("This is the value",data['value'])
 sensor_value=0
 try:
  sensor_value=int(data['value'])
 except Exception as e:
  print("There was an error while parsing the response")
  continue
 try:
  if sensor_value>conf.max or sensor_value<conf.min:
   print("The sensor value has crossed threshold")
   led()
   buzzer()
   response=sms.send_sms("The temperature of the refrigerator has gone out of t$
   print("The response received from Twilio is: "+ str(response))
   print("The status of the SMS at Twilio is: " + str(response.status))
  if sensor_value<conf.max or sensor_value>conf.min:
     time.sleep(10)
     response=mybolt.digitalWrite("0","LOW")
     response=mybolt.digitalWrite("1","LOW")

 except Exception as e:
   print("There was an error while sending the SMS:", e)

 bound=compute_threshold(history_data,conf.FRAME_SIZE,conf.MUL_FACTOR)
 if not bound:
   required_data_count=conf.FRAME_SIZE-len(history_data)
   print("There is no sufficient data, the no. of data points required is:",req$
   history_data.append(int(data['value']))
   time.sleep(10)
   continue
 try:
   if sensor_value>bound[0]:
    print("The temperature has increased, sending SMS")
    response=sms.send_sms("The temperature has increased")
    led()
    buzzer()
   print("This is the response",response)
   history_data.append(sensor_value);
   if sensor_value<bound[0]:
        time.sleep(10)
        response=mybolt.digitalWrite("0","LOW")
        response=mybolt.digitalWrite("1","LOW")

 except Exception as e:
   print("error",e)
 time.sleep(10)

Credits

Meghana Vidyadhar
2 projects • 0 followers

Comments