MQ2 Gas Sensor: What It Detects, Warm-Up Time and Limits
The MQ-2 is a heated tin dioxide sensor that reacts to burnable gases and smoke. This guide covers what it detects, how long it needs to warm up, what a 0–100 gas reading means, and why it is a learning tool, never a real alarm.
By the MakerBuddy team Published 20 min read
An MQ-2 gas sensor with its metal mesh cap sits on a small green module board, with heat rising from the cap, a cut-away showing the heater inside the tin dioxide layer, a stopwatch reading 3 min of warm-up and a gas level gauge from 0 to 100 pointing at 22.
The MQ2 gas sensor is a small, low-cost sensor that reacts to burnable gases and smoke. Inside its metal mesh cap, a tiny heater keeps a layer of tin dioxide hot. When a gas such as LPG, propane, hydrogen or methane reaches that hot layer, its electrical resistance drops, and the sensor's output voltage rises. It needs a warm-up before its readings settle: a few minutes each time you power it, and much longer when it is brand new. It gives a rough, relative signal, not an exact amount of one named gas, so it is a learning sensor and never a replacement for a certified smoke, gas or carbon monoxide alarm.
On the MakerBuddy kit the MQ-2 plugs into the socket marked 33, and the dashboard shows it as a gas level from 0 to 100 with no code. Lesson 17, Gas and Air Quality, teaches how to warm it up and record a clean-air baseline.
What the MQ2 gas sensor detects
The maker's datasheet is the place to start. The Hanwei MQ-2 datasheet (opens in a new tab) says the sensor has high sensitivity to LPG, propane and hydrogen, and can also be used for methane and other combustible vapours. Its detection range is listed as 300 to 10,000 ppm of combustible gas, and the sensor type is given as "combustible gas and smoke".
Ppm means parts per million, so 10,000 ppm is 1% of the air. The MQ-2 is built for amounts you would find near a leak, not faint traces.
The MQ-2 cannot tell you which of these gases it found. They all push the reading the same way, so a high reading means only "something burnable is in the air near me".
The MQ-2 and its siblings, such as the MQ-4 and MQ-7, are metal-oxide semiconductor sensors with a tin dioxide layer, per their datasheets. Figaro, a gas sensor maker, explains the idea on its page about how metal-oxide sensors work (opens in a new tab). Here it is in four steps.
1
Heat the oxide. Tin dioxide grains are heated in air. That is why these sensors have a heater.
2
Oxygen grabs electrons. Oxygen from the air sticks to the surface of each grain and captures free electrons from it. This builds a barrier at the edge of each grain, so current struggles to pass from grain to grain. In clean air, the sensor has a high resistance.
3
Gas uses up the oxygen. A burnable gas reacts with the oxygen stuck to the grains. The captured electrons go back into the tin dioxide, the barrier shrinks, and the resistance falls.
4
Clean air resets it. When the gas drifts away, oxygen sticks to the grains again and the resistance climbs back. Figaro notes that the sensor recovers its original resistance once the gas is gone.
The MQ-2 datasheet (opens in a new tab) says the same thing in short: tin dioxide has low conductivity in clean air, and its conductivity rises as the gas concentration rises.
From resistance to a voltage
A microcontroller measures voltage, not resistance. So the sensor sits in series with a load resistor (RL) across a supply, 5 V in the datasheet's test circuit, and the voltage across the load resistor is the output.
When gas lowers the sensor's resistance (Rs), more of the 5 V lands across the load resistor, so the output voltage rises. More gas, higher voltage, higher number on the dashboard. The guide to analog vs digital signals explains why this is an analog signal.
In clean air, oxygen on the hot tin dioxide grains holds electrons and builds tall barriers between grains, so resistance is high and output low; when gas arrives it uses up the oxygen, the electrons return, the barriers drop and the output rises. Below, the 5 V supply feeds Rs, the sensor, in series with RL, the load, and the output voltage across RL goes to an analog pin.
Inside the MQ-2 sensor: parts and specifications
The MQ-2 itself is the round part with the stainless steel mesh cap. According to the datasheet (opens in a new tab), inside it a tiny aluminium oxide ceramic tube carries the tin dioxide layer, the measuring electrodes and the heater. The bare sensor has six pins: four carry the signal and two feed the heater. Most school kits use it on a small module board that adds the load resistor and a plug.
The two makers' figures differ slightly, so check the datasheet for the part you own. Two things matter for students: close to a watt of heat goes into a small part, so the cap gets hot, and the heater wants 5 V, not 3.3 V.
MQ-2 warm-up time: minutes, a day or 48 hours?
Three different warm-up numbers are in circulation, and they describe three different things.
Warm-up
How long
Why
Every time you power it
A few minutes; Lesson 17 says watch for at least 3
The heater must bring the layer up to working temperature before readings settle
Brand-new sensor, first use
About a day, per Lesson 17; Seeed says the best preheat is above 24 hours
A new sensor's layer drifts until it has been heated for a long time
The maker's test conditions
Over 48 hours
The preheat behind the datasheet's published sensitivity figures
Warm-up
Every time you power it
How long
A few minutes; Lesson 17 says watch for at least 3
Why
The heater must bring the layer up to working temperature before readings settle
Warm-up
Brand-new sensor, first use
How long
About a day, per Lesson 17; Seeed says the best preheat is above 24 hours
Why
A new sensor's layer drifts until it has been heated for a long time
Warm-up
The maker's test conditions
How long
Over 48 hours
Why
The preheat behind the datasheet's published sensitivity figures
The datasheet adds that a sensor stored for a long time without power drifts and needs a long ageing time before it is stable again, so a kit back from the holidays reads differently on its first morning.
In class, plug the sensor in before you explain anything, so it has its few minutes by the time the theory ends. If the sensor is new, leave the board powered for a day first.
How to know warm-up is done
Lesson 17 gives a clear test: when the reading changes by less than 5 points over 30 seconds, record it as your clean-air baseline. Here is what a student's notebook might look like. These are example numbers; yours will differ.
Time since power-on
Gas level
Change from the last reading
3:00
22
—
3:10
21
1
3:20
23
2
3:30
22
1
Time since power-on
3:00
Gas level
22
Change from the last reading
—
Time since power-on
3:10
Gas level
21
Change from the last reading
1
Time since power-on
3:20
Gas level
23
Change from the last reading
2
Time since power-on
3:30
Gas level
22
Change from the last reading
1
Across 30 seconds the reading stayed between 21 and 23, a spread of 2 points. That is under 5, so the baseline is 22.
A gas level chart for the first five minutes after power-on: the reading swings widely while the heater warms up, then settles from minute 3, where a 30-second check shows it moving less than 5 points, giving a baseline B = 22. Dashed alert levels sit at B + 10 = 32, B + 20 = 42 and B + 30 = 52, all below 100. These are example numbers; yours will differ.
What the kit's 0–100 gas reading means
The MakerBuddy firmware reads the MQ-2 on GPIO 33. Espressif's GPIO reference (opens in a new tab) lists that pin as ADC1 channel 5, and it warns that ADC2 pins cannot be used when Wi-Fi is used. All four analog sensor pins on the board are on ADC1, so the gas reading keeps working while the dashboard is connected.
The ESP32 turns the voltage into a whole number. Arduino-ESP32's ADC reference (opens in a new tab) says analogRead is 12 bits by default, a range of 0 to 4095. The firmware reads the pin four times, averages the four, and then scales the result to 0–100:
text
gas level = raw × 100 ÷ 4095 (whole numbers only, fractions dropped)
Worked example: from raw number to gas level to alert levels
1
A raw average of 900 gives 900 × 100 ÷ 4095 = 21.98. The firmware drops the fraction, so the card shows 21.
2
A raw average of 901 gives 22.002, which shows as 22. One point on the card is about 41 raw steps, because 4095 ÷ 100 = 40.95.
3
A raw average of 4095, the top of the scale, shows as 100. Once the card reads 100 it cannot tell you how much more gas there is. Lesson 17 says to move the vapour source further away if that happens.
Now use the baseline. With B = 22 from the warm-up log, Lesson 17's plan sets three levels that stay below 100:
Level
Formula
Value
What it does in the lesson plan
1
B + 10
32
Colour light yellow
2
B + 20
42
Colour light red and a beeping buzzer
3
B + 30
52
Relay on (in a real building this would start an exhaust fan)
Level
1
Formula
B + 10
Value
32
What it does in the lesson plan
Colour light yellow
Level
2
Formula
B + 20
Value
42
What it does in the lesson plan
Colour light red and a beeping buzzer
Level
3
Formula
B + 30
Value
52
What it does in the lesson plan
Relay on (in a real building this would start an exhaust fan)
After the teacher's vapour demo, measure the change. Say the peak was 68, another example number. The rise is 68 − 22 = 46 points. Lesson 17 also asks for the percentage change when the baseline is 10 or more: 46 ÷ 22 × 100 = 209%. So the reading roughly tripled.
What the number is not
The level is not ppm, and it is not a percentage of gas in the air. It is a position on a scale from 0 to the top of the ESP32's input. Lesson 17 puts it plainly: real alarms are calibrated in ppm for one gas, while the MakerBuddy reading is relative, which is fine for learning and not for protecting people.
The same number appears everywhere on the board. The text screen can show it with the {gas} wildcard as a whole number, and servo mapping can link it to the servo angle, so 0–100 turns a needle across 0–180° like a gauge. Both are described on the technical details page, under the LCD screen and servo control.
For coders: read the MQ-2 sensor with Arduino on an ESP32
This sketch prints the same raw average and 0–100 level the firmware works out, and it ignores the first three minutes while the heater warms up.
cpp
// MQ-2 on GPIO 33: print raw and 0-100 level once a second.
const int GAS_PIN = 33; // ADC1 channel 5, so it works with Wi-Fi on
const unsigned long WARM_UP_MS = 180000; // 3 minutes, as Lesson 17 suggests
int readAverage(int pin) {
long sum = 0;
for (int i = 0; i < 4; i++) {
sum += analogRead(pin); // 12-bit: 0 to 4095
}
return sum / 4; // average four reads to calm the noise
}
void setup() {
Serial.begin(115200);
}
void loop() {
int raw = readAverage(GAS_PIN);
long level = map(raw, 0, 4095, 0, 100); // same scaling as the dashboard
if (millis() < WARM_UP_MS) {
Serial.print("warming up ");
}
Serial.print("raw ");
Serial.print(raw);
Serial.print(" gas level ");
Serial.println(level);
delay(1000);
}
Uploading your own sketch replaces the MakerBuddy firmware until you put the firmware back, so the dashboard and rules stop working in the meantime. The guide to programming an ESP32 with the Arduino IDE covers the upload, and the guide to the ESP32 ADC and reading analog sensors accurately explains the input range in depth. Arduino-ESP32's ADC page (opens in a new tab) lists the 11 dB attenuation setting as measuring about 150 mV to 3100 mV on the ESP32.
Vc is the circuit voltage, VRL the voltage across the load resistor, and RL the load resistor. Take a bare sensor on Vc = 5 V with an RL of 10 kΩ, chosen for this example. If VRL is 1.0 V in clean air, Rs = (5 ÷ 1 − 1) × 10 = 40 kΩ. Seeed's wiki (opens in a new tab) then divides the clean-air resistance by 9.8, a ratio it read off the datasheet graph, to get R0 = 40 ÷ 9.8 = 4.08 kΩ. If gas later pushes VRL to 2.5 V, Rs = (5 ÷ 2.5 − 1) × 10 = 10 kΩ, and Rs ÷ R0 = 2.45. You would then look up 2.45 on the datasheet's curve for your chosen gas.
Every step adds error: the 9.8 was read from a printed graph, the curve assumes you know which gas you have, and Seeed says its equations are not calibrated. That is why the MakerBuddy dashboard shows a relative level instead.
Worked example: a two-rule gas alert with a threshold window
The MakerBuddy rules run on the board itself, so this works with the browser closed. A rule watches one or two sensors and runs up to 10 steps, and the dashboard and rules read sensors once a second. The guide to if-then statements with real sensors explains the logic. This build follows Lesson 28, Smart Safety Systems, using the baseline of 22 from earlier.
Goal: sound the buzzer and show red when the gas level rises well above the baseline, and only switch back to green when the air is properly clear.
1
Find the baseline. Unplug the USB cable, plug the MQ-2 into the socket marked 33, power up and wait about 3 minutes. The baseline here is 22.
2
Choose two values with a gap. Danger at 50 or more. Clear below 35. The gap from 35 to 49 is the threshold window.
3
Rule 1, "GasDanger". Mode: Condition. Sensor: Gas Level (MQ2). Operator: Greater or equal (>=). Threshold: 50.
Rule 2, "GasClear". Mode: Condition. Sensor: Gas Level (MQ2). Operator: Less than (<). Threshold: 35.
6
Step 1: Buzzer Off, delay 100 ms. Step 2: RGB Green, delay 100 ms. Save, and enable both rules.
A Condition rule starts once its match has held for 0.3 seconds and repeats while the match lasts, according to the automation rules in the documentation. When the level is between 35 and 49, neither rule runs. The alarm that started at 50 keeps sounding until the level drops below 35. Without the gap, a reading hovering around one value would flip the alarm every second. Lesson 27 on range logic and threshold windows teaches this idea, and the guide to picking sensor thresholds covers the method.
Lesson 28's challenge extends it to three stages, green, yellow and red, with the yellow rule testing the same sensor twice joined with AND. A rule that stops leaves its last step in place, so each quieter stage must switch the buzzer off itself.
A 0 to 100 gas level line with the baseline at 22: below 35 the GasClear rule runs Buzzer Off and RGB Green, at 50 or more the GasDanger rule runs Buzzer On and RGB Red, and between 35 and 49 is the threshold window, where neither rule runs and the last state holds. A match must hold for 0.3 s, and sensors are read once a second.
The full project, with the honest list of what such a build can and cannot do, is in the gas leakage detector project guide. If you add Lesson 17's Level 3 relay step, keep it to a small low-voltage fan. The relay is for low-voltage things only, never mains electricity; the guide to how a relay works explains why.
MQ-2 vs other gas sensors and real alarms
The MQ family has a sensor for each job, and none of them is a home alarm. This table puts the MQ-2 next to two of its siblings and the two alarms every home should have.
Device
Main target
Range or method
How it is heated or works
Certified home alarm?
MQ-2
LPG, propane, hydrogen; also methane, other burnable vapours and smoke
300–10,000 ppm combustible gas
Heater held at 5 V all the time
No
MQ-4
Methane (natural gas); also propane and butane
300–10,000 ppm natural gas or methane
Heater held at 5 V all the time
No
MQ-7
Carbon monoxide
10–10,000 ppm CO
Heater cycles: 5 V for 60 s to clean, 1.5 V for 90 s to measure CO
No
Home smoke alarm
Smoke from fires
Ionisation or photoelectric
Sealed, tested unit
Yes
Home CO alarm
Carbon monoxide
A sensor made for CO
Battery or battery backup
Yes
Device
MQ-2
Main target
LPG, propane, hydrogen; also methane, other burnable vapours and smoke
Range or method
300–10,000 ppm combustible gas
How it is heated or works
Heater held at 5 V all the time
Certified home alarm?
No
Device
MQ-4
Main target
Methane (natural gas); also propane and butane
Range or method
300–10,000 ppm natural gas or methane
How it is heated or works
Heater held at 5 V all the time
Certified home alarm?
No
Device
MQ-7
Main target
Carbon monoxide
Range or method
10–10,000 ppm CO
How it is heated or works
Heater cycles: 5 V for 60 s to clean, 1.5 V for 90 s to measure CO
The MQ-7 row shows why an MQ-2 is a poor CO detector: CO needs a different heating pattern, so Hanwei built a separate sensor for it. The air-quality side of the family, the MQ-135, gets its own guide: MQ-2 vs MQ-135. And if you are wondering about fire, the flame sensor guide explains why a sensor that sees flames is not a smoke alarm either.
Limits: why an MQ-2 is never a real smoke or gas alarm
It cannot name the gas. A spray of deodorant and a gas leak can look alike.
It drifts with the weather. The temperature and humidity graph in the MQ-2 datasheet (opens in a new tab) shows the sensor's resistance ratio shifting between −20 and 50 °C, with separate curves for 30%, 60% and 85% relative humidity. The same gas gives a different number on a humid afternoon.
It can be poisoned. The datasheet (opens in a new tab) warns that silicone vapour, from sealants, putty or silicone rubber, can make the sensor stop working. Corrosive gases, salt spray, water and freezing also damage it, and long exposure to high gas levels changes it, powered or not.
The kit's reading is relative. A level set against your own baseline is good for comparing, not for deciding whether air is safe.
Real alarms deal with all of this through design and testing. The US Fire Administration's smoke alarm page (opens in a new tab) says to test alarms monthly and to get new ones every 10 years. The US Consumer Product Safety Commission's CO page (opens in a new tab) calls carbon monoxide a colourless, odourless, poisonous gas, says more than 200 people in the United States die every year from accidental non-fire CO poisoning, and advises CO alarms on every level of the home and outside sleeping areas. A student build cannot promise any of that.
Common MQ-2 sensor mistakes and how to fix them
Symptom
Cause
Fix
The reading swings wildly for the first minutes
The heater has not reached working temperature
Wait at least 3 minutes; for a new or long-stored sensor, power it for a day first
Alerts fire as soon as the board starts
The thresholds were set from a cold reading, or the rules were enabled before warm-up
Record the baseline after warm-up and set thresholds well above it
The alarm flickers on and off
The on and off rules use the same value, or the danger level sits too close to the baseline
Leave a gap between the clear and danger values, as in the two-rule example
The card is stuck at 100
The vapour source is too close, so the reading has hit the top of the scale
Move the source further away; compare peaks at 5, 10, 15 and 20 cm as in Lesson 17
A reading shows with the sensor unplugged
The analog pin floats, and the board cannot detect a missing analog sensor
Check the plug before trusting a strange number
Yesterday's baseline no longer matches today
Temperature and humidity changed, or the sensor was unpowered for a long time
Take a fresh baseline at the start of every session
The sensor responds less than it used to
Silicone vapour, water or corrosive gas has damaged the layer
Keep the sensor away from sealants and liquids; replace a damaged sensor
Readings fail on your own ESP32 project once Wi-Fi starts
The sensor is on an ADC2 pin
Move it to an ADC1 pin such as GPIO 32 to 39
Symptom
The reading swings wildly for the first minutes
Cause
The heater has not reached working temperature
Fix
Wait at least 3 minutes; for a new or long-stored sensor, power it for a day first
Symptom
Alerts fire as soon as the board starts
Cause
The thresholds were set from a cold reading, or the rules were enabled before warm-up
Fix
Record the baseline after warm-up and set thresholds well above it
Symptom
The alarm flickers on and off
Cause
The on and off rules use the same value, or the danger level sits too close to the baseline
Fix
Leave a gap between the clear and danger values, as in the two-rule example
Symptom
The card is stuck at 100
Cause
The vapour source is too close, so the reading has hit the top of the scale
Fix
Move the source further away; compare peaks at 5, 10, 15 and 20 cm as in Lesson 17
Symptom
A reading shows with the sensor unplugged
Cause
The analog pin floats, and the board cannot detect a missing analog sensor
Fix
Check the plug before trusting a strange number
Symptom
Yesterday's baseline no longer matches today
Cause
Temperature and humidity changed, or the sensor was unpowered for a long time
Fix
Take a fresh baseline at the start of every session
Symptom
The sensor responds less than it used to
Cause
Silicone vapour, water or corrosive gas has damaged the layer
Fix
Keep the sensor away from sealants and liquids; replace a damaged sensor
Symptom
Readings fail on your own ESP32 project once Wi-Fi starts
The safe test is the one in Lesson 17, and only a teacher does it. In a ventilated room, the teacher puts a few drops of hand sanitiser on a tissue and holds it 10 to 15 cm from the sensor. Liquid must never touch the sensor. Sanitiser burns easily, so it stays away from heaters and flames, and the tissue goes into a closed bin straight afterwards. Lesson 17 says to expect a sharp jump, then a slow return to the baseline over about 30 to 60 seconds.
Never use lighters, matches, candles, incense or released cooking gas. Keep fingers off the metal cap: on the kit, the heater is on whenever the board has power, as the technical details page warns.
Compare the gas number in different rooms or at different times, then discuss what a low-cost sensor can and cannot tell you
Gas sensor
17
Gas Traffic Light
Three rules turn the colour light green, yellow or red as the gas number rises
Gas sensor, colour light
5, 17, 27, 28
Kitchen Gas Alert (practice model)
One rule gives a slow beep when the number rises, a second gives a fast beep and a red light when it rises more
Gas sensor, buzzer, colour light
5, 8, 17, 27, 28
Idea
Air Quality Lab
What students do
Compare the gas number in different rooms or at different times, then discuss what a low-cost sensor can and cannot tell you
Parts used
Gas sensor
Lessons
17
Idea
Gas Traffic Light
What students do
Three rules turn the colour light green, yellow or red as the gas number rises
Parts used
Gas sensor, colour light
Lessons
5, 17, 27, 28
Idea
Kitchen Gas Alert (practice model)
What students do
One rule gives a slow beep when the number rises, a second gives a fast beep and a red light when it rises more
Parts used
Gas sensor, buzzer, colour light
Lessons
5, 8, 17, 27, 28
The library marks each one as a learning model, not a real alarm. A good class question: which room in the school has the highest baseline, and why? Schools in Pakistan can order kits for a class from the MakerBuddy buy-now page, with other countries getting a written quote.
FAQ
What does the MQ2 gas sensor detect?
Burnable gases and smoke. Its datasheet (opens in a new tab) lists high sensitivity to LPG, propane and hydrogen, plus methane and other combustible vapours, and it also reacts to alcohol vapour. It cannot tell you which gas it found.
How do MQ sensors work?
An MQ sensor such as the MQ-2 heats a layer of tin dioxide. In clean air, oxygen on the layer's surface traps electrons, so its resistance is high. A burnable gas reacts with that oxygen, frees the electrons and lowers the resistance, which a simple resistor circuit turns into a rising voltage, as Figaro's page on metal-oxide sensors (opens in a new tab) explains.
How long does an MQ-2 sensor take to warm up?
Give it at least 3 minutes every time you power it, until the reading moves less than 5 points over 30 seconds. A brand-new sensor needs about a day of power before its readings stop drifting. The maker's published figures assume a preheat of over 48 hours.
What is the normal range of an MQ-2 gas sensor?
The datasheet range is 300 to 10,000 ppm of combustible gas. On the MakerBuddy dashboard the reading is a relative level from 0 to 100, and "normal" is whatever your room reads in clean air after warm-up. Measure your own baseline rather than copying someone else's.
Can the MQ-2 detect carbon monoxide?
Not reliably. Carbon monoxide is a different job, and Hanwei makes a separate sensor for it, the MQ-7, which cycles its heater between 5 V and 1.5 V to measure CO. For people's safety, only a certified CO alarm will do.
Is the MQ-2 a smoke sensor?
It does react to smoke, and its datasheet lists smoke as a target. But it is not a smoke alarm. Home smoke alarms are ionisation or photoelectric devices built and tested for that job, and the US Fire Administration advises testing them monthly and replacing them every 10 years.
Does the MQ-2 work with an ESP32?
Yes. Put its analog output on an ADC1 pin, such as GPIO 33, because ADC2 pins cannot be used while Wi-Fi is on. The heater needs 5 V, and at the 11 dB setting the ESP32's analog input measures up to about 3.1 V, per Arduino-ESP32's ADC reference (opens in a new tab), so a module's output may need to be brought down before it reaches the pin. On the MakerBuddy kit, the sensor just plugs into the socket marked 33.
Why does my MQ-2 read high in clean air?
Usually it has not warmed up, or it was unpowered for a long time and needs ageing. Humidity, temperature and vapours such as perfume or cleaning sprays also push it up. Wait, air the room, and take a fresh baseline.
A soil moisture sensor turns the water around its probe into a number. This guide explains how capacitive and resistive probes work, how to turn the raw number into a percentage, how to calibrate dry and wet, and how to use the reading in a plant rule.
The DS18B20 is a digital temperature sensor that sends exact readings over one data wire, and its waterproof probe version can sit in water or soil. This guide covers its specs, pinout, how the one-wire bus works, a no-code water rule and ESP32 code.
The DHT11 measures air temperature and relative humidity and sends both over one data wire. This guide covers its pinout, what its ±2 °C and ±5% accuracy really mean, how it senses humidity, and how to use it on the MakerBuddy board with no code or with Arduino code.
· 19 min read
Learn with MakerBuddy
Start building today.
Every part in these guides has its own lesson. Read them free, or get a kit for your class.