suraj singla
Published

Temperature Monitoring Device Using Bolt IoT Module

Temperature Monitoring device which notifies you via Email for any sudden change in temperature or if it goes out of the defined threshold.

IntermediateFull instructions provided1 hour1,436
Temperature Monitoring Device Using Bolt IoT Module

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

Story

Read more

Schematics

Hardware devices used

Bolt IoT module, Male/Female Jumper Wires, LM35 Temperature Sensor

Connecting devices

LM35 Temperature sensor connected to the Jumper wires.

Connecting devices

Sensor pin connecting to the 5V input of the Bolt IoT module.

Connecting devices

Ground pin of sensor connecting with the ground of the Bolt IoT module.

Connecting devices

The output pin of the sensor connected with the output (A0) of the Bolt IoT module.

Connecting with Power Source

The Bolt IoT module is connected with a remote power source. The slowly blinking blue light starts to glow in the module.

Connecting with WiFi

The Bolt IoT module is connected with the internet which is indicated by the stable blue and green LEDs.

Code

Temperature_sensor

Python
This is the python code for the temperature monitoring device.
import pandas as pd
import conf, json, time, math, statistics
from boltiot import Email, Bolt

# read the CSV file of the readings
df = pd.read_csv("file:///home/suraj333/Documents/IOT/temp_recording.csv")

#print the data of the csv files (temperature readings)
print("DATA SET \n",df)

# removing the 1st data row as it was the room temperature
print("\nDATA SET without 1st reading(room temp)\n", df[1:])

# describing the mean, median, mode, max and min from the data
print("\nData Set Description\n", df[1:].describe())

# saving max and min sensor readings in a variable to define the range of temperature
minimum_val = (df[1:].describe()['sensor_reading']['min'])
maximum_val = (df[1:].describe()['sensor_reading']['max'])

# Function to set upper and lower bound by Z-score analysis
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]


# configuring bolt device
mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID)

# configuring e-mail alert requirement
mailer = Email(conf.MAILGUN_API_KEY, conf.SANDBOX_URL, conf.SENDER_EMAIL, conf.RECIPIENT_EMAIL)

# setting up empty list to save the temperature (sensor) readings
history_data=[]

# system will keep on running infinitely
while True:
    # prints the history data
    print("\n\nHistory", history_data)
    
    # prints the minimum temperatre
    print("minimum = ", minimum_val)

    # prints the maximum temperature
    print("maximum = ", maximum_val)

    # saves bolt module response in variable
    response = mybolt.analogRead('A0')

    # saves the response data in variable
    data = json.loads(response)

    # print the response data
    print("complete data ", data)

    # prints current sensor value
    print("data_val ", data['value'])

    # saving the upper and lower bounds by Z-score analysis in a variable named bound
    bound = compute_bounds(history_data,conf.FRAME_SIZE,conf.MUL_FACTOR)

    # prints the bounds measured via Z-score analysis
    print("Bounds", bound)

    # checks if bound is empty or not
    # if it is empty, then it will save the current sensor value in the history_data list otherwise, will directly go to try.
    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']))

    try:
        # saves current sensor value in variable
        sensor_value = int(data['value'])
        print(" sensor_val ", sensor_value)

        # condition for when sensor value crosses the maximum threshold
        if sensor_value > maximum_val:
            temp = sensor_value/10.24
            response = mailer.send_email("Alert", "Fridge door is open.\nTemperature is beyond threshold!!!\nThe current temp val is " +str(temp))
            print(response)

        # condition for when sensor value crosses the minimum threshold
        elif sensor_value < minimum_val:
            temp = sensor_value/10.24
            response = mailer.send_email("Alert", "Fridge is cooling much more than required.\nTemperature is beyond threshold!!!\nThe current temp val is " +str(temp))
            print(response)
                 
        elif bound != None:
            # condition for when current sensor_value is greater than the upper bount calculated by Z-score analysis
            if sensor_value > bound[0]:
                response = mailer.send_email("Warning!!!", "Someone has opened the fridge door!!!")
                print ("Someone has opened the fridge door.")

            # condition for when current sensor_value is lowerer than the lower bound calculated by Z-score analysis           
            elif sensor_value < bound[1]:
                print("Someone decreased the temperature.")
            else:
                history_data.append(sensor_value)

    # in case of any error
    except Exception as e:
        print("Error", e)
    time.sleep(10)

Temperature_sensor_configurations

Python
This is the configuration file which is used for sending the email and to set the frame size and multiplication factor for Z-score analysis.
# The URL, device ID and API keys are to be filled by you and is not to be shared with anyone

MAILGUN_API_KEY = "410669354d735497XXXXXXXXXXXXXXXX-3939XXXX-7349XXXX"
SANDBOX_URL = "sandboxc54681880a064db0XXXXXXXXXXXXXXXX.mailgun.org"
SENDER_EMAIL = "test@sandboxc54681880a0XXXXXXXXXXXXXXXXXXXX.mailgun.org"
RECIPIENT_EMAIL = "surajsingla333@gmail.com"
API_KEY = "2fbeXXXX-95XX-44XX-b0XX-b73fXXXXXXXX"
DEVICE_ID = "BOLTXXXXXXXX"
FRAME_SIZE = 4
MUL_FACTOR = 3

Credits

suraj singla

suraj singla

1 project • 3 followers

Comments