Component guide · Beginner · 3 min read
MQ-2 gas sensor

Pinout, Wiring and Code
By Geekobot Learning Team · Updated 29 Oct 2026
On this page
The MQ-2 module detects smoke and flammable gases such as LPG, propane, methane and hydrogen. It has an analog output that rises as gas concentration rises, and a digital output that switches at a level set by the trimmer. Its heater needs 5 V and about 150 mA, and readings settle only after a few minutes of warm-up.
Key specs at a glance
- Detects
- LPG, propane, methane, hydrogen, alcohol, smoke
- Range
- About 300 to 10,000 ppm (combustible gas)
- Heater
- 5 V, about 150 mA (0.9 W)
- Outputs
- AO analog, DO digital (LM393 comparator with trimmer)
- Warm-up
- A few minutes for use, 24 to 48 hours burn-in for a new sensor
- Supply
- 5 V
Models in this guide
These are alternatives. Pick the one that fits your project; you only need one.
Option 1MQ-2 Smoke LPG Butane Hydrogen Gas Sensor Module – 5V Analog/Digital Output₹82
Option 2Waveshare MQ-2 Combustible Gas Sensor Module – Analog & Digital Output₹449
Option 3Winsen MQ-2 Smoke & Flammable Gas Sensor Module₹110
Option 4Seeed Studio Grove MQ2 Gas Sensor Module – Analog Output₹919
Option 5DFRobot Gravity Analog Gas Sensor MQ2 for Arduino – Analog Output₹839
What the MQ-2 gas sensor is
The MQ-2 is a metal-oxide gas sensor. A tin dioxide layer is heated, and its resistance falls when combustible gases or smoke reach it. The module turns that change into a voltage.
It is good for detecting a change, such as a gas leak or smoke, in a learning project or alarm demo. It is not selective between gases and is not a certified safety device.
MQ-2 gas sensor pinout
The pins on the MQ-2 gas sensor and what each one does.
| Pin | Function |
|---|---|
| VCC | 5 V (heater and circuit) |
| GND | Ground |
| AO | Analog output, higher = more gas |
| DO | Digital output, switches when AO crosses the trimmer setting |
- VCC
- 5 V (heater and circuit)
- GND
- Ground
- AO
- Analog output, higher = more gas
- DO
- Digital output, switches when AO crosses the trimmer setting
Wiring the MQ-2 gas sensor
On an ESP32, AO can reach 5 V, so scale it with a divider (10 kΩ over 20 kΩ) before the ADC. The heater draws 150 mA; power it from the 5 V rail, not a 3.3 V pin.
| MQ-2 gas sensor pin | Arduino Uno | ESP32 |
|---|---|---|
| VCC | 5V | 5V (VIN) |
| GND | GND | GND |
| AO | A0 | GPIO 34 via 10k/20k divider |
| DO | D2 | GPIO 27 |
- VCC
- Arduino Uno:
- 5V
- ESP32:
- 5V (VIN)
- GND
- Arduino Uno:
- GND
- ESP32:
- GND
- AO
- Arduino Uno:
- A0
- ESP32:
- GPIO 34 via 10k/20k divider
- DO
- Arduino Uno:
- D2
- ESP32:
- GPIO 27
Example code
Most modules pull DO LOW when gas is detected; check yours. The threshold above the baseline needs tuning for your room.
const int AO_PIN = A0, DO_PIN = 2, BUZZER = 8;
int baseline;
void setup() {
Serial.begin(9600);
pinMode(DO_PIN, INPUT); pinMode(BUZZER, OUTPUT);
Serial.println("Warming up 60 s...");
delay(60000);
baseline = analogRead(AO_PIN); // clean-air reading
}
void loop() {
int v = analogRead(AO_PIN);
bool alarm = v > baseline + 150 || digitalRead(DO_PIN) == LOW;
digitalWrite(BUZZER, alarm);
Serial.print(v); Serial.println(alarm ? " GAS!" : "");
delay(500);
}Setup and tuning
run a new sensor for 24 to 48 hours before trusting its baseline.
turn it until the DO LED is just off in clean air; then gas turns it on.
converting to ppm needs calibration in a known gas concentration and the datasheet curve; treat raw values as relative.
never use it as the only protection against gas leaks or fire; use certified alarms.
What you need
Shop this list6 of 7 found in our store · ₹2,425
MQ-2 smoke, LPG, butane, hydrogen gas sensor module: the common moduleMQ-2 Smoke LPG Butane Hydrogen Gas Sensor Module – 5V Analog/Digital Output₹82
Waveshare MQ-2 gas sensor module: alternative boardWaveshare MQ-2 Combustible Gas Sensor Module – Analog & Digital Output₹449
Winsen MQ-2 smoke and flammable gas sensor: the original maker's sensorWinsen MQ-2 Smoke & Flammable Gas Sensor Module₹110
Seeed Grove MQ2 gas sensor: Grove connectorSeeed Studio Grove MQ2 Gas Sensor Module – Analog Output₹919
DFRobot Gravity analog MQ2 sensor: Gravity connectorDFRobot Gravity Analog Gas Sensor MQ2 for Arduino – Analog Output₹839- 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
Alternatives and when to choose them
- MQ-135: air quality (NH3, CO2-related, benzene) rather than flammable gas.
- MQ gas sensors guide: MQ-3, MQ-7 and others compared.
- Electrochemical gas sensors: selective and calibrated for specific gases.
Try it: Voltage divider calculator
Change the values and the diagram and results update as you type.
Common mistakes to avoid
- Reading it immediately after power-on.
- Feeding 5 V AO directly into an ESP32 pin.
- Treating it as a certified smoke or gas alarm.
- Expecting it to tell which gas it detects.
Frequently asked questions
What gases does the MQ-2 detect?
LPG, propane, methane, butane, hydrogen, alcohol and smoke. It cannot tell them apart.
How long does it need to warm up?
A few minutes before each use; a new sensor needs 24 to 48 hours of burn-in.
Can it measure ppm?
Only after calibration against a known gas level. Out of the box, use relative values.
Why is the sensor hot?
It has a built-in heater; warm to the touch is normal.
Can I run it from 3.3 V?
No. The heater needs 5 V.
Is it suitable for a home gas alarm?
Use it for learning and demos. For real safety, use a certified gas or smoke alarm.
Parts for this guide
Calculators
Terms in this guide
Projects that use it
Put this into practice: 23 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.

