Niranjan Akella
Published © MIT

IOTBased_Fire_Alarm_System by Akella Niranjan

An IOT based Fire alarm system using BOLT IOT Module through a Linux OS on the Digital Ocean Cloud.

AdvancedFull instructions provided3 hours384
IOTBased_Fire_Alarm_System by Akella Niranjan

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1
LED (generic)
LED (generic)
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Buzzer
Buzzer
×1
Temperature Sensor
Temperature Sensor
×1
Jumper wires (generic)
Jumper wires (generic)
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×1
Internet Connected Computer
×1

Software apps and online services

Bolt Cloud
Bolt IoT Bolt Cloud
Bolt IoT Android App
Bolt IoT Android App
Telegram
SMS Messaging API
Twilio SMS Messaging API
Digital Ocean Cloud
Linux OS

Story

Read more

Schematics

Circuit Diagram

Fritzing File.

Code

Python Config File Code

Python
All the main access codes as associated with this file.
""" BOLT Cloud Access Parameters. """
bolt_api = "YOUR BOLT CLOUD API KEY GOES HERE"
device_id = "YOUR BOLT MODULE DEVICE ID [BOLTXXXXXX]"

""" Twilio Message control access Parameters. """
Twilio_SSID = "YOUR TWILIO ACCOUNT ACCESS SID"
Twilio_Auth = "TWILIO MESSAGING AUTHENTICATION KEY"
Twilio_Number = "YOUR TWILIO ALLOCATED NUMBER"
My_Number = "RECIPIENT NUMBER"

""" Telegram Access Parameters. """
Telegram_ChatID = "@CHAT ID OF THE TELEGRAM CHANNEL"
Telegram_bottoken = "TELEGRAM BOT TOKEN START WITH BOT[FOLLOWED BY TOKEN]"

""" Threshold Level for the Fire Alarm. """
threshold = 35 

Main Python Code

Python
This is the complete python code for the Fire Alarm System.
""" Hello, I am Niranjan, Welcome to my project IOT_Based_Fire_Alaram_System using BOLT IOT Module. """
""" Import all the necessary libraries for the project. """
import config, json, time, requests
from boltiot import Bolt,Sms

""" BOLT Cloud and the Twilio Messaging access Parameters. """
bolt = Bolt(config.bolt_api,config.device_id)
sms = Sms(config.Twilio_SSID,config.Twilio_Auth, config.My_Number, config.Twilio_Number)

""" Function for getting the temperature sensor values from the analog ‘A0’ pin on the BOLT Module. """
def getSensorValue(x):
        try:
                response = bolt.analogRead(x)
                data = json.loads(response)
                if data["success"] != 1:
                        print("Request Falied!!!")
                        print("The Received Response is:", data)
                        return 0
                sensorValue = int(data['value'])
                return sensorValue
        except Exception as error:
                print("Error Occured while returning sensor value")
                print(error)
                return -1

""" Function for sending a message to the desired number through the Twilio Messaging Service. """
def MessageAlert(value):
        try:
                a = sms.send_sms("Hello!, Niranjan the current temperature value is :" + str(value) + " degrees")
                print("The response from Twilio is :" + str(a.status))
        except Exception as error:
                print("Error!!! While send Message")
                print(error)

""" Function for sending an alert message to the desired recipient through the Telegram Messaging Service. """
def sendTelegram (message):
    url = "https://api.telegram.org/" + config.Telegram_bottoken + "/sendMessage"
    data = {
        "chat_id": config.Telegram_ChatID,
        "text": message
    }
    try:
        response = requests.request(
            "POST",
            url,
            params=data
        )
        print("Response From Telegram")
        print(response.text)
        telegram_data = json.loads(response.text)
        return telegram_data["ok"]
  except Exception as error:
        print("Error Occured while send Telegram")
        print(error)
        return False
        
""" The main code sequence. """
while True:
        """ Calling the getSensorValue function to get the temperature value from the BOLT Module. """
        ValueOfSensor = getSensorValue('A0') 
        
        """ Converting the received value into degree Celsius. """
        ValueOfSensor = int(ValueOfSensor/10.42)
        
        print("Hi! Niranjan, The current temperature is :", ValueOfSensor," degrees")
        if ValueOfSensor == -1:
                print("Request Unsuccessful!!!")
                time.sleep(10)
                continue
        if ValueOfSensor >= config.threshold:
                print("ALERT!!!! FIRE!!!- Something is Burning!!!")
                
                """ Triggering the Buzzer and the LED. """
                bolt.digitalWrite('0','HIGH')
                bolt.digitalWrite('1','HIGH')
                
                """ Sending the alert message through the Twilio Service. """
                MessageAlert(ValueOfSensor)
                message = "ALERT!!, Hello !! Niranjan, The temperature in the vicinity is:" + str(ValueOfSensor)+" degrees"
                
                """ Sending the alert message through the Telegram Service. """
                TelegramMessageStatus = sendTelegram(message)
                print("Telegram Status is :", TelegramMessageStatus)
                
                """ As the above tasks take about 4 seconds approx. to complete, the below sleep is given as 6 . """
                time.sleep(6)
                bolt.digitalWrite('0','LOW')
                bolt.digitalWrite('1','LOW')
        time.sleep(10)

Bolt Cloud JS Code

JavaScript
//Akella Niranjan's JavaScript for Data Visualization!!
var lineGraph = new boltGraph();
lineGraph.setChartType("lineGraph");
setChartTitle("Akella Niranjan's Graphs");
lineGraph.setAxisName('Time','Temperature');
lineGraph.plotChart('time_stamp','temp');
var barGraph = new boltGraph();
barGraph.setChartType("barGraph");
barGraph.setAxisName('Time','Temperature');
barGraph.plotChart('time_stamp','temp');
var scattergraph = new boltGraph();
scattergraph.setChartType("scatterGraph");
scattergraph.setAxisName("Time","Temperature");
scattergraph.plotChart('time_stamp','temp')
setAnimation(true);
dataDownload(false);

Credits

Niranjan Akella
1 project • 1 follower
Contact

Comments

Please log in or sign up to comment.