NextPCB
Published © Apache-2.0

IoT Based Fire Alarm System Using NodeMCU ESP8266

This a multi sensor project where we will interface flame sensor and MQ2 gas sensor with ESP8266 NodeMCU.

IntermediateFull instructions provided1 hour27,554
IoT Based Fire Alarm System Using NodeMCU ESP8266

Things used in this project

Story

Read more

Schematics

Schematics

Code

Code

Arduino
//Nextpcb
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

int led = 13; // Connected to D7 pin of NodeMCU
int flame_sensor = 12; //Connected to D6 pin of NodeMCU
int buzzer = 4; //Connected to D2 pin of NodeMCU
int relay = 5; //Connected to D1 pin of NodeMCU
int smoke_sensor = A0; //Connected to A0 pin of NodeMCU
int temp_smoke_sensor;
int flame_sensor_read;

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "Auth Token"; // Enter Auth Token

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Your WiFi SSID"; //Enter the wifi name
char pass[] = "Your WiFi Password";// Enter the wifi password

void setup()
{
  pinMode(led, OUTPUT);
  pinMode(flame_sensor, INPUT);
  pinMode(buzzer, OUTPUT);
  pinMode(relay, OUTPUT);
  pinMode(smoke_sensor, INPUT);
  
  digitalWrite(led, LOW);
  digitalWrite(buzzer, LOW);
  digitalWrite(relay, LOW);
  // Debug console
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
}

void loop() 
{
  flame_sensor_read = digitalRead(flame_sensor); //reading the sensor data on A0 pin
  Blynk.virtualWrite(V0, flame_sensor_read); //sending data to Blynk
  Serial.print("Flame Status:");
  Serial.println(flame_sensor_read);

  int led_status = digitalRead(led);
  if (led_status == HIGH)
  {
   Blynk.virtualWrite(V1, 255);
  }
  else
  {
   Blynk.virtualWrite(V1, 0);
  }
  
  temp_smoke_sensor = analogRead(smoke_sensor);
  Blynk.virtualWrite(V2, temp_smoke_sensor);
  Serial.print("Current Gas Level:");
  Serial.println(temp_smoke_sensor);
  if (temp_smoke_sensor > 500)
  {
    digitalWrite(led, HIGH);
    digitalWrite(buzzer, HIGH);
    digitalWrite(relay, HIGH);
    Blynk.notify("Alert Smoke Detected");  
    }
  else
    {
     digitalWrite(led, LOW);
     digitalWrite(buzzer, LOW);
     digitalWrite(relay, LOW);
    }

if (flame_sensor_read == 0)
    {
    //Blynk.virtualWrite(V1, 255);
    digitalWrite(led, HIGH);
    digitalWrite(buzzer, HIGH);
    digitalWrite(relay, HIGH);
    Blynk.notify("Alert Fire Detected");  
    }
  else
      {
      digitalWrite(led, LOW);
      digitalWrite(buzzer, LOW);
      digitalWrite(relay, LOW);
      }
      delay(500);
      Blynk.run();
}

Credits

NextPCB

NextPCB

21 projects • 45 followers
We share Electrical, Electronics, Power, Robotics, Software, Communication, IOT “Internet Of Things”, based projects

Comments