IoT based fire alarm system using Nodemcu ESP8266 and Blynk

IoT based fire alarm system using Nodemcu ESP8266 and Blynk

Hello, welcome back. In this tutorial, we will learn how to make a Fire alarm security system using the Nodemcu and Blynk app. This project is mainly based on IoT technology. Also, the system uses a flame sensor to detect fire. The unique feature of this system is that it receives a push notification to your smartphone in the event of a fire at the connected location. That function is performed by the Blynk app. We can use this project mainly for homes, offices, and factories. If you want to do this project with Arduino. For that, click on this link.

The process of this system

When this system is powered on, the Nodemcu board connects to the Blynk cloud through the internet. Then, we can turn ON and OFF this system using the Blynk app interface. When the system is activated, the smartphone receives a push notification as soon as the red LED and buzzer is activated in the event of a fire. Afterward, the system goes back to normal. Then the green LED bulb is activated.

OK, let’s do this project step by step. The required components are given below.

Step 1

Firstly, identify these components.

Step 2

Secondly, connect these components. To do this, use the circuit diagram below.

Step 3

Thirdly, let’s set up the Blynk app. For that, follow the steps below.

  • First, download and install the Blynk app on your smartphone. After, sign up for this app using your email address. Then, run the Blynk app and click the “New project” button.
  • Next, enter the project name as you like. Also, select the device and connection type. Finally, click the “Confirm” button.
  • Wow, now we can see the project interface. Then, click the + icon in the corner. OK, now include a button widget and a notification widget.
  • OK, let’s set up these widgets. First, click the button widget and named it as you like. After, change the PIN as V0 and mode to switch. Customize Other things as you like.
  • Next, click the notification widget and change the priority to HIGH.
  • Then customize these widgets as you like. OK, now the Blynk app is ready.

Step 4

Now, let’s creates the program for this project. It is as follows.

/*Fire alarm security system with Nodemcu
 * http://srituhobby.com
 */
 
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = "";
char ssid[] = "";
char pass[] = "";

BlynkTimer timer;
int pinValue = 0;

#define LED1 D1
#define LED2 D2
#define Buzzer D3
#define Sensor D0

void setup() {
  Serial.begin(9600);
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(Buzzer, OUTPUT);
  pinMode(Sensor, INPUT);
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(1000L, notifiaction);
}
BLYNK_WRITE(V0) {
  pinValue = param.asInt();
}

void notifiaction() {
  int sensor = digitalRead(Sensor);
  if (pinValue == 1) {
    Serial.println("System is ON");
    if (sensor == 1) {
      digitalWrite(LED2, HIGH);
      digitalWrite(LED1, LOW);
      digitalWrite(Buzzer, LOW);
    } else if (sensor == 0) {
      Blynk.notify("WARNING! A fire was detected");
      digitalWrite(LED2, LOW);
      digitalWrite(LED1, HIGH);
      digitalWrite(Buzzer, HIGH);
    }
  } else if (pinValue == 0) {
    Serial.println("System is OFF");
  }
}

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

Code explanation

Firstly, libraries are included.

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

Secondly, let’s include the Blynk auth token and Wi-Fi connection details.

char auth[] = "64snlG7Nr_yeX-PlnjnaDPAySLXBW4au";
char ssid[] = "SriTu Hobby";
char pass[] = "12345";

Then, the LED pin, buzzer pin, and sensor pin are defined.

#define LED1 D1
#define LED2 D2
#define Buzzer D3
#define Sensor D0

In the setup function,

void setup() {
//The serial monitor is beginning
  Serial.begin(9600);
//The LED pins are set as the output pins
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
//The buzzer pin is set as the output pin
  pinMode(Buzzer, OUTPUT);
//The sensor pin is set as the input pin
  pinMode(Sensor, INPUT);
//This code initiates the Blynk library
  Blynk.begin(auth, ssid, pass);
//This code is called the main function
  timer.setInterval(1000L, notifiaction);
}

This code gets values from the Blink app button widget.

BLYNK_WRITE(V0) {
  pinValue = param.asInt();
}

This is the main function of this project,

void notifiaction() {
//This code takes the sensor values and puts them in the variable
  int sensor = digitalRead(Sensor);
//After, these values are checked using the IF condition
  if (pinValue == 1) {
    Serial.println("System is ON");
//If the sensor value is 1, the green LED is activated
    if (sensor == 1) {
      digitalWrite(LED2, HIGH);
      digitalWrite(LED1, LOW);
      digitalWrite(Buzzer, LOW);
//If the sensor value is 0, the red LED and Buzzer turns ON, Also, the push notification is sent to the smartphone
    } else if (sensor == 0) {
      Blynk.notify("WARNING! A fire was detected");
      digitalWrite(LED2, LOW);
      digitalWrite(LED1, HIGH);
      digitalWrite(Buzzer, HIGH);
    }
  } else if (pinValue == 0) {
    Serial.println("System is OFF");
  }
}

In the loop function, the Blynk library is run.

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

Step 5

OK, now select board and port, Afterward, upload this code to the Nodemcu board.

Step 6

Lastly, go to the Blynk app and click the run button. OK, enjoy this project. The full video guide is given below. So, we will meet in the next tutorial.

IoT based fire alarm system using Nodemcu ESP8266 and Blynk

Similar Posts

Leave a Reply

Your email address will not be published.