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

PartQtyRole
ESP32 DEVKIT V11Controller and Wi-Fi
MQ2 Gas Sensor Module1Detects LPG, methane and smoke
Resistors, 12 kΩ, 10 kΩ and 1 kΩ3Sensor divider and transistor base
Active Buzzer1Local alarm
2N2222 NPN Transistor1Drives the buzzer
Relay Module 2 Channel 5VOptional1Exhaust fan control, for bench testing

Wiring

SignalConnect toWhy
MQ-2 VCC5 V (VIN on the dev board)
MQ-2 AO12 kΩ to GPIO35, 10 kΩ from GPIO35 to GNDScales 5 V down to about 2.27 V for ADC1 channel 7.
MQ-2 DONot connectedIt 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.

  1. Ignore readings for the first two minutes after power-up while the heater warms the sensor.
  2. Record a clean-air baseline and store it in NVS; re-record it from a button press or an MQTT command.
  3. Sample once a second and keep a 10-second moving average.
  4. Raise an alarm when the average exceeds the baseline by your chosen ratio: buzzer on, relay on, alarm event published with QoS 1.
  5. 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.