Atul Singh
Created June 26, 2020 © GPL3+

Temperature monitor system with Z score analysis

Some expensive vaccines has to be kept at certain temperature level. So we use Z score analysis+buzzer system in help.

BeginnerProtip7 hours2

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
LM35 IC
×1
Buzzer
Buzzer
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

VmWare Software.
Twilio
Twilio is a third-party SMS functionality provide

Story

Read more

Schematics

connections

NOTICE: that the sensor IC's flat side is facing you.
keep the device OFF while connecting.
A push button can be used with buzzer for its manual control.

Code

code section to code in VMware

Python
this code consist of following steps
1. creating a new folder and enter it using the following command:
mkdir Anomaly_Detection;
cd Anomaly_Detection;
2.Creating a configurations file for this project, using the following command.
3. Creating one more file which contains the main code
#create a new folder using following command
mkdir Anomaly_Detection;
cd Anomaly_Detection;

# Create a configurations file for this project, using the following command
nano conf.py

#After the editor is open, type in the following
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 your 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 = 10
MUL_FACTOR = 6

# replace all the above value with your credentials

#create one more file named anomaly_detction.py
sudo nano anomaly_detection.py

# start with the imports.
import conf, json, time, math, statistics
from boltiot import Sms, Bolt

# define a function which calculates the Z-score parameters
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=[]

#main part of the code
while True:
    buzzer= mybolt.analogWrite('0','0')
    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 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 temperature  level increased suddenly. Sending an SMS.")
            response = sms.send_sms("Someone opened the refrigirator door")
            print("This is the response ",response)
        elif sensor_value < bound[1]:
            print ("The temperature level decreased suddenly. Sending an SMS.")
            response = sms.send_sms("Someone decreased the temperature of the refrigirator")
            print("This is the response ",response)
            buzzer= mybolt.analogWrite('0','40')
        history_data.append(sensor_value);
    except Exception as e:
        print ("Error",e)
    time.sleep(10)

Credits

Atul Singh

Atul Singh

0 projects • 0 followers
Thanks to Bolt IOT ML .

Comments