Aniruddha Mishra
Published © GPL3+

Capstone Project (Temperature Monitor and Anomaly Detector)

It monitors Fridge's temperature and alerts via Telegram, if the temperature falls below thresholds. It alerts if someone opens the door, too.

IntermediateProtip2.5 hours776
Capstone Project (Temperature Monitor and Anomaly Detector)

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
Temperature Sensor
Temperature Sensor
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1

Software apps and online services

Bolt Cloud
Bolt IoT Bolt Cloud
Integromat
Telegram

Story

Read more

Schematics

LM35 Sensor Circuit Connection

Hold the Flat surface of sensor facing you
Now,
> Connect the Left Leg to 5V(VCC)
> Connect the Middle leg to Output (A0)
> Connect the Right leg to Ground (GND)

Code

fridge_alert.py

Python
Code carrying out Z-Score Analysis and alerting for various thresholds
import conf,json,requests,math,statistics
import time
from boltiot import Bolt

PARAMS={'status': "undefined"}

def trigger_integromat_webhook(state):
	PARAMS['status']=state
	URL = conf.INTEGROMAT_URL
	response = requests.get(URL, PARAMS)
	print (response.text)

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)
history_data=[]
# these thresholds are set using the data collected from 2 Hours
max_threshold = 5
min_threshold = 0

while True:
	response = mybolt.analogRead('A0')
	data = json.loads(response)
	if data['success'] != 1:
		print("There was an error whilst retrieving the data")
		print("This is the temperature" + data['value'])
		time.sleep(10)
		continue
	try:
		sensor_value = int(data['value'])
		sensor_value = sensor_value/10.24
		print("The Temperature is ",round(sensor_value,2),"degree Celsius")
	except e:
		print("There was an error while parsing the response: ",e)
		continue

	if sensor_value > max_threshold:
		# temperature is beyond required maximum
		trigger_integromat_webhook("MAX")
	elif sensor_value < min_threshold:
		# temperature is below required minimum
		trigger_integromat_webhook("MIN")

	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(10)
		continue
	try:
		# If temperature rises abnormally --> DOOR IS OPEN
		if sensor_value > bound[0]:
			trigger_integromat_webhook("OPEN")
		history_data.append(sensor_value)
	except Exception as e:
		print("Error",e)
	time.sleep(10)

conf.py

Python
Configuration file consisting of credentials,APIs,URLs,etc.
API_KEY="YOUR_API_KEY"
DEVICE_ID="YOUR_DEVICE_ID"
INTEGROMAT_URL="YOUR_INTEGROMAT_WEBHOOK_URL"
FRAME_SIZE=10
MUL_FACTOR=3

product_code

JavaScript
This is the product code for plotting the data values obtained and predicting values using Polynomial Regression
setChartLibrary('google-chart');
setChartTitle('Polynomial Regression');
setChartType('predictionGraph');
setAxisName('time_stamp','temp_input');
mul(0.0977);
setAnimation(true);
setCrosshair(true);
plotChart('time_stamp','temp_input');

Credits

Aniruddha Mishra

Aniruddha Mishra

1 project • 1 follower
Final Year Computer Science & Engineering Student, NIT Andhra Pradesh

Comments