IoT based Fire Security Alarm System using NodeMCU | Custom Android App
In this tutorial we are going to build a fire security alarm using multiple sensors. This project will send an alert whenever it detects fire and smoke. It has also connected with a buzzer and an LED which will act as a audio and visual indication for alert. So lets quickly start building IoT based Fire Security Alarm System using NodeMCU with custom android app.
Below material are needed to build this project.
- ESP8266 NodeMCU x 1
- Flame Sensor x 1
- MQ2 Smoke Sensor x 1
- 5V Buzzer x 1
- Led Any color x 1
- Transistor BC547 x 1
- Resistor 1KΩ x 2
- Jumper cables
Flame sensor is capable of detecting flame and infrared light sources. It can measure the wavelengths ranging from 760 nm to 1100 nm. The module uses a LM393 comparator chip to provide a stable digital output signal. This comparator has a driving ability of 15 mA. This flame detector sensor can be used in different project including fire alarms and other fire detecting devices or projects.
- LM393 comparator chip
- Detection Range: 760 nm to 1100 nm
- Operating Voltage: 3.3 V to 5 V
- Maximum Output Current: 15 mA
- Digital Outputs: 0 and 1
- Detection Angle: about 60 degrees
- Adjustable sensitivity via potentiometer
- LED lights indicators: power (red) and digital switching output (green)
In this project we are using a MQ2 smoke sensor. This sensor can detect various gases including Methane, Butane and LPG. We are using a MQ2 gas sensor module in this project for better interface. Below is the pin diagram of the module.
This pin powers the module, the operating voltage is +5V
This is the ground pin
You can also get digital output from this sensor using this pin, by setting a threshold value using the potentiometer
This pin provides an output of 0-5V analog voltage based on the intensity of the gas
- Operating Voltage is +5V
- Can be used to Measure or detect LPG, Alcohol, Propane, Hydrogen, CO and even methane
- Analog output voltage: 0V to 5V
- Digital Output Voltage: 0V or 5V (TTL Logic)
- Preheat duration 20 seconds
- Can be used as a Digital or analog sensor
- The Sensitivity of Digital pin can be varied using the potentiometer
Here all the red and black wired are Vcc and GND connection. You can also add an additional relay module to switch on exhaust or any other ac appliance. You can modify the code and add it. We are using A0 pin of MQ2 gas sensor and D0 pin of Flame sensor.
This code need ESP8266 Arduino library. You can download Arduino IDE from Here. This is done by selecting Sketch > Include Library > Manage Libraries from the top menu. Now search for ESP8266 and install.
We need to add the below library as well in Arduino development environment. Type in esp8266 firebase and install the below library.
Building Firebase Realtime Database
First login to Firebase and create an account if you are logging in for first time. Enter a name for your project.
As per your requirement you can enable google analytics or disable it and click on Continue. This is optional and doesn’t make any impact if you don’t enable it.
Now your project will be created in sometime. Then click on Continue.
Now click on Realtime Database to create it.
Click on Create Database to build it.
Let the default location be there for your Realtime DB and click on Next.
By default the locked mode will be selected. click on enable.
After enabling, click on Rules and edit rules. Make the read and write as true. Also click on Publish to save changes.
Click on Data to get the the URL of your Realtime database. Copy this and keep it in a notepad. We need this in our Arduino code.
Go to Project settings and collect the required information.
Click on Service accounts and click on Database secrets to get the secret key to connect with your database. Copy and paste it in notepad as we need it in our Arduino code.
Please update the firebase URL, firebase secret key, your wifi ssid along with wifi password to connect with firebase Realtime Database and internet.
Building Android App
Here we have shared the aia file. You can download and import it in MIT App Inventor. Before you create an apk file you have to make changes in the firebase DB as shown below.
Update the Firebase DB secret key in firebase token. Also ass the firebase URL which you have coped earlier along with the project bucket.
Building and Testing
We have connected the components as per the connection diagram and now its time to test the project. For both the alert the buzzer will start beeping.
You will receive below alert notification when flame sensor detects flame or fire. Once the smoke sensor detects smoke or gas leak and the value goes beyond 500 then smoke/ gas leak alert will be detected. You can change the value in the code as per your need.
In this app you have the feature to turn activate or deactivate the alarm. You can modify the project as per your need.
This a multi sensor project where we will interface flame sensor and MQ2 gas sensor with ESP8266 NodeMCU. This will send a notification using blynk app using WiFi. The project is simple and easy to build. This project is for beginners to understand the concepts of sensors and interfacing them. Also the custom android app helps you to control your hardware form anywhere. Don’t forget to share the tutorial with others.
Some more Interesting Projects:
- IoT Vehicle Parking System using ESP8266 and Blynk
- NTP Digital Clock using ESP8266 and OLED Display
- NodeMCU based WiFi Network Scanner with OLED Display
- DHT11 Sensor with ESP-NOW and ESP32
- Raspberry Pi Flask Web Server with DHT11
- ESP32 Web Server PWM based LED Control
- IoT Heart Rate Monitoring with ThingSpeak Platform
- Temperature Monitoring with ESP-DASH Webserver
- Setting up a LDR Sensor with Arduino
- Wemos D1 Mini Web Server based Servo Motor Control
- ESP8266 Web Server for Controlling Electrical Devices
- Controlling ESP32 via Bluetooth using Blynk