IoTBeginnerPRJ-067

Smart Fire & Gas Detection System Using ESP8266

Lights an LED and sounds a buzzer on flames or a gas leak.

Built and tested by Shahan Fathima K · Industrial Robotics Institute

Circuit diagram of the Smart Fire & Gas Detection System using ESP8266 NodeMCU
Circuit diagram · ESP8266 NodeMCU
LevelBeginner
Build time1–2 hours
BoardESP8266 NodeMCU
Parts8 components

What is the Smart Fire & Gas Detection System?

A safety alarm for kitchens, homes and workshops. A flame sensor watches for fire and an MQ-2/MQ-135 gas sensor checks for harmful gas. The ESP8266 reads both several times a second and turns on a warning LED and buzzer the moment either one detects danger.

How it works

  1. The flame sensor output goes LOW when it sees a flame.
  2. The gas sensor gives a higher reading as gas concentration rises.
  3. If there is a flame or the gas reading is above 400, the LED and buzzer turn on.
  4. Otherwise they stay off; the check repeats every 200 ms.

Parts list

ComponentQty
ESP8266 NodeMCU1
Flame Sensor Module1
Gas Sensor (MQ-2 / MQ-135)1
Buzzer1
LED1
Resistor 220Ω (for LED)1
Jumper WiresAs needed
Power Supply1

Software

  • Arduino IDE

Wiring and connections

FromConnect to
Flame sensor VCC3.3V
Flame sensor GNDGND
Flame sensor OUTD1
Gas sensor VCC5V (VIN)
Gas sensor GNDGND
Gas sensor AOUTA0
LED + (via resistor)D2
Buzzer +D3
LED − / Buzzer −GND

How to build the Smart Fire & Gas Detection System

  1. Connect the flame sensor to 3.3V, GND and D1.
  2. Connect the gas sensor to VIN (5V), GND and A0.
  3. Connect the LED through a resistor to D2 and the buzzer to D3.
  4. Upload the code from the Arduino IDE.
  5. Let the gas sensor warm up, then test with a lighter flame held at a safe distance.

Smart Fire & Gas Detection System code

Complete, tested Arduino C++ code for this project. Copy it into Arduino IDE and upload it to the ESP8266 NodeMCU.

#define flamePin D1
#define gasPin   A0
#define ledPin   D2
#define buzzer   D3

int gasValue = 0;

void setup()
{
  pinMode(flamePin, INPUT);
  pinMode(ledPin, OUTPUT);
  pinMode(buzzer, OUTPUT);
}

void loop()
{
  int flame = digitalRead(flamePin);   // LOW = flame detected
  gasValue = analogRead(gasPin);

  if (flame == LOW || gasValue > 400)
  {
    digitalWrite(ledPin, HIGH);
    digitalWrite(buzzer, HIGH);
  }
  else
  {
    digitalWrite(ledPin, LOW);
    digitalWrite(buzzer, LOW);
  }

  delay(200);
}

Real-world uses

  • Home kitchens
  • Restaurants
  • Labs and workshops
  • Industrial safety

Frequently asked questions

What is a Smart Fire & Gas Detection System?

A safety alarm for kitchens, homes and workshops. A flame sensor watches for fire and an MQ-2/MQ-135 gas sensor checks for harmful gas.

What components are needed for the Smart Fire & Gas Detection System?

You need: ESP8266 NodeMCU (1), Flame Sensor Module (1), Gas Sensor (MQ-2 / MQ-135) (1), Buzzer (1), LED (1), Resistor 220Ω (for LED) (1), Jumper Wires, Power Supply (1). Software: Arduino IDE.

Is the Smart Fire & Gas Detection System project good for beginners?

Yes. It is rated beginner and takes about 1–2 hours to build, using the ESP8266 NodeMCU. The guide on this page explains every connection and step.

Where can I get the code for the Smart Fire & Gas Detection System?

The complete, tested Arduino C++ code is free on this page. Copy it into Arduino IDE and upload it to the board.

Can I buy a kit for the Smart Fire & Gas Detection System?

Yes. IRI sells a kit with the parts for this project (PRJ-067). Message IRI on WhatsApp at +91 86060 82634 for the kit price and delivery details.

Industrial Robotics Institute
Logo