Madhu Madhavi
Published

Home Automation with Fire Alarm

It controls the turning ON, OFF and brightness of led by our own device, works as a fire alarm and informs us by a message accordingly.

IntermediateFull instructions provided822
Home Automation with Fire Alarm

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
USB-A to Mini-USB Cable
USB-A to Mini-USB Cable
×1
LED (generic)
LED (generic)
×2
Resistor 10k ohm
Resistor 10k ohm
×1
Temperature Sensor
Temperature Sensor
×1
Buzzer
Buzzer
×1
Push Button Switch
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

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

Story

Read more

Schematics

Schematics for controlling LED

Schematics for Fire Alarm

Code

Configuration File (conf.py)

Python
It has the specific keys for each user/device. We will import this file in our main code and use the various attributes. Fill your own details in the configuration file to run the code.
SID = 'XXXXXX'                  # SID in Twilio Dashboard 
AUTH_TOKEN = 'XXXXXX'           # on Twilio Dashboard 
FROM_NUMBER = 'XXXXXXXXXXXX' #This is the no. generated by Twilio on Twilio Dashboard
TO_NUMBER = 'XXXXXXXXXXXXXX'  # your number with +91 in beginning
API_KEY = 'XXXXXXXX'         #Bolt Cloud accout API key
DEVICE_ID =  'BOLTXXXXXXX'   # Bolt device ID

User Interface for Light Control

HTML
This code is for the user interface for light control by our own device i.e. Bolt Android App.
<!DOCTYPE html>
<html>
    <head>
        <title>HOME AUTOMATION</title>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <script type="text/javascript" src="https://cloud.boltiot.com/static/js/boltCommands.js"></script>
        <script>
        setKey('{{ApiKey}}','{{Name}}');
        

        function Show() {
         let x = document.getElementById("Power");
          x.style.display = "block";    
        }
          function Hide() {
            let x = document.getElementById("Power");
          x.style.display = "none";    
        }

 </script>

 <style>
 body, html {
  height: 100%;
  margin: 0;
}

.bg {
  /* Full height */
  height: 100%; 

  /* Center and scale the image nicely */
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}
.button0 {
 
  border: none;
  color: white;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 32px;
  margin: 4px 2px;
  cursor: pointer;
 
}

.button1 {background-color: #4CAF50;
          padding: 50px 50px;
           width: 50%;
}
.button2 {background-color: #f44336;
    padding: 50px 50px;
     width: 50%;
}

.div{
    height: 100px;
}
.div1{height: 40px;}
 

.slidecontainer {
  width: 100%;
}

.slider {
  -webkit-appearance: none;
  width: 50%;
  height: 15px;
  border-radius: 5px;
  background: #FDEBD0;
  outline: none;
  opacity: 0.7;
  -webkit-transition: .2s;
  transition: opacity .2s;
}

.slider:hover {
  opacity: 1;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 25px;
  height: 25px;
  border-radius: 50%;
  background: #FF8C00;
  cursor: pointer;
}

.slider::-moz-range-thumb {
  width: 25px;
  height: 25px;
  border-radius: 50%;
  background: #FF8C00;
  cursor: pointer;
}
</style>
    </head>
    <body bgcolor="#000000" text="#ffffff"  onload="Hide()">
       <center>
        <div class="div1"></div>    
        <div class="div">
    
        <button class="button0 button1" onclick="Show(); digitalWrite(1, 'HIGH');"><b>ON</b></button>

        </div>
        
        <div class="div1"></div>
        <center>
        
        <div id="Power"  class="div slidecontainer">
        <h1> <font color="">BRIGHTNESS </font></h1>
       
        
        <input type="range" min="1" max="255" value="200" onchange="analogWrite(1,this.value);" class="slider" id="myRange">
  <p>Value: <span id="demo"></span></p>
  <script>
var slider = document.getElementById("myRange");
var output = document.getElementById("demo");
output.innerHTML = slider.value;
slider.oninput = function() {
  output.innerHTML = this.value;
}
</script>
        </div>
        </center>
        <div class="div1"></div>
        <div class="div1"></div>
        <div class="div">
            
     <button class="button0 button2" onclick="Hide(); digitalWrite(1, 'LOW');"><b>OFF</b></button> 
        </div>
    </center>

    </body>
</html>

Home Automation with Fire Alarm

Python
import conf
from boltiot import Sms, Bolt
import json, time
import threading

maximum_limit = 50
on = 1

mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID)
sms = Sms(conf.SID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER)

def fire_alarm():
    while True:
        print("Reading Sensor Value")
        response = mybolt.analogRead('A0')
        data = json.loads(response)
        print("Sensor Value is : " + str(data['value']))
        try:
            sensor_value = int(data['value'])
            temp = (100 * sensor_value)/1024
            print(temp)
            if temp > maximum_limit:
                mybolt.digitalWrite('0','HIGH')
                print("Making request to Twilio to send a SMS")
                response = sms.send_sms("FIRE !!! FIRE !!! The Current Temperature Sensor value in degree celcius is " + str(temp))
                print("Response received from Twilio is " + str(response))
                print("Status of SMS at Twilio is " + str(response.status))
            else:
                mybolt.digitalWrite('0', 'LOW')
        except Exception as e:
            print("Error occured : Below are the details ")
            print(e)
        time.sleep(10)
        
def home_light():
    while True:
        response1 = mybolt.digitalRead('4')
        data1 = json.loads(response1)
        print("Status is " + str(data1['value']))
        try:
            status = int(data1['value'])
            if status == on:
                response1 = sms.send_sms("Someone switched ON the light")
        except Exception as e:
            print("Error occured : Below are the details")
            print(e)
        time.sleep(10)
        
t1 = threading.Thread(target=fire_alarm)
t1.start()

t2 = threading.Thread(target=home_light)
t2.start()

Credits

Madhu Madhavi
1 project • 0 followers

Comments