Rajan PalAishwarya Khade
Published

Refrigerator Temperature Sensor Using IoT

A temperature sensor for all and any cooling system where you need to monitor the temperature.

BeginnerFull instructions provided3 hours1,760
Refrigerator Temperature Sensor Using IoT

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×3
Temperature Sensor
Temperature Sensor
LM35 temperature sensor
×1
USB-A to Mini-USB Cable
USB-A to Mini-USB Cable
×1

Software apps and online services

Bolt Cloud
Bolt IoT Bolt Cloud
Bolt Cloud
Bolt IoT Bolt Cloud

Story

Read more

Schematics

circuit connections

Code

product code

JavaScript
this code is entered in bolt cloud
setChartLibrary('google-Chart');
setChartTitle('Polynomial Regression');
setChartType('predictionGraph');
setAxisName('time_stamp','temp');
mul(0.097)
plotChart('time_stamp','temp');

alert code

Python
this is a python code to be written in your linux ubuntu for sending alert via sms, email and telegram
import config, json, time,requests, math, statistics
from boltiot import Bolt, Sms, Email
mybolt= Bolt(config.API_KEY,config.DEVICE_ID)
sms=Sms(config.SID, config.AUTH_TOKEN, config.TO_NUMBER, config.FROM_NUMBER)
history_data=[]
mailer=Email(config.MAILGUN_API_KEY, config.SANDBOX_URL, config.SENDER_EMAIL, config.RECIPIENT_EMAIL)
min=0
max=5
def send_telegram_message(message1):
        url = "https://api.telegram.org/" +config.telegram_bot_id+"/sendMessage"
        data ={"chat_id": config.telegram_chat_id, "text": message1}
        try:
                tresponse = requests.request("POST", url, params=data)
                print("This is the telegram URL")
                print(url)
                print("This is the telegram response")
                print(tresponse.text)
                telegram_data = json.loads(tresponse.text)
                return telegram_data["ok"]
        except Exception as e:
                print("An error occurred in sending the alert message via Telegram")
                print(e)
                return False
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]
while True:
        print("Reading sensor value")
        rresponse = mybolt.analogRead('A0')
        data = json.loads(rresponse)
        x=int(data['value'])
        temperature= (100*x)/1024
        print("Sensor value is :" +str(data['value']))
        print(temperature)
        try:
                if temperature>max or temperature<min:
                        print("Making request to mailgun to send an alert email")
                        response= mailer.send_email("Alert","the current temperature is :"+str(temperature))
                        response_text = json.loads(response.text)
                        print("Response received from mailgun is:"+str(response_text))
                        print("Making request to Twilio to send a SMS")
                        sresponse= sms.send_sms("the Current tmperature is " +str(temperature))
                        print("Response received from Twilio is:" +str(sresponse))
                        print("Status of SMS at Twilio is :" +str(sresponse.status))
                        message1="Alert! Sensor value is "+str(x)+"temperature is "+str(temperature)
                        telegram_status = send_telegram_message(message1)
                        print("This is the Telegram status:", telegram_status)
        except Exception as e:
                print ("Error occured: Below are the details")

                print(e)
        bound= compute_bounds(history_data, config.FRAME_SIZE, config.MUL_FACTOR)
        if not bound:
                required_data_count= config.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 x > bound[0]:
                        print("The temperature increased suddenly. Sending an SMS.")
                        result= sms.send_sms("Someone opened the fridge door.")
                        print("This is the response", result)
                history_data.append(x);
        except Exception as e:
                print ("Error",e)
        time.sleep(10)

   

configuration

Python
enter details of bolt device, twilio account, mailgun account and telegram
SID= 'AC14c17f04a77f2c3f0675beff63f3050d'
AUTH_TOKEN = '0866be10fdd1fc53373c384f2c8213d3'
FROM_NUMBER = '+19737183033'
TO_NUMBER = '+919920048496'
API_KEY = '799f605d-4a3e-4506-b63d-4a3bbae1f249'
DEVICE_ID = 'BOLT4628128'
MAILGUN_API_KEY = 'cfc82e14830a9205f620a59beb899deb-f7910792-aa65bddd'
SANDBOX_URL = 'sandboxc15e194f405d4238a97973980069616a.mailgun.org'
SENDER_EMAIL= 'test@sandboxc15e194f405d4238a97973980069616a.mailgun.org'
RECIPIENT_EMAIL= 'rajanpal1012000@gmail.com'
telegram_chat_id="@temp_alertrajaish9833"
telegram_bot_id = "bot1009404181:AAE2xEISdtIda2NDUV7FUXCtRsrP91l5bLc"
MUL_FACTOR=3
FRAME_SIZE=5

Credits

Rajan Pal

Rajan Pal

1 project • 1 follower
Aishwarya Khade

Aishwarya Khade

0 projects • 1 follower

Comments