RD-02
Gas watch
An MQ-2 gas sensor read by an ESP32 that logs readings, sounds a local alarm and switches an exhaust fan relay when the level rises above a clean-air baseline.
Draft. Wiring and firmware outline written. Bench validation pending.
Where it fits
- Generator and battery rooms
- Workshops
- Monitoring alongside a certified kitchen alarm
Power: A 5 V USB adapter. The sensor's heater draws around 150 mA all the time, so this is not a battery design.
Parts list
| Part | Qty | Role |
|---|---|---|
| ESP32 DEVKIT V1 | 1 | Controller and Wi-Fi |
| MQ2 Gas Sensor Module | 1 | Detects LPG, methane and smoke |
| Resistors, 12 kΩ, 10 kΩ and 1 kΩ | 3 | Sensor divider and transistor base |
| Active Buzzer | 1 | Local alarm |
| 2N2222 NPN Transistor | 1 | Drives the buzzer |
| Relay Module 2 Channel 5VOptional | 1 | Exhaust fan control, for bench testing |
Wiring
| Signal | Connect to | Why |
|---|---|---|
| MQ-2 VCC | 5 V (VIN on the dev board) | |
| MQ-2 AO | 12 kΩ to GPIO35, 10 kΩ from GPIO35 to GND | Scales 5 V down to about 2.27 V for ADC1 channel 7. |
| MQ-2 DO | Not connected | It swings to 5 V, which the ESP32 pins cannot take. |
| Buzzer + | 5 V (VIN) | |
| Buzzer − | 2N2222 collector; emitter to GND, base to GPIO26 through 1 kΩ | |
| Relay IN1 (optional) | GPIO27 |
Firmware outline
Written for ESP-IDF. The same steps work in Arduino with the matching calls.
- Ignore readings for the first two minutes after power-up while the heater warms the sensor.
- Record a clean-air baseline and store it in NVS; re-record it from a button press or an MQTT command.
- Sample once a second and keep a 10-second moving average.
- Raise an alarm when the average exceeds the baseline by your chosen ratio: buzzer on, relay on, alarm event published with QoS 1.
- Publish the averaged reading every 30 seconds for logging.
Design notes
- Why a divider on AO
- Running at 5 V, the module's analog output can reach 5 V. The ESP32's recommended range at 12 dB attenuation ends at 2.45 V, so 12 kΩ over 10 kΩ brings 5 V down to about 2.27 V.
- Why a baseline, not ppm
- An MQ-2 is not calibrated out of the box, and its resistance drifts with temperature, humidity and age. Comparing against a stored clean-air baseline is honest about what it can tell you.
- Warm-up and burn-in
- Every power-up needs a warm-up before readings settle, and a new sensor needs a long burn-in before you record a baseline. The manufacturer's datasheet asks for more than 24 hours.
Limits
- It is not a certified gas detector. Where LPG is used, install a certified alarm and treat this as monitoring.
- Switching a mains fan needs a relay rated for the load, a proper enclosure and an electrician.
