Overview
The MQ-2 is a metal-oxide gas sensor that responds to flammable and combustible gases — LPG, propane, methane, hydrogen, alcohol, and smoke. It's the workhorse sensor for DIY smoke detectors, leak alarms for gas appliances, robot kitchen monitors, and any safety-oriented hobby project that needs to know "is something burning or leaking nearby?".
The breakout board includes the MQ-2 sensing element, a sensitivity-adjustment trim pot, an LM393 comparator, a power LED, and a digital-output indicator LED. The analog output (AO) gives you a continuous gas concentration reading; the digital output (DO) goes LOW when the level crosses the threshold set by the on-board pot. Wire it to any microcontroller with an analog input.
Like all MQ-series sensors, the MQ-2 has an internal heater that needs to warm up before readings stabilize: about 24-48 hours on first use, then 1-3 minutes any time you re-power.
At a Glance
Specifications
| Parameter | Value |
| Sensing Element | MQ-2 (SnO2 metal-oxide semiconductor) |
| Operating Voltage | 5V DC |
| Heater Voltage | 5V +/- 0.1V |
| Heater Power | ~800 mW |
| Heater Current | ~150 mA |
| Detected Gases | LPG, propane, butane, methane, H2, alcohol, smoke |
| Detection Range | 300 - 10000 ppm (gas-dependent) |
| Analog Output (AO) | 0 - VCC, increases with gas concentration |
| Digital Output (DO) | HIGH normally, LOW above pot threshold |
| Comparator | LM393, threshold via on-board pot |
| Initial Warm-up | 24-48 hours (first use) |
| Re-warm-up | 1-3 minutes |
| Operating Temperature | -20 degC to +50 degC |
| Dimensions | ~32 x 22 mm |
Pinout Diagram
Wiring Guide
Arduino Wiring
The MQ-2 needs a stable 5V supply because the heater pulls roughly 150 mA. A USB-powered Arduino works for one MQ sensor; for multiple sensors use an external 5V supply.
| MQ-2 Pin | Arduino Pin |
|---|---|
| VCC | 5V |
| GND | GND |
| AO | A0 (analog input) |
| DO | D2 (digital input, optional) |
ESP32 Wiring
Power the heater from VIN (5V). The analog output can swing close to 5V at high concentrations, so use a 2:1 voltage divider before the ADC pin to stay in the 0-3.3V safe range.
| MQ-2 Pin | ESP32 Pin | Details |
|---|---|---|
| VCC | VIN (5V) | Heater needs full 5V |
| GND | GND | |
| AO | GPIO 34 | Through 2:1 divider |
| DO | GPIO 35 | 3.3V logic; safe direct |
Raspberry Pi Wiring
The Pi has no analog input. Read AO through an external ADC like the ADS1115 over I2C; DO can connect to a regular GPIO directly.
| Connection | Pi / ADC |
|---|---|
| MQ-2 VCC | Pin 2 (5V) |
| MQ-2 GND | Pin 6 (GND) |
| MQ-2 AO | ADS1115 A0 |
| MQ-2 DO | Pin 11 (GPIO 17) |
| ADS1115 SDA | Pin 3 (GPIO 2) |
| ADS1115 SCL | Pin 5 (GPIO 3) |
Raspberry Pi Pico Wiring
The Pico's 12-bit ADC reads up to 3.3V. Power the heater from VBUS (5V) and use a 2:1 divider on AO before the GPIO ADC pin.
| MQ-2 Pin | Pico Pin | Details |
|---|---|---|
| VCC | VBUS (5V from USB) | |
| GND | GND | |
| AO | GP26 (ADC0) | Through 2:1 divider |
| DO | GP15 |
Code Examples
Arduino - Smoke / Gas Alarm
// MQ-2 - Print analog reading and trigger a buzzer if smoke/gas detected
const int aoPin = A0;
const int doPin = 2;
const int buzzer = 8;
const int ALARM_THRESHOLD = 400; // tune to your environment
void setup() {
Serial.begin(9600);
pinMode(doPin, INPUT);
pinMode(buzzer, OUTPUT);
Serial.println("MQ-2 warming up - wait 1-3 minutes for stable values");
}
void loop() {
int raw = analogRead(aoPin);
bool digitalAlarm = (digitalRead(doPin) == LOW);
Serial.print("Raw="); Serial.print(raw);
if (raw > ALARM_THRESHOLD || digitalAlarm) {
Serial.print(" [ALARM]");
tone(buzzer, 1000, 200);
}
Serial.println();
delay(500);
}
ESP32 - Read Concentration in Volts
// MQ-2 on ESP32 - read AO through a 2:1 divider
const int aoPin = 34;
const float VREF = 3.3;
const float DIVIDER = 0.5;
void setup() {
Serial.begin(115200);
analogReadResolution(12);
}
void loop() {
int raw = analogRead(aoPin);
float vAtPin = raw * VREF / 4095.0;
float vReal = vAtPin / DIVIDER;
Serial.printf("Raw=%4d Vpin=%.3f Vreal=%.3f V\n", raw, vAtPin, vReal);
delay(500);
}
Raspberry Pi Pico - MicroPython
# MQ-2 on Raspberry Pi Pico (MicroPython)
# AO -> 2:1 divider -> GP26 (ADC0); DO -> GP15
from machine import ADC, Pin
import time
ao = ADC(26)
do = Pin(15, Pin.IN)
print("Warming up MQ-2 - wait 1-3 minutes for stable values")
while True:
raw = ao.read_u16()
v_pin = raw * 3.3 / 65535
v_real = v_pin * 2
alarm = " ALARM" if do.value() == 0 else ""
print("Raw={:5d} Vreal={:.2f} V{}".format(raw, v_real, alarm))
time.sleep(0.5)