IoT based Fire Security Alarm System using NodeMCU | Custom Android App

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.

Materials Required

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
  • Breadboard

Flame Sensor

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.

Specifications:

  • 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)

Smoke Sensor

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.

Pin Number

Pin Name

Description

1

Vcc

This pin powers the module, the operating voltage is +5V

2

Ground

This is the ground pin

3

Digital Out

You can also get digital output from this sensor using this pin, by setting a threshold value using the potentiometer

4

Analog Out

This pin provides an output of 0-5V analog voltage based on the intensity of the gas

Specifications:

  • 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

Connection

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.

IoT based Fire Security Alarm System using NodeMCU

Arduino Library

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.

Arduino config

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.

IoT Door Security with custom Android App using Firebase

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.

IoT Door Security with custom Android App using Firebase

Code

You can download the Arduino code from link below and open it using Arduino IDE. Please update the below changes and then upload the code in NodeMCU.

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.

IoT based Fire Security alarm system using NodeMCU

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.

IoT based Fire Security alarm system using NodeMCU

Summary

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:

1 thought on “IoT based Fire Security Alarm System using NodeMCU | Custom Android App”

Leave a Comment