IoT Fire Monitoring System Using NodeMCU, Flame Sensor, MQ-2 and DHT11 Using KiwisIoT

by ananthi rk in Circuits > Microcontrollers

22 Views, 0 Favorites, 0 Comments

IoT Fire Monitoring System Using NodeMCU, Flame Sensor, MQ-2 and DHT11 Using KiwisIoT

ChatGPT Image Sep 23, 2026, 12_25_17 PM.png

Fire accidents can cause serious damage to homes, laboratories, offices, industries, and other environments. Early detection of fire and smoke can help provide a quick warning.

In this project, we build a simple IoT Fire Monitoring System using a NodeMCU ESP8266.

The system uses three sensors:

  1. Flame Sensor – detects flame
  2. MQ-2 – measures smoke/gas level
  3. DHT11 – measures temperature and humidity

The sensor data is sent to the KiwisIoT dashboard through Wi-Fi, allowing the readings to be monitored remotely.

Supplies

Hardware Required

  1. NodeMCU ESP8266
  2. Flame Sensor Module
  3. MQ-2 Smoke Sensor
  4. DHT11 Sensor
  5. Jumper Wires
  6. USB Cable
  7. Wi-Fi Network

Software Required

  1. Arduino IDE
  2. ESP8266 Board Package
  3. DHT Sensor Library
  4. KiwisIoT Library
  5. KiwisIoT Dashboard
  6. USB Driver for NodeMCU



Circuit Connections

circuit_image (1).png

Flame Sensor

Flame SensorNodeMCU
VCC 3.3V
GND GND
DO D5

MQ-2 Sensor

MQ-2 NodeMCU
VCC VIN
GND GND
AO A0


DHT11

DHT11 NodeMCU
VCC 3.3V
GND GND
DATA D2


Circuit Overview

┌──────────────────┐
│ NodeMCU ESP8266│
└────────┬─────────┘
│
┌──────────────┼──────────────┐
│ │ │
▼ ▼ ▼
Flame Sensor MQ-2 DHT11
D5 A0 D2
│ │ │
▼ ▼ ▼
Flame Smoke Temperature
Detection Level Humidity
│ │ │
└──────────────┼──────────────┘
▼
Wi-Fi
│
▼
KiwisIoT
Dashboard

KiwisIoT Platform Setup

kiwisiot_832x551 (1).png
kiwisiot_panel_832x551.png
kiwisiot_fire_monitoring_832x551_blurred.png
kiwisiot_smoke_level_832x551_blurred.png
kiwisiot_temperature_832x551_blurred.png
kiwisiot_temperature_832x551_blurred.png

1. Login to KiwisIoT

Open the KiwisIoT platform and log in to your account.

After logging in, create a new dashboard/panel for the Fire Monitoring System.

2. Create a New Panel

Create a panel with the following name:

  1. Panel Name: Fire Monitoring System

3. Add Widgets

Create four widgets in the dashboard.

4. Configure Flame Status

Add a LABEL widget.

  1. Widget Type: LABEL
  2. Name: FLAME STATUS
  3. Channel ID: 0

The ESP8266 sends:

  1. FLAME DETECTED when a flame is detected
  2. NO FLAME when no flame is detected

5. Configure Smoke Level

Add a GAUGE or VALUE DISPLAY widget.

  1. Widget Type: GAUGE / VALUE
  2. Name: SMOKE LEVEL
  3. Channel ID: 1
  4. Unit: %

The MQ-2 sensor reading is converted into a 0–100% scale and sent to Channel 1.


kiwisiot.send("1", String(smokeLevel));

6. Configure Temperature

Add another GAUGE or VALUE DISPLAY widget.

  1. Widget Type: GAUGE / VALUE
  2. Name: TEMPERATURE
  3. Channel ID: 2
  4. Unit: °C

The DHT11 temperature value is sent to Channel 2.


kiwisiot.send("2", String(temperature));

7. Configure Humidity

Add another GAUGE or VALUE DISPLAY widget.

  1. Widget Type: GAUGE / VALUE
  2. Name: HUMIDITY
  3. Channel ID: 3
  4. Unit: %

The DHT11 humidity value is sent to Channel 3.


kiwisiot.send("3", String(humidity));

8. Copy the Topic ID

After creating the dashboard, copy the Topic ID provided by KiwisIoT.

It will look similar to:


dash_XXXXXXXXXXXXX

Replace the placeholder in your Arduino code:


const char* topic = "dash_XXXXXXXXXXXXX";

with your actual Topic ID.

9. Final Dashboard Structure

Your KiwisIoT dashboard should contain:

🔥 Fire Monitoring System

  1. FLAME STATUS → Channel 0 → Flame detected / No flame
  2. SMOKE LEVEL → Channel 1 → Smoke percentage
  3. TEMPERATURE → Channel 2 → Temperature in °C
  4. HUMIDITY → Channel 3 → Humidity in %

Once the ESP8266 connects to Wi-Fi and KiwisIoT, the sensor values will be updated on the dashboard approximately every 5 seconds.

