IoT based Fire Detector & Automatic Extinguisher using NodeMCU

IoT based Fire Detector & Automatic Extinguisher using NodeMCU

IoT Projects

Nowadays, Fire detecting and Alerting system are very common in banks, offices, homes, etc. They usually detect fire and alert people with a siren. But, what happens, when nobody is there to listen to Alarm. Like when nobody is at home or office. So, to inform the authority about fire incidents and to automatically extinguish the fire. We have made this IoT Fire Detector & Automatic Extinguisher using the NodeMCU project. This project can be further modified to notify the fire control department automatically.

This IoT based project detects the nearby flame using an Infrared Flame Sensor and then NodeMCU Tiggers the relay to extinguish the fire automatically. It also informs the authority using IoT Blynk Application. With the help of this project, you can easily understand the concept of a fire detector and alert system.

Requirements for IoT Fire Detector and extinguisher system

The following are the components required for making IoT based fire detector and automatic extinguisher system using NodeMCU:

  • NodeMCU ESP8266 12-E Development Board
  • A Relay Module
  • Infrared Flame Sensor
  • A LED
  • 12 volt DC Fan
  • Few jumpers wires
  • Breadboard
  • 12-volt adaptor

Circuit Diagram

Now let’s start assembling all the components for IoT based Fire detector and automatic extinguisher system using NodeMCU(ESP8266) and flame sensor.

Circuit Diagram of IoT based Fire Detector & Automatic Extinguisher using NodeMCU
Circuit Diagram of IoT based fire extinguisher project
  • First of all, connect the Vin pin to the positive rail on the breadboard.
  • Then connect GND Pin to the negative rail of the breadboard.
  • To interfere with the flame sensor Connect Vcc and GND to Vcc and GND on the breadboard.
  • Now Connect the D0 pin(signal pin of the flame sensor) to the D1 pin of NodeMCU (ESP8266).
  • Now let’s connect the Negative terminal of LED to GND Pin of NodeMCU and PositiveTerminal to D2 pin.
  • Similarly, interface single channel relay GND and Vcc pin to GND and Vcc. Then, Input Pin to NodeMCU D4 Pin.
  • Now, connect the 12v DC fan positive terminal to normally open (NO) Pin, connect the positive terminal 12V adaptor to the common pin of the relay.
  • Finally, the Negative Terminal of the DC fan to the 12v adaptor Negative Terminal.

Note: Here, the relay module works as a switch. we have successfully assembled the circuit. Now let’s get into the programming part. The programming code is provided below.

IoT based Fire Detector App designed on Blynk

I have done many projects related to IoT with the Blynk application and designed many apps before. In this session, I am designing IoT based Fire Alert Notifier and an automatic extinguisher App. So, Make sure you download and install the Blynk app from Playstore/Appstore.

  • First of all, open the blynk application.
  • Click on the create a new project and enter the project name as “IoT Fire Control“. Instead, you can type any name. You can change the name later.
  • Click on Choice Tools and select NodeMCU ESP8266.
  • Make sure the connection type is set to WIFI.
  • Finally, click on the create button, a verification token will be sent to your email ID, which will be used in the Program CODE.
  • Click anywhere on the screen, and search for the Notification Widget. Now Your designed IoT Fire Control application is ready to use.
  • Blynk App configuration for IoT based Fire Detector - Create Project
  • Blynk App configuration for IoT based Fire Detector Projects Details WiFi NodeMCU ESP8266
  • Blynk App configuration for IoT Fire Detector & Automatic Extinguisher Notification
  • Blynk App Fire Alert Notification
  • Blynk IoT Fire Alarm Notification

Program Code Explanation

The program code for IoT Fire Detector & Automatic Extinguisher using NodeMCU is very easy and simple to understand. Anyone with a piece of basic knowledge can code the program for this system.

First of all, I started adding the libraries required for a Fire Detector & Automatic Extinguisher using ESP8266. The download link is provided below.

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

Here, integer variable LED, Relay, and flame sensor pins are defined according to our circuit diagram. The flame_detected integer variable is defined to read the value from the flame sensor.

int LED = D2;
int RELAY = D4;
int Flame_sensor = D1;
int Flame_detected;

Replace the following Blynk authentication token, WiFi SSID, and Password credentials with yours. This is the authentication token which was sent via email while building the Blynk IoT App. This authentication token will be mailed to your registered email ID.

Blynk App configuration Auth Token For Program Code
Blynk Authentication Token on E-Mail
char auth[] = "jovd0wly3APhqOwX6XJzwN4j0m6wpTwR"; //Auth code sent via Email
char ssid[] = "Alsan";
char pass[] = "12345678"

Custom function notifyOnFire() is created to read data, execute commands to tigger relay and notify the user through Blynk IoT platform.

