ESP8266 Smart Gas Leakage Detection Using MQ-2 & KiwisIoT Cloud Platform

by prakatheeshwaranR in Circuits > Microcontrollers

82 Views, 0 Favorites, 0 Comments

ESP8266 Smart Gas Leakage Detection Using MQ-2 & KiwisIoT Cloud Platform

27347515-8009-4e96-b62d-ffa896fada3a.png

Gas monitoring is important in homes, laboratories, industries, kitchens, and other environments where combustible or harmful gases may be present.

In this project, I built a simple IoT-based gas monitoring system using an MQ gas sensor and an ESP8266 NodeMCU (ESP-12E).

The MQ gas sensor detects changes in gas concentration in the surrounding air. The ESP8266 reads the sensor value and sends the data through Wi-Fi to the KiwisIoT cloud dashboard.

The gas level can then be monitored remotely in real time using a Gauge widget.

The basic working flow is:

Gas in Air → MQ Gas Sensor → ESP8266 → Wi-Fi → KiwisIoT Cloud → Live Dashboard

This is a beginner-friendly project for learning how sensors, microcontrollers, Wi-Fi, and IoT dashboards work together.

Note: This project is intended for learning and prototyping. It should not be used as a certified life-safety or industrial gas alarm.


Supplies

For this project, I used:

  1. ESP8266 NodeMCU development board with ESP-12E module
  2. MQ-series gas sensor module
  3. Jumper wires
  4. Micro-USB cable
  5. Laptop/PC
  6. Wi-Fi connection
  7. Arduino IDE
  8. KiwisIoT account/dashboard
  9. Platform:https://kiwisiot.in/

For your Supplies section, upload your separate ESP8266 photo and separate MQ sensor photo. Those real photos are much better here than generated component images.

Understanding the ESP8266 NodeMCU

342af9f6-d79b-4b9e-ae3d-8ee59dcc4c03.png
74c868ea-2e87-41d3-a59e-30c7ee745bcf.png

The ESP8266 NodeMCU is a Wi-Fi-enabled development board based on the ESP8266 microcontroller.

It is useful for IoT applications because it can read sensor data, process the readings, connect directly to a Wi-Fi network, and communicate with an online IoT platform.

In this project, the ESP8266 performs two main jobs:

  1. Reads the gas sensor value.
  2. Sends the reading to the KiwisIoT dashboard through Wi-Fi.


Understanding the ESP8266 NodeMCU

74c868ea-2e87-41d3-a59e-30c7ee745bcf.png

The MQ-series gas sensor is designed to respond to gases present in the surrounding air.

The module provides a signal whose value changes according to the sensor response.

For this project, we use the sensor reading as our Gas Value and send it to the ESP8266.

The sensor module generally provides pins such as:

VCC – Power

GND – Ground

AO – Analog Output

DO – Digital Output, if provided by the module

The analog output is useful when we want to observe changes in the sensor reading instead of only receiving a simple HIGH/LOW indication.

Connect the MQ Sensor to ESP8266

59a19f4e-7954-4264-83dc-6fc0b55bad66.png

Connect the MQ gas sensor module to the ESP8266 NodeMCU.

For the analog-reading part of this project, the important connections are:

MQ Sensor ESP8266 NodeMCU

GND → GND
AO → A0
Power → According to sensor module requirement

Important: ESP8266 I/O works at 3.3 V, and the allowable A0 input depends on the exact NodeMCU board design. Some MQ modules are powered at 5 V and can produce an output higher than the ESP8266 ADC can safely accept. Check your specific sensor module and NodeMCU specifications and use a voltage divider/level conditioning when necessary.

After completing the connections, connect the ESP8266 to the computer using the USB cable.

Install and Configure Arduino IDE

lo.jpeg

Download and install the Arduino IDE.

Then add ESP8266 board support and select the appropriate NodeMCU board.

Typical setup:

Board:
NodeMCU 1.0 (ESP-12E Module)

Port:
Select the COM port assigned to your ESP8266

Connect the board using the USB cable and verify that Arduino IDE detects the correct port.

Read the Gas Sensor Value

249b072a-3aa0-486e-bff2-6bba71769b18.png

Before connecting the project to the cloud, first verify that the ESP8266 is receiving sensor readings correctly.

A basic analog test can be done with:


#define GAS_PIN A0

void setup() {
Serial.begin(9600);
}

void loop() {

int gasValue = analogRead(GAS_PIN);

Serial.print("Gas Value = ");
Serial.println(gasValue);

delay(1000);
}

Upload the program and open:

Tools → Serial Monitor

Set:

Baud Rate: 9600

You should start seeing values similar to:

Gas Value = 235
Gas Value = 236
Gas Value = 235
Gas Value = 236

The values will change according to the sensor response.

Image: This is exactly where your Arduino screenshot should go. Your screenshot already shows readings around 235–236, so it provides good evidence that the sensor and ESP8266 are communicating.

Don't describe 235 as a specific gas concentration or danger level unless you have calibrated the particular MQ sensor for the target gas.

Convert It Into an IoT Project

Screenshot 2026-09-09 124924_832x551.png

Once the sensor reading is working correctly, the next step is to send the data to the cloud.

The ESP8266 connects to the Wi-Fi network and sends the gas sensor value to the KiwisIoT platform.

The complete data flow becomes:

