V. Nimal Yughan
Published

Indoor Temperature Monitor And Control

Monitor and predict room temperature, alert the user and control it by turning on heater or fan when temperature is too cold or too hot.

IntermediateFull instructions provided3 hours533
Indoor Temperature Monitor And Control

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
Temperature Sensor
Temperature Sensor
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
DC motor (generic)
×2
Buzzer, Piezo
Buzzer, Piezo
×1
Dual H-Bridge motor drivers L298
SparkFun Dual H-Bridge motor drivers L298
×1

Software apps and online services

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

Story

Read more

Custom parts and enclosures

HEATER

The heater made from fan and bulb.

Schematics

CIRCUIT DIAGRAM:

CONNECTIONS:

After connection it looks like this.

Code

PYTHON CODE FOR THE PROJECT

Python
This python code is executed in Ubuntu. Create conf.py first and then import conf into this file.
import conf
from boltiot import Sms,Bolt
import json, time, math, statistics

min_temp = 320
max_temp = 340

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=[]

while True: 
    print ("Reading room temperature")
    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'])
    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(30)
        continue
    try: 
        print("Temperature is: "+ str(sensor_value))
        if sensor_value > max_temp:
            if sensor_value > bound[0] :
                 print ("The temperature increased suddenly. Sending an SMS.")
                 response = sms.send_sms("Temperature increased: Fan turned on")
                 print("Please turn on the AC!")
                 response3 = mybolt.digitalWrite('0','HIGH')
                 time.sleep(10)
                 response2 = mybolt.digitalWrite('1','HIGH')
                 response2 = mybolt.digitalWrite('2','LOW')
                 response2 = mybolt.digitalWrite('3','HIGH')
                 response2 = mybolt.digitalWrite('4','HIGH') 
            else:
                 print("Room is hot..Sending message that fan is getting turned on")
                 print("Turn on the AC also!")
                 response = sms.send_sms("Its hot: " +str(sensor_value)+" Fan Turned on")
                 print("Response received from Twilio is: " + str(response))
                 print("Status of SMS at Twilio is :" + str(response.status))
                 response2 = mybolt.digitalWrite('1','HIGH')
                 response2 = mybolt.digitalWrite('2','LOW')
                 response2 = mybolt.digitalWrite('3','HIGH')
                 response2 = mybolt.digitalWrite('4','HIGH')
        elif sensor_value < min_temp:
            if sensor_value < bound[1]:
                print ("The temperature decreased suddenly. Sending an SMS.")
                response = sms.send_sms("Temperature increased: Heater turned on")
                print("Please turn off the AC!")
                response3 = mybolt.digitalWrite('0','HIGH')
                time.sleep(10)
                response2 = mybolt.digitalWrite('1','HIGH')
                response2 = mybolt.digitalWrite('2','HIGH')
                response2 = mybolt.digitalWrite('3','HIGH')
                response2 = mybolt.digitalWrite('4','LOW') 
            else:
                print("Room is cold..Sending message that heater is getting turned on")
                print("Turn off the AC!")
                response = sms.send_sms("Its cold: " +str(sensor_value)+" Heater Tuned on")
                print("Response received from Twilio is: " + str(response))
                print("Status of SMS at Twilio is :" + str(response.status))
                response2 = mybolt.digitalWrite('1','HIGH')
                response2 = mybolt.digitalWrite('2','HIGH')
                response2 = mybolt.digitalWrite('3','HIGH')
                response2 = mybolt.digitalWrite('4','LOW')

        history_data.append(sensor_value);
    except Exception as e: 
        print ("Error occured: Below are the details")
        print (e)
    time.sleep(60)

BOLT CLOUD CODE:

JavaScript
This is the code for monitoring and predicting temperature using the bolt cloud.
setChartLibrary('google-chart');
setChartTitle('TEMPERATURE MONITORING AND CONTROL');
setChartType('predictionGraph');
setAxisName('time_stamp','temperature');
mul(0.0977);
plotChart('time_stamp','room_temp');

conf.py

Python
This code contains the Bolt API key, device id.
SSID, Auth Token, From Number and To Number of your Twilio Acount.
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

Credits

V. Nimal Yughan
1 project • 0 followers

Comments