praveen kumar
Published

Accidental Fire Alert System Built with Bolt - IoT

Project made with Bolt - IoT

IntermediateFull instructions provided2 hours836
Accidental Fire Alert System Built with Bolt - IoT

Things used in this project

Hardware components

LED (generic)
LED (generic)
×2
Through Hole Resistor, 330 kohm
Through Hole Resistor, 330 kohm
×2
LM35 temperature sensor
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Buzzer
Buzzer
×1
Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1

Software apps and online services

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

Story

Read more

Schematics

Accidental fire alert system

Code

Main source code acc_fire.py

Python
make a file in ubuntu server and paste it
from boltiot import Bolt , Sms
import time , conf , json , sys , statistics
r = 5
c = 5
data_set = []
alarm_state = 0

mybolt = Bolt(conf.API_KEY,conf.DEVICE_ID)#importing bolt api key and devide id from conf.py
sms = Sms(conf.SSID,conf.AUTH_TOKEN,conf.TO_NUM,conf.FROM_NUM)# importing twillo ssid , auth ,and numbers

def check_device(): #  function for checking the device 
        data = json.loads(mybolt.isOnline())
        if data["value"]=="online":
                print('Device online')
                mybolt.digitalWrite("1","HIGH")
        else:
                print('Device offline.')
                sys.exit()

def get_temp():# function for getting temp values
        data = json.loads(mybolt.analogRead("A0"))
        if data["success"]==1:
                val =float(data["value"])
                temp =  100 * val / 1024
                return temp

        else:
                return -999

def set_limits(data_set,r,c):# function for z-score
        if len(data_set)<r:
                return None
        if len(data_set)>r:
                data_set=data_set[len(data_set)-r:]

        Mn = statistics.mean(data_set)
        Variance = 0
        for data in data_set:
                Variance += (data - Mn) ** 2
        Zn = c * ((Variance / r) ** 0.5)
        H = data_set[r-1] + Zn
        return H

def run_alarm(val): #function for buzzor and sms
        print('Risk of a possible firm.Raising alarm.')
        sms.send_sms('Sudden raise in temperature. Can be possibly a fire. The temperature is '+str(val))
        mybolt.digitalWrite('0','HIGH')
        global alarm_state
        alarm_state = 1

def stop_alarm(val):
                mybolt.digitalWrite('0','LOW')

check_device()

while 1: # indefinite loop for countinous tracking of temparature
        try:
                temp = get_temp()
                print('The temperature is ',temp)
                limit=set_limits(data_set,r,c)
                if not limit:
                        print('Not enough value to conduct Z-score analysis.Need more values.')
                        data_set.append(temp)
                else:
                        if temp > limit:
                                run_alarm(temp)
                        else:
                                if alarm_state:
                                        stop_alarm(temp)
                                        alarm_state = 0
                        data_set.append(temp)

                time.sleep(10)

        except KeyboardInterrupt: # press ctrlc + c for stopping the loop
                print('Device Stopped.')
                mybolt.digitalWrite('1','LOW')
                mybolt.digitalWrite('0','LOW')
                sys.exit()

conf.py

Python
second code
API_KEY = "YOUR_API_KEY" #change the values here and keep the original device details
DEVICE_ID = "BOLTXXXXXXX"
SID = "FOUND_IN_TWILIO_ACCOUNT"
AUTH_TOKEN = "FOUND_IN_TWILIO_ACCOUNT"
FROM_NUM = "FOUND_IN_TWILIO_ACCOUNT"
TO_NUM = "YOUR_NUMBER"

Credits

praveen kumar
1 project • 0 followers

Comments