Component guide · Beginner · 3 min read
MQ-4 Methane (CNG) Sensor

Pinout, Wiring and Code
By Geekobot Learning Team · Updated 29 Oct 2026
On this page
The MQ-4 is a heated metal-oxide sensor most sensitive to methane, the main gas in natural gas and CNG. Its module gives an analog voltage that rises with methane level and a digital alarm output set by a trim pot. Power it from 5 V, mount it high because methane rises, and calibrate in clean air before use.
Key specs at a glance
- Detects
- Methane (CNG)
- Range
- About 200 to 10,000 ppm methane
- Heater
- 5 V, about 150 mA (about 0.75 W)
- Output
- Analog (AO) and digital threshold (DO) on modules
- Warm-up
- A few minutes before use; 24 to 48 hours of burn-in for stable readings
- Most sensitive to
- Methane (CH4) and natural gas; low response to alcohol and smoke
Models in this guide
These are alternatives. Pick the one that fits your project; you only need one.
Option 1MQ-4 Methane CNG Gas Detector Module – Analog & TTL Output₹94
Option 2ACEBOTT MQ-4 Natural Gas & Methane Sensor – Analog Output, Easy-Plug Compatible₹419
Option 3DFRobot Gravity Analog CH4 Gas Sensor MQ4 for Arduino – Module Only₹839
Option 4Winsen MQ-4 Methane Gas Sensor Module – Semiconductor Sensor₹129
What the MQ-4 is
The MQ-4 uses the same tin dioxide principle as the other MQ sensors but is most sensitive to methane, the main part of natural gas and CNG. Its resistance falls as methane rises.
It is used in learning projects for kitchen gas leak indicators, biogas monitoring and CNG experiments. MQ sensors are for hobby and learning projects. They are not certified gas alarms; for safety use an approved detector.
MQ-4 pinout
The pins on the MQ-4 and what each one does.
| Pin | Function |
|---|---|
| VCC | 5 V supply for the heater and the comparator |
| GND | Ground |
| AO | Analog output: rises as the gas level rises |
| DO | Digital output from the LM393 comparator; switches at the level set by the trim pot |
- VCC
- 5 V supply for the heater and the comparator
- GND
- Ground
- AO
- Analog output: rises as the gas level rises
- DO
- Digital output from the LM393 comparator; switches at the level set by the trim pot
Wiring the MQ-4
The heater draws about 150 mA, so power it from the 5 V rail, not a 3.3 V pin. The analog output can reach 5 V, so an ESP32 needs a divider (10 kΩ over 20 kΩ gives a third off) on AO.
| MQ-4 pin | Arduino Uno | ESP32 |
|---|---|---|
| VCC | 5V | 5V (VIN) |
| GND | GND | GND |
| AO | A0 | GPIO 34 through a 10k/20k divider |
| DO | D2 (optional) | GPIO 27 (optional, via divider) |
- VCC
- Arduino Uno:
- 5V
- ESP32:
- 5V (VIN)
- GND
- Arduino Uno:
- GND
- ESP32:
- GND
- AO
- Arduino Uno:
- A0
- ESP32:
- GPIO 34 through a 10k/20k divider
- DO
- Arduino Uno:
- D2 (optional)
- ESP32:
- GPIO 27 (optional, via divider)
Example code
Rs/R0 falls as the gas level rises. Convert it to ppm with the curve in the datasheet; treat the result as an estimate, not a certified reading.
const int AO = A0;
const float RL = 10.0; // load resistor on the module, kOhm (check yours)
const float CLEAN_AIR = 4.4; // Rs/R0 in clean air from the datasheet curve
float R0 = 0;
float readRs() {
long sum = 0;
for (int i = 0; i < 50; i++) { sum += analogRead(AO); delay(5); }
float v = (sum / 50.0) * 5.0 / 1023.0;
return RL * (5.0 - v) / v; // sensor resistance, kOhm
}
void setup() {
Serial.begin(115200);
Serial.println("Warming up 3 minutes in clean air...");
delay(180000);
R0 = readRs() / CLEAN_AIR; // calibrate in clean air
Serial.print("R0 = "); Serial.println(R0);
}
void loop() {
float ratio = readRs() / R0; // lower ratio = more gas
Serial.print("Rs/R0 = "); Serial.println(ratio, 2);
delay(1000);
}Setup and tuning
24 to 48 hours for a new sensor.
methane is lighter than air, so mount the sensor high on the wall, near the ceiling.
set R0 in clean air; the clean-air ratio is about 4.4.
use DO for a buzzer, or compare Rs/R0 in code for more control.
What you need
Shop this list7 of 8 found in our store · ₹1,735
MQ-4 methane CNG gas detector module: the sensor this guide coversMQ-4 Methane CNG Gas Detector Module – Analog & TTL Output₹94Closest match, check the specs
ACEBOTT MQ-4 Natural Gas & Methane Sensor – Analog Output, Easy-Plug Compatible: another version this guide coversACEBOTT MQ-4 Natural Gas & Methane Sensor – Analog Output, Easy-Plug Compatible₹419
DFRobot Gravity Analog CH4 Gas Sensor MQ4 for Arduino – Module Only: another version this guide coversDFRobot Gravity Analog CH4 Gas Sensor MQ4 for Arduino – Module Only₹839
Winsen MQ-4 Methane Gas Sensor Module – Semiconductor Sensor: another version this guide coversWinsen MQ-4 Methane Gas Sensor Module – Semiconductor Sensor₹129- Uno R3 development board: the controller used in the wiring tableFind this part
Buzzer module 3.3-5 V: for an audible alarmBuzzer Module 3.3–5V₹27
16x2 LCD with I2C: to show readings on a character display16×2 LCD with I2C (RG1602A)₹179Closest match, check the specs
Dupont jumper wires: for the connectionsDupont Jumper Wires (40 pcs)₹49Closest match, check the specs
Alternatives and when to choose them
- MQ-5: better for LPG (cooking gas cylinders).
- MQ gas sensors: the whole family compared.
- Winsen gas sensor modules: catalytic and MEMS alternatives.
Try it: Voltage divider calculator
Change the values and the diagram and results update as you type.
Common mistakes to avoid
- Mounting it low; methane rises.
- Relying on it as a certified safety alarm.
- Skipping the warm-up and burn-in.
- Running the 150 mA heater from a 3.3 V regulator.
Frequently asked questions
What gas does the MQ-4 detect?
Methane and natural gas (CNG) best, with smaller responses to other gases.
Can the MQ-4 detect LPG?
Weakly. For LPG cylinders, use the MQ-5 or MQ-6.
Where should I mount it?
High up, because methane is lighter than air.
Does it work at 3.3 V?
The heater needs 5 V; the output can be divided down for 3.3 V boards.
How accurate is it?
It gives an estimate; humidity and temperature shift the reading.
Parts for this guide
Calculators
Projects that use it
Put this into practice: 10 step-by-step builds in our project library use parts from this guide.
Keep learning
Sources
Written by the Geekobot team from manufacturer datasheets. Always check the datasheet for the exact part and variant you buy.

