Adhyoksh Jyoti
Published

Keep the door closed!!!!

Keep a check whether the refrigerator door is not left open so that your favourite delicacies don't get spoiled!!

IntermediateFull instructions provided1 hour277
Keep the door closed!!!!

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
Gravity: Analog LM35 Temperature Sensor For Arduino
DFRobot Gravity: Analog LM35 Temperature Sensor For Arduino
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×15
USB-A to Mini-USB Cable
USB-A to Mini-USB Cable
×1
Power bank/ Any 5V dc power supp
×1

Software apps and online services

SMS Messaging API
Twilio SMS Messaging API
Snappy Ubuntu Core
Snappy Ubuntu Core
Bolt Cloud
Bolt IoT Bolt Cloud

Story

Read more

Schematics

Circuit Schematics

Code

Main Python code for the project

Python
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.SID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER)
history_data=[]

frame=5
factor=2

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

    sensor_value=0
    try:
        sensor_value = int(data['value'])/10.24
    except e:
        print("There was an error while parsing the response: ",e)
        continue

    print ("This is the current temperature ", sensor_value)

    bound = compute_bounds(history_data,frame,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'])/10.24)
        time.sleep(10)
        continue

    try:
        if sensor_value > bound[0] :
            print ("The temperature has increased suddenly. Sending an SMS.")
            response = sms.send_sms("Someone has opened the fridge door")
            print("This is the response ",response)
        history_data.append(sensor_value);
    except Exception as e:
        print ("Error",e)
    time.sleep(10)

Credits

Adhyoksh Jyoti
11 projects • 9 followers
Electronics and Communication Engineering B.Tech graduate from NIT Srinagar, J&K.
Contact

Comments

Please log in or sign up to comment.