Ever heard of burned down houses and uncontrollable fires. Well, this is a very common thing. Sometimes the fire-fighters reach too late and all is lost. What if there was a system that could detect the fire and immediately signal us through an alarm or a notification on our mobile phone? Wouldn’t that make things easier!!
Well, this can be done using Internet Of Things. If you want to know how to build your very own fire alarm read on.
The objectives of this device are:
- To detect a fire by sensing the temperature when it exceeds the set threshold.
- To alert the people in the vicinity of it by an alarm or by an automated SMS.
To build the circuit for the fire alarm we use the Bolt WiFi module, buzzer and LM35 sensor.
Step 1] Connect the Bolt Wifi module to the USB cable and then to a current source.
Step 2] The circuit is connected as follows:
- VCC pin of the LM35 connects to 5v of the Bolt Wifi module. (White wire)
- Output pin of the LM35 connects to A0 (Analog input pin) of the Bolt Wifi module. (Grey wire)
- GND pin of the LM35 connects to the GND. (Purple wire)
- Positive pin of the buzzer connects to the GPIO pin 0. (Black wire)
- Negative pin of the buzzer connects to the GND. (Purple wire)Use breadboard as required.
Step 3] Now power on the Bolt WiFi Module and ensure it is connected to the WiFi and Bolt Cloud (i.e the blue WiFi LED is stable and the green Cloud LED is on respt.).
If there is still any confusion, refer to https://docs.boltiot.com/docs/setting-up-the-bolt-wifi-module
Step 1] Login to your Bolt Cloud account or create one by visiting https://cloud.boltiot.com/register/
Step 2] Get your device ID (eg. BOLTXXXXXXX)
Step 3] Click on the API tab to get your unique API Key.
Step 1] Login to your Twilio account or create a new one by visiting https://www.twilio.com/
Step 2] Get your Trial Number, Account SID and Auth Token.
Step 1] Open ubuntu server. If you don’t have ubuntu you can download it via VirtualBox.
The link to the softwares is given below:
VirtualBox - https://www.virtualbox.org/wiki/Downloads
Ubuntu Server ISO link - http://releases.ubuntu.com/16.04/ubuntu-16.04.6-server-i386.iso
Step 2] Install the Bolt Python Library:
Login to the Ubuntu server and follow the below steps to use Bolt Python library in your code.
Execute the following commands to:
- Update the packages on Ubuntu
sudo apt-get -y update
- Install python3 pip3
sudo apt install python3-pip
- Installing boltiot library using pip3
sudo pip3 install boltiot
In your ubuntu server, create a file to store your credentials by executing the following command
sudo nano conf.py
Now enter the following code in the file.
SID = 'You can find SID 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 accout API key'
DEVICE_ID = 'This is the ID of your Bolt device'
You have to replace all the above values with your credentials.
Now create your main code file.
sudo nano fire_alarm.py
Enter the following code.
#Code by Annalie D'Almeida
from boltiot import Sms, Bolt
import json, time
max_limit = 400
#Fetch your credentials
mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID)
sms = Sms(conf.SID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER)
#Infinite loop to fetch temperature and check with threshold
print ("Reading sensor value")
response = mybolt.analogRead('A0')
data = json.loads(response)
print("Sensor value is: " + str(data['value']))
sensor_value = int(data['value'])
if sensor_value > max_limit:
response1 = mybolt.digitalWrite('0', 'HIGH')
print("Making request to Twilio to send a SMS")
temperature = (100*sensor_value)/1024
response2 = sms.send_sms("Alert!!! The Fire Alarm has been tripped!! The current temperature of the fire is: " +str(temperature))
print("Response received from Twilio is: " + str(response2))
print("Status of SMS at Twilio is :" + str(response2.status))
response3 = mybolt.digitalWrite('0', 'LOW')
except Exception as e:
print ("Error occured: Below are the details")
You can change the max_limit value based on your average maximum room temperature.
Now let's start our device but before you run the program ensure that the Bolt device is on and the connections are proper then execute the below command.
sudo python3 fire_alarm.py
Here is a video demonstration of the working of the Fire Alarm.
Below is the output after running the code file.
Below is the message received from Twilio.
Yay!!! The fire alarm is working.
Thank You for reading!!