Arduino Code

#include <KiwisIoT.h>
#include <DHT.h>

// WiFi Details
const char* ssid = "YOUR WI-FI NAME";
const char* pass = "YOUR WI-FI PASSWORD";

// KiwisIoT Dashboard Topic ID
const char* topic = "dash_XXXXXXXXXXXXX";

KiwisIoT kiwisiot(ssid, pass, topic);

// Sensor Pins
#define FLAME_PIN D5
#define MQ2_PIN A0
#define DHT_PIN D2

// DHT Sensor Type
#define DHTTYPE DHT11

DHT dht(DHT_PIN, DHTTYPE);

void setup() {

Serial.begin(115200);

pinMode(FLAME_PIN, INPUT);

dht.begin();

// Start WiFi + KiwisIoT
kiwisiot.begin();

Serial.println("Fire Monitoring System Started");
}

void loop() {

// Keep KiwisIoT connection active
kiwisiot.run();

// Flame Sensor
int flame = digitalRead(FLAME_PIN);

if (flame == LOW) {
Serial.println("Flame Detected!");
kiwisiot.send("0", "FLAME DETECTED");
}
else {
Serial.println("No Flame");
kiwisiot.send("0", "NO FLAME");
}

// MQ-2 Smoke Sensor
int smokeRaw = analogRead(MQ2_PIN);

int smokeLevel = map(smokeRaw, 0, 1023, 0, 100);

smokeLevel = constrain(smokeLevel, 0, 100);

Serial.print("Smoke Level: ");
Serial.print(smokeLevel);
Serial.println("%");

kiwisiot.send("1", String(smokeLevel));

// DHT11 Temperature
float temperature = dht.readTemperature();

// DHT11 Humidity
float humidity = dht.readHumidity();

if (!isnan(temperature)) {

Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");

kiwisiot.send("2", String(temperature));
}

if (!isnan(humidity)) {

Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %");

kiwisiot.send("3", String(humidity));
}

Serial.println("----------------------");

delay(5000);
}

Code Explanation

The Arduino program controls the Flame Sensor, MQ-2 Smoke Sensor, DHT11, and communicates with the KiwisIoT dashboard. The code reads the sensor values and sends them to different dashboard channels every 5 seconds.

1. Include Required Libraries


#include <KiwisIoT.h>
#include <DHT.h>

  1. KiwisIoT.h is used to connect the NodeMCU to the KiwisIoT platform.
  2. DHT.h is used to read temperature and humidity from the DHT11 sensor.

2. Wi-Fi Configuration


const char* ssid = "YOUR WI-FI NAME";
const char* pass = "YOUR WI-FI PASSWORD";

These lines store the Wi-Fi network name and password.

Replace the placeholder values with your actual Wi-Fi credentials.

3. KiwisIoT Topic ID


const char* topic = "dash_XXXXXXXXXXXXX";

KiwisIoT kiwisiot(ssid, pass, topic);

The Topic ID identifies the KiwisIoT dashboard that will receive the sensor data.

Replace dash_XXXXXXXXXXXXX with the Topic ID generated from your KiwisIoT dashboard.

4. Define Sensor Pins


#define FLAME_PIN D5
#define MQ2_PIN A0
#define DHT_PIN D2

These definitions specify where each sensor is connected to the NodeMCU:

Sensor NodeMCU Pin
Flame Sensor D5
MQ-2 A0
DHT11 D2

5. Configure the DHT11 Sensor


#define DHTTYPE DHT11

DHT dht(DHT_PIN, DHTTYPE);

Here, the code specifies that the connected sensor is a DHT11.

The dht object is then used to read temperature and humidity.

6. Setup Function


void setup() {

Serial.begin(115200);

pinMode(FLAME_PIN, INPUT);

dht.begin();

kiwisiot.begin();

Serial.println("Fire Monitoring System Started");
}

The setup() function runs only once when the NodeMCU starts.

It performs these operations:

  1. Starts Serial Monitor at 115200 baud.
  2. Configures the Flame Sensor pin as an input.
  3. Starts the DHT11 sensor.
  4. Starts the Wi-Fi and KiwisIoT connection.
  5. Displays a startup message in the Serial Monitor.

7. Keep KiwisIoT Connection Active


kiwisiot.run();

This function is called inside the loop() function to keep the KiwisIoT communication active.

8. Read Flame Sensor


int flame = digitalRead(FLAME_PIN);

The NodeMCU reads the digital output from the Flame Sensor.

The code checks:


