Lessons and the learning game

MQ gas sensors, honestly

What cheap MQ gas sensors can and cannot tell you: heater warm-up, Rs/R0, calibration, cross sensitivity, alarms, and why a listed alarm still matters.

Take the course at /learn/path/gas-sensors-honestly. It is an intermediate course on the Uno.

An MQ build is never a substitute for a listed detector. A CO alarm listed to UL 2034, or a gas detector listed to UL 2075, is built around a sensor chosen for its gas, tested by an independent lab against a standard, and made to keep working for years. Every build in this course is a way to learn. Keep listed alarms where the code and the maker say, and test them. Everything here runs on 5 V.

The bench

An Uno with an MQ-2 board on A0 (DO on pin 2). Later lessons add an MQ-7 on A1 and an MQ-135 on A2, an active buzzer on pin 8, a TEST button on pin 5 and a green lamp on pin 9 that stands in for an exhaust fan. From the calibration lesson on, the sensors use 10 k load resistors, which lift clean air from about 11 ADC counts to about 40, and the bench starts them warm so the lessons do not wait.

The lessons

The heater and burn-in. A cold MQ-2 reads 2.44 V in clean air and lights its DO lamp, then settles as the heater warms. An alarm needs a warm-up lockout, and a new sensor needs 24 to 48 hours of burn-in.

Rs/R0 ratios. AO to Rs to Rs/R0 to ppm, from the datasheet's log-log chart. 1000 ppm of LPG reads about 995 ppm.

Calibration in clean air. A sensor with R0 = 25 k measures 25.1 k. The datasheet's typical 10 k would read 1000 ppm as 141.

Cross sensitivity. Alcohol reads as LPG on the MQ-2, hydrogen reads as more CO than CO does on the MQ-7, and hand sanitizer reads as CO2 on the MQ-135. A real CO2 meter uses NDIR.

Alarms with hysteresis. A reading that hovers near 150 ppm flips a single threshold again and again; an ON at 150, OFF below 100 pair holds.

What a listed detector does. Exposure over time instead of one reading (the UL 2034 windows, sped up a minute per second), the temporal four pattern, a test button, and a fault report when the sensor reads 0 V.

Boss: a garage fume alarm. Warm-up lockout, R0 at boot, a fan on CO, a CO dose alarm, a fuel vapor alarm and a test button, with its limits written down.

The sketches

Sketch What it does
gsxwarm Watches a cold MQ-2 warm up, with an alarm lockout
gsxratio AO, Rs, Rs/R0 and an LPG estimate
gsxcal Measures R0 in clean air and compares it with a guess
gsxcross Three sensors, each read on one gas's line
gsxalarm A single threshold and a hysteresis pair side by side
gsxlisted Dose over time, the T4 pattern, TEST and a fault (not a CO alarm)
gsxgarage The garage fume alarm (a hobby build)

What the simulation leaves out

The MQ parts follow the datasheet charts with one gas in the air at a time. Temperature, humidity, aging and drift are not modeled, and neither is the MQ-7's heater cycle (60 s at 5 V, 90 s at 1.4 V): the blue boards hold the heater at 5 V, and the model reads the CO line all the time. The warm-up is seconds instead of minutes, and burn-in is not modeled at all. The DO comparator has no hysteresis. The dose rule in the last two lessons is a toy, not the physiology a listed alarm is tested against.

The MQ sensors, the MQ-2, the buzzer and the environmental sensors course.