Back to All Blog Posts
Tutorial EltroNerd Engineering

Forest Fire Detection System

Forest Fire Detection System using ESP32. This project is perfect for IoT-based environmental monitoring and early fire alert systems.

Forest Fire Detection System using ESP32

Forest fires are devastating and can spread rapidly if not detected early.
This project builds an IoT-based forest fire detection system using ESP32 with multiple sensors to detect smoke, temperature spikes, and gas emissions, enabling real-time alerts.


Hardware Requirements

  • ESP32 Development Board
  • MQ-2 / MQ-135 Gas Sensor (smoke detection)
  • DHT22 or BME280 (temperature & humidity)
  • Flame Sensor (optional, for visible fire detection)
  • Buzzer or Relay Module (for local alarm)
  • Wi-Fi connection for remote alert
  • Jumper wires, breadboard, USB cable

Working Principle

  1. Smoke Detection:

    • MQ-2 or MQ-135 sensors detect smoke particles and dangerous gases.
  2. Temperature & Humidity Monitoring:

    • Rapid rise in temperature or very low humidity can indicate fire conditions.
  3. Flame Detection (Optional):

    • Infrared flame sensors detect visible fire within line-of-sight.
  4. Alert System:

    • ESP32 processes sensor readings.
    • If values exceed thresholds, it triggers:
      • Local buzzer/alarm
      • Wi-Fi notification to server, app, or SMS via cloud service

Arduino Code Example

c

#include <WiFi.h>
#include <DHT.h>

#define DHTPIN 15
#define DHTTYPE DHT22
#define MQ2_PIN 34
#define BUZZER_PIN 23

const char* ssid = "Your_SSID";
const char* password = "Your_PASSWORD";

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(115200);
  dht.begin();
  pinMode(MQ2_PIN, INPUT);
  pinMode(BUZZER_PIN, OUTPUT);

  WiFi.begin(ssid, password);
  Serial.print("Connecting to Wi-Fi");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("\nWi-Fi connected!");
}

void loop() {
  // Read sensors
  float temp = dht.readTemperature();
  float hum = dht.readHumidity();
  int smoke = analogRead(MQ2_PIN);

  Serial.printf("Temp: %.2f °C, Humidity: %.2f %%, Smoke: %d\n", temp, hum, smoke);

  // Simple threshold logic
  if (smoke > 400 || temp > 50) {
    Serial.println("⚠️ Fire Detected!");
    digitalWrite(BUZZER_PIN, HIGH);

    // Optional: send notification via HTTP, MQTT, or cloud service
    // sendAlert(temp, hum, smoke);
  } else {
    digitalWrite(BUZZER_PIN, LOW);
  }

  delay(2000);
}

How to Use

Connect DHT22, MQ-2, and buzzer to ESP32 pins as per code.

Upload the code to ESP32 and open Serial Monitor.

Try this project in your browser

Compile code and simulate hardware output with EltroNerd Cloud IDE.

Launch Cloud IDE