if (flame == LOW) {

If the sensor output is LOW, the code treats it as flame detected.


kiwisiot.send("0", "FLAME DETECTED");

The flame status is sent to Channel ID 0.

If no flame is detected:


kiwisiot.send("0", "NO FLAME");

So Channel 0 displays the current flame status.

9. Read MQ-2 Smoke Sensor


int smokeRaw = analogRead(MQ2_PIN);

The NodeMCU reads the analog value from the MQ-2 sensor through A0.

The raw reading is converted into a 0–100 scale:


int smokeLevel = map(smokeRaw, 0, 1023, 0, 100);

Then the value is limited between 0 and 100:


smokeLevel = constrain(smokeLevel, 0, 100);

Finally, the value is sent to KiwisIoT:


kiwisiot.send("1", String(smokeLevel));

Therefore, Channel ID 1 is used for the normalized smoke-level reading.

Note: The 0–100 value is only a normalized sensor reading. It is not a calibrated smoke concentration measurement such as ppm.

10. Read Temperature


float temperature = dht.readTemperature();

The DHT11 measures the temperature and stores the value in the temperature variable.

The code checks whether the reading is valid:


if (!isnan(temperature)) {

If valid, it sends the temperature to Channel ID 2:


kiwisiot.send("2", String(temperature));

The temperature is displayed in degrees Celsius.

11. Read Humidity


float humidity = dht.readHumidity();

The DHT11 also measures humidity.

The code checks whether the value is valid:


if (!isnan(humidity)) {

Then the humidity value is sent to Channel ID 3:


kiwisiot.send("3", String(humidity));

The value is displayed as a percentage.

12. Update Interval


delay(5000);

The program waits for 5 seconds before starting the next reading cycle.

Therefore, the sensor data is updated approximately every 5 seconds.

Channel Mapping Summary

Channel IDSensor/DataOutput

0

Flame Sensor

FLAME DETECTED / NO FLAME

1

MQ-2

Normalized 0–100 reading

2

DHT11

Temperature °C

3

DHT11

Humidity %

So the overall flow is:

Sensors → NodeMCU ESP8266 → Wi-Fi → KiwisIoT → Dashboard

How the System Works

Step 1 – Flame Detection

The Flame Sensor is connected to D5.

When a flame is detected, the sensor output becomes LOW.

The NodeMCU checks:


if (flame == LOW)

and sends:

FLAME DETECTED

to KiwisIoT.

Step 2 – Smoke Detection

The MQ-2 analog output is connected to A0.

The NodeMCU reads the analog sensor value:


int smokeRaw = analogRead(MQ2_PIN);

The raw value is converted into a simple 0–100 scale:


int smokeLevel = map(smokeRaw, 0, 1023, 0, 100);

The result is then displayed on the KiwisIoT dashboard.

Note: This 0–100 value is a normalized sensor reading, not a calibrated smoke concentration measurement such as ppm.

Step 3 – Temperature

The DHT11 measures temperature:


float temperature = dht.readTemperature();

The temperature is sent to KiwisIoT using Channel ID 2.

Step 4 – Humidity

The DHT11 also measures humidity:


float humidity = dht.readHumidity();

The humidity value is sent using Channel ID 3.

Step 5 – IoT Monitoring

The NodeMCU connects to Wi-Fi and sends all sensor readings to KiwisIoT.

The dashboard allows you to monitor:

  1. Flame status
  2. Smoke level
  3. Temperature
  4. Humidity


Testing the Project

ChatGPT Image Sep 22, 2026, 12_44_02 PM.png
ChatGPT Image Sep 22, 2026, 12_45_38 PM.png

After uploading the code to the NodeMCU:

  1. Open the Serial Monitor.
  2. Set the baud rate to 115200.
  3. Wait for the NodeMCU to connect to Wi-Fi.
  4. Place a safe flame source near the Flame Sensor for testing.
  5. Check the flame status.
  6. Test the MQ-2 using a suitable smoke source in a controlled environment.
  7. Observe the temperature and humidity values.
  8. Open the KiwisIoT dashboard.
  9. Verify that all four values are updating.

Expected Serial Monitor Output

Fire Monitoring System Started

No Flame
Smoke Level: 12%
Temperature: 30.00 °C
Humidity: 65.00 %
----------------------

Flame Detected!
Smoke Level: 38%
Temperature: 30.00 °C
Humidity: 65.00 %
----------------------


KiwisIoT Dashboard Result

ChatGPT Image Sep 22, 2026, 12_47_27 PM.png
ChatGPT Image Sep 22, 2026, 12_46_31 PM.png

The final dashboard should contain four widgets:

Flame Status

FLAME DETECTED

Smoke Level

Smoke Level: 38%

Temperature

Temperature: 30°C

Humidity

Humidity: 65%


Applications

This project can be used as an educational prototype for:

  1. Home fire monitoring
  2. Office safety monitoring
  3. Laboratory monitoring
  4. Industrial environment monitoring
  5. Early fire-warning prototypes
  6. IoT-based safety systems
  7. Academic IoT projects


Conclusion

This project demonstrates how NodeMCU ESP8266, Flame Sensor, MQ-2, and DHT11 can be combined with KiwisIoT to create an IoT-based fire monitoring prototype.

The system detects flame, monitors a normalized smoke level, measures temperature and humidity, and sends the collected information to an online dashboard through Wi-Fi.

It provides a useful foundation for developing more advanced IoT-based fire and safety monitoring projects.