Jeev
Published © CC BY-SA

Arduino Gas Leakage and Flame Detection With Alert System

For the detection of flame I have added the flame sensor and for the detection of gas I have added the MQ2 gas sensor modules!

IntermediateFull instructions provided2 hours4
Arduino Gas Leakage and Flame Detection With Alert System

Things used in this project

Hardware components

Arduino UNO Wifi Rev.2
Arduino UNO Wifi Rev.2
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)

Story

Read more

Schematics

circuit diagram

Code

gas_and_flame_sensor_arduno.ino

Arduino
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

#define flamePin 2
#define gasPin A0
#define buzzer 8
#define ledPin 13 

LiquidCrystal_I2C lcd(0x27, 16, 2); // Change to 0x3F if needed

void setup() {
  pinMode(flamePin, INPUT);
  pinMode(buzzer, OUTPUT);
  pinMode(ledPin, OUTPUT);
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Fire & Smoke");
  lcd.setCursor(0, 1);
  lcd.print("Detector Ready");
  delay(2000);
  lcd.clear();
}

void loop() {
  int flame = digitalRead(flamePin);
  int gasValue = analogRead(gasPin);
  int gasThreshold = 300; // Adjust based on environment

  lcd.setCursor(0, 0);
  lcd.print("Flame: ");
  lcd.print(flame == LOW ? "YES " : "NO  "); // For active LOW sensors

  lcd.setCursor(0, 1);
  lcd.print("Smoke: ");
  lcd.print(gasValue > gasThreshold ? "YES " : "NO  ");

  if (flame == LOW || gasValue > gasThreshold) {
    // Danger detected
    digitalWrite(buzzer, HIGH);

    // Flash LED
    digitalWrite(ledPin, HIGH);
    delay(150);
    digitalWrite(ledPin, LOW);
    delay(150);
  } 
  else {
    // Normal condition
    digitalWrite(buzzer, LOW);
    digitalWrite(ledPin, LOW);
    delay(300);
  }
}

Credits

Jeev
2 projects • 0 followers

Comments