Component guide · Intermediate · 3 min read
MQ Gas Sensors
MQ-2, MQ-135, MQ-7 and How to Use Them
By Geekobot Learning Team · Updated 24 Oct 2026
On this page
MQ sensors are cheap metal-oxide gas sensors: a heated tin-dioxide surface changes resistance when gas is present. The MQ-2 senses smoke, LPG and methane, the MQ-135 senses air quality (ammonia, benzene, CO2-like pollution) and the MQ-7 carbon monoxide. They need 5 V at about 150 mA for the heater, a 24 to 48 hour burn-in, and calibration before any ppm value means anything.
Key specs at a glance
- Heater
- 5 V, about 150 mA (0.75 W); the module gets warm
- Output
- Analog (gas level) and digital (threshold via trimmer)
- Warm-up
- 20 seconds to a few minutes; burn-in 24 to 48 hours for stable readings
- Sensitivity
- Changes with temperature and humidity
- Response
- Seconds; recovery can take minutes
- Not for
- Safety-critical alarms; use a certified detector
Which MQ sensor do you need?
| Sensor | Detects | Typical use |
|---|---|---|
| MQ-2 | Smoke, LPG, propane, methane, hydrogen | Kitchen smoke or gas-leak demo |
| MQ-3 | Alcohol vapour | Breathalyser projects |
| MQ-4 | Methane, natural gas (CNG) | Gas leak demo |
| MQ-5 | LPG, natural gas | Gas leak demo |
| MQ-6 | LPG, butane | LPG cylinder leak demo |
| MQ-7 | Carbon monoxide | CO monitoring experiments |
| MQ-8 | Hydrogen | Lab projects |
| MQ-9 | CO and flammable gas | Combined demo |
| MQ-135 | Ammonia, benzene, smoke, air quality | Indoor air-quality indicator |
- MQ-2
- Detects:
- Smoke, LPG, propane, methane, hydrogen
- Typical use:
- Kitchen smoke or gas-leak demo
- MQ-3
- Detects:
- Alcohol vapour
- Typical use:
- Breathalyser projects
- MQ-4
- Detects:
- Methane, natural gas (CNG)
- Typical use:
- Gas leak demo
- MQ-5
- Detects:
- LPG, natural gas
- Typical use:
- Gas leak demo
- MQ-6
- Detects:
- LPG, butane
- Typical use:
- LPG cylinder leak demo
- MQ-7
- Detects:
- Carbon monoxide
- Typical use:
- CO monitoring experiments
- MQ-8
- Detects:
- Hydrogen
- Typical use:
- Lab projects
- MQ-9
- Detects:
- CO and flammable gas
- Typical use:
- Combined demo
- MQ-135
- Detects:
- Ammonia, benzene, smoke, air quality
- Typical use:
- Indoor air-quality indicator
How an MQ sensor works
Inside the mesh cap is a tiny ceramic tube with a tin-dioxide coating and a heater coil. When heated to a few hundred degrees, the coating's resistance drops in the presence of reducing gases. The module turns that resistance into a voltage with a load resistor, and an LM393 comparator gives a digital alarm output when the voltage passes the trimmer's threshold.
Wiring to Arduino and ESP32
Four pins: VCC (5 V), GND, A0 (analog), D0 (digital). The heater must have 5 V. On an ESP32 or Pico the analog output can reach 5 V, so add a voltage divider (for example 10 kΩ and 20 kΩ) before the ADC pin.
const int A_PIN = A0;
const int D_PIN = 7;
const int LIMIT = 400; // raw value, set from your own tests
void setup() {
Serial.begin(9600);
pinMode(D_PIN, INPUT);
delay(20000); // let the heater warm up
}
void loop() {
int v = analogRead(A_PIN);
Serial.print("Gas level: "); Serial.println(v);
if (v > LIMIT || digitalRead(D_PIN) == LOW) Serial.println("ALARM");
delay(1000);
}Getting a ppm estimate
The datasheet graphs relate the ratio Rs/Ro to gas concentration on a log-log scale, where Ro is the sensor resistance in clean air. To estimate ppm:
- 1Burn the sensor in for 24 to 48 hours.
- 2In clean air, measure the analog value, convert to Rs using the load resistor (10 kΩ on most modules), and record Ro = Rs / 9.8 for the MQ-2 (the clean-air ratio from its datasheet; other sensors use other ratios).
- 3Use the curve for your gas to convert Rs/Ro into ppm. Libraries such as MQUnifiedsensor do this for you.
Expect ±30% at best. Temperature and humidity shift the readings, so a reading is an indicator, not a measurement.
Better sensors for real measurements
| Need | Use instead |
|---|---|
| Real CO2 ppm | SCD40 / SCD41 or MH-Z19 (NDIR) |
| Indoor air quality index | ENS160, SGP40, BME688 |
| Particulates (PM2.5) | PMS5003, SPS30 |
| Life-safety CO or gas alarm | A certified standalone detector |
- Real CO2 ppm
- SCD40 / SCD41 or MH-Z19 (NDIR)
- Indoor air quality index
- ENS160, SGP40, BME688
- Particulates (PM2.5)
- PMS5003, SPS30
- Life-safety CO or gas alarm
- A certified standalone detector
Try it: ADC resolution calculator
Change the values and the diagram and results update as you type.
Common mistakes to avoid
- Reading the sensor as soon as it is powered, before the heater stabilises.
- Powering the heater from 3.3 V, which gives weak and wrong readings.
- Feeding the 5 V analog output straight into an ESP32 pin.
- Treating the raw ADC value as ppm.
- Using an MQ sensor as the only protection against a gas leak.
Frequently asked questions
What does the MQ-2 sensor detect?
Smoke and flammable gases: LPG, propane, methane, hydrogen and alcohol vapour. It responds to all of them, so it cannot tell you which one.
What is the difference between MQ-2 and MQ-135?
MQ-2 targets flammable gases and smoke; MQ-135 targets air-quality pollutants such as ammonia, benzene and smoke, which makes it the usual choice for a rough indoor air-quality indicator.
How long does an MQ sensor take to warm up?
Readings settle after a few minutes, but a new sensor needs 24 to 48 hours of powered burn-in before values are repeatable.
Can an MQ sensor measure CO2?
Not reliably. The MQ-135 reacts to pollutants that often come with CO2 but does not measure CO2 itself. Use an NDIR sensor such as the SCD40 or MH-Z19.
Can I use MQ sensors with an ESP32?
Yes: power the heater from 5 V, and divide the analog output down to 3.3 V before the ADC pin.
Parts for this guide
Calculators
Terms in this guide
Projects that use it
Put this into practice: 48 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.