GAS IN AIR
↓
MQ GAS SENSOR
↓
Analog Reading
↓
ESP8266 NodeMCU
↓
Wi-Fi
↓
KiwisIoT Cloud
↓
Live Dashboard
↓
Monitor / Alert

This is what converts our basic sensor project into an IoT project.

Instead of viewing the reading only on the computer connected to the ESP8266, we can monitor the sensor through an online dashboard.

Connect ESP8266 to KiwisIoT

Screenshot 2026-09-09 124924_832x551.png
Screenshot 2026-09-09 124913_832x551.png

In my project, I used the KiwisIoT library to connect the ESP8266 to the KiwisIoT platform.

The program follows this structure:


/*
* Kiwistrons
* KiwisIoT - MQ-2 Gas Sensor
* NodeMCU ESP8266
*/

#include <KiwisIoT.h>

const char* ssid = "YOUR_WIFI_NAME";
const char* pass = "YOUR_WIFI_PASSWORD";
const char* topic = "dash_1787738664437";

KiwisIoT kiwisiot(ssid, pass, topic);

#define GAS_PIN A0

void setup() {

Serial.begin(9600);

kiwisiot.begin();
}

void loop() {

kiwisiot.run();

// Read MQ-2 analog value
int gasValue = analogRead(GAS_PIN);

// Send gas value to Channel ID 1
kiwisiot.send("1", gasValue);

Serial.print("Gas Value = ");
Serial.println(gasValue);

delay(1000);
}

Replace the Wi-Fi and topic details with your own credentials.

Very important before publishing: Don't put your real Wi-Fi password, private API keys, access tokens, or other credentials in the Instructables screenshots/code. Blur or replace them with placeholders such as YOUR_WIFI_PASSWORD.

Monitor the Gas Value on KiwisIoT Dashboard

Screenshot 2026-09-09 124924_832x551.png

After the ESP8266 connects successfully, the gas sensor data is transmitted to the KiwisIoT dashboard.

I added a Gauge widget to display the live sensor value.

During testing, the dashboard displayed a value such as:

285

The gauge provides a simple visual way to monitor changes in the sensor reading.

The complete communication is:

MQ Sensor → ESP8266 → Wi-Fi → KiwisIoT → Gauge

Your KiwisIoT screenshot is perfect for this step because it visibly shows:

Connected → Online → Gauge → 285

How the Complete System Works

The complete operation can be understood in five stages.

1. Detection: The MQ sensor responds to gas in the surrounding air.

2. Reading: The ESP8266 reads the analog sensor signal through the configured analog input.

3. Processing: The ESP8266 converts the ADC result into a value that can be displayed and transmitted.

4. IoT Communication: Using its built-in Wi-Fi capability, the ESP8266 sends the value to KiwisIoT.

5. Monitoring: The KiwisIoT dashboard receives the data and displays the current gas sensor reading using the Gauge widget.


Testing the Project

Power the ESP8266 through USB and allow the MQ sensor enough time to stabilize according to the sensor manufacturer's recommendations.

Open Arduino Serial Monitor and confirm that values are being received.

Then open the KiwisIoT dashboard.

Check that:

MQ Sensor
↓
ESP8266 receives reading
↓
Serial Monitor shows Gas Value
↓
ESP8266 sends data through Wi-Fi
↓
KiwisIoT receives data
↓
Gauge displays live value

During my test, the Serial Monitor showed values around 235–236, while the dashboard screenshot captured a later live value of 285.

Possible Improvements

This basic project can be expanded with additional features.

You can add a buzzer and warning LED for local alerts, configure dashboard alerts, add an OLED/LCD display, store historical readings, add multiple sensors, or create automatic control using a relay.

A more advanced version could follow:

Gas detected → ESP8266 → Cloud → Alert → Exhaust fan/relay control

For meaningful gas concentration or alarm thresholds, however, the sensor should be properly calibrated for the particular gas and application.

Applications

This type of IoT gas-monitoring prototype can be used as a learning foundation for projects involving:

  1. Smart-home environmental monitoring
  2. Kitchen monitoring prototypes
  3. Laboratory demonstrations
  4. Industrial IoT education
  5. Air-quality experiments
  6. IoT sensor-data logging
  7. Remote environmental monitoring

For real safety-critical environments, certified gas-detection equipment should be used rather than a hobby MQ/ESP8266 prototype.

Conclusion

In this project, we successfully interfaced an MQ gas sensor with an ESP8266 NodeMCU and monitored the sensor reading using the KiwisIoT IoT dashboard.

First, the ESP8266 reads the analog sensor value. We verified the reading using Arduino Serial Monitor. The ESP8266 then uses Wi-Fi to transmit the data to KiwisIoT, where it can be displayed using a live Gauge widget.

The project demonstrates the basic IoT workflow:

Sense → Read → Process → Connect → Send → Monitor

It is a simple starting point for beginners who want to learn ESP8266, sensors, Arduino programming, Wi-Fi communication, and IoT dashboards.

Best order for your actual images

Use your ESP8266 close-up in Step 1, MQ sensor close-up in Step 2, connected hardware photo in Step 3, Arduino Serial Monitor screenshot in Step 5/7, and KiwisIoT Gauge screenshot in Step 8. That sequence tells the story naturally: components → wiring → code → sensor data → cloud result.