Vivek Kumar Singh
Published

Automated Refrigerator Alert System

In this project, LDR connected to Bolt WiFi module is placed inside the fridge. When someone opens the door of fridge alert message is sent.

BeginnerFull instructions provided30 days788
Automated Refrigerator Alert System

Things used in this project

Hardware components

Light Dependent Resistor
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1

Software apps and online services

Bolt Cloud
Bolt IoT Bolt Cloud
Bolt IoT Android App
Bolt IoT Android App
SMS Messaging API
Twilio SMS Messaging API

Hand tools and fabrication machines

Refrigerator

Story

Read more

Code

Light.py

Python
It is a python code. In this code we are fetching sensor values from Bolt WiFi module and anomaly detection is applied. If there is sudden change in the values fetched from the sensor, an alert is sent to 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(10)
        continue

    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: ",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(10)
        continue

    try:
        if sensor_value > bound[0] :
            print ("The light level increased suddenly. Sending an SMS.")
            response = sms.send_sms("Someone opened the door of refrigerator")
            print("This is the response ",response)
        elif sensor_value < bound[1]:
            print ("The light level decreased suddenly. Sending an SMS.")
            response = sms.send_sms("Someone closed the door of refrigerator")
            print("This is the response ",response)
        history_data.append(sensor_value)
    except Exception as e:
        print ("Error",e)
    time.sleep(10)

Credits

Vivek Kumar Singh
1 project • 1 follower
Thanks to Satyam Shahi.

Comments