void notifyOnFire()

Here Flame_Detected read the data from the flame sensor and Print its value in the serial monitor. If its value is =0 then, Information is printed on the serial monitor as “Flame detected…! take action immediately”. At the same time, it triggers a notification on Blynk App, a Red LED is turned on as an indication, and Relay is turned ON to run a fan at a very high speed to extinguish the fire.

Flame_detected = digitalRead(Flame_sensor);
  Serial.println(Flame_detected);
  //delay(100);
  if (Flame_detected == 0) {
    Serial.println("Flame detected...! take action immediately.");
    Blynk.notify("Alert : Fire detected...! take action immediately.");
    digitalWrite(LED, HIGH);
    digitalWrite(RELAY, LOW);
    delay(500);

In Else Condition it simply Print “No Fire detected. stay cool” on serial monitor and Relay and LED remains on OFF state.

else
  {
    Serial.println("No Fire detected. stay cool");
    digitalWrite(LED, LOW);
    digitalWrite(RELAY, HIGH);
  }

Basically, on the setup part, Serial Monitor is initiated at the baud rate of 115200 with serial.begin function. Blynk WiFi authentication is initiated with Blynk.begin, and pinMode function is initialized as OUTPUT for LED and Relay. Similarly, for a flame sensor, the Input_Pullup argument is used. and finally timer interval for function notifyOnFire is defined as 1000L

void setup()
{
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);
  pinMode(LED, OUTPUT);
  pinMode(RELAY, OUTPUT);
  digitalWrite(RELAY, HIGH);
  pinMode(Flame_sensor, INPUT_PULLUP);
  timer.setInterval(1000L, notifyOnFire);
}

On a Loop, part two function Blynk.run() and timer.run are executed.

void loop()
{
  Blynk.run();
  timer.run();
}

Isn’t the programming code is super easy to understand? However, if you still have any queries regarding this program code. You can ask me in the comment section below.

IoT Fire Detector & Automatic Extinguisher using NodeMCU Program Code

This is the full program code for IoT Fire Detector & Automatic Extinguisher using the NodeMCU project. just copy the below code and paste it in your Arduino IDE Program.

//Welcome to The IoT Projects
//IoT Based Fire Alarm Notification and control system using ESP8266
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>


int LED = D2;
int RELAY = D4;
int Flame_sensor = D1;
int Flame_detected;

BlynkTimer timer;
char auth[] = "jovd0wly3APhqOwX6XJzwN4j0m6wpTwR"; //Auth code sent via Email
char ssid[] = "Alsan";
char pass[] = "12345678";

void notifyOnFire()
{
  Flame_detected = digitalRead(Flame_sensor);
  Serial.println(Flame_detected);
  //delay(100);
  if (Flame_detected == 0) {
    Serial.println("Flame detected...! take action immediately.");
    Blynk.notify("Alert : Fire detected...! take action immediately.");
    digitalWrite(LED, HIGH);
    digitalWrite(RELAY, LOW);
    delay(500);
  }
  else
  {
    Serial.println("No Fire detected. stay cool");
    digitalWrite(LED, LOW);
    digitalWrite(RELAY, HIGH);
  }
}
void setup()
{
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);
  pinMode(LED, OUTPUT);
  pinMode(RELAY, OUTPUT);
  digitalWrite(RELAY, HIGH);
  pinMode(Flame_sensor, INPUT_PULLUP);
  timer.setInterval(1000L, notifyOnFire);
}
void loop()
{
  Blynk.run();
  timer.run();
}

Uploading Code

Now go to the Tools menu and select the NodeMCU ESP8266 12-E Development board and its COM Port. Now, click on upload to upload the code to the NodeMCU.

After successful upload, open your serial monitor at the baud rate of 115200 to see the status.

data on serial monitor

Video Demonstration of IoT based Fire Detector & Automatic Extinguisher using NodeMCU

IoT based Fire Alarm Notification using NodeMCU and Blynk app

Watch the video below which demonstrate IoT based Fire Detector & Automatic Extinguisher using NodeMCU. If you like this video please subscribe to this channel. Your one subscribe can make our day.

Wrapping up

So that’s all for today. We have successfully made an IoT based Fire Detector & Automatic Extinguisher using NodeMCU. I hope this tutorial was helpful to you.

Recommended projects

Alsan Parajuli

I am a WordPress enthusiast, a hardworking and highly positive person. I always believes in practicality rather than theoretical knowledge. With my curiosity and fast learning skills, I managed to learn everything on my own. I love coding, editing, writing and rummaging around Internet. I am passionate about IoT Projects, Digital marketing, website designing, and reviewing. Moreover, I had been contributing to WordPress Biratnagar as an active member since 2018.

https://theiotprojects.com/

Leave a Reply