Preview build — page text is a draft awaiting human review. Code badges come from real compiles. The flasher is real but not yet hardware-tested; the Playground is still a preview.

MQ-2 gas sensor with ESP32-C3 SuperMini — divider wiring

Read an MQ-2 smoke/LPG sensor on an ESP32-C3 SuperMini: 5 V heater, AO on GPIO3 through a 10 kΩ / 10 kΩ divider to fit the C3’s 2.5 V ADC range.

Arduino C++Verified — core esp32 3.3.12, 3 Nov 2026Compile-only

Community draft — report a mistake

The MQ-2 senses LPG, smoke and other flammable gases — the sensor behind most DIY kitchen gas alarms in India. Its heater needs 5 V, which makes its output a 5 V signal too.

On the SuperMini, a two-resistor divider halves AO before it reaches GPIO3. The sketch multiplies the reading back up, waits a minute for the heater, and flags readings above a threshold you set from your own clean-air value.

Wiring

ESP32-C3 SuperMiniOnly the pins used are shown · 3.3 V logicMQ-2 gas sensor module10k│10k5VGND3 · 3VCCGNDDO (not connected)AO
Also needed: 2 × 10 kΩ resistors.
Every connection
ESP32-C3 SuperMiniMQ-2 gas sensor moduleWireNotes
5VVCCredHeater draws about 150 mA — from USB 5 V, never from 3V3.
GNDGNDblack
3AOyellowVia 10 kΩ / 10 kΩ divider — 10 kΩ from AO to GPIO3, 10 kΩ from GPIO3 to GND: 5 V → 2.5 V.

5 V (heater: about 150 mA) part, 3.3 V board. The heater needs 5 V. AO can reach about 5 V, so on ESP32 and Pico feed AO through a 10 kΩ / 20 kΩ divider (or similar) to stay under 3.3 V. DO is driven by the comparator from VCC — divide it too on 3.3 V boards.

Board quirks

  • The module runs at 5 V, so AO can reach 5 V. A 10 kΩ / 10 kΩ divider halves it to 2.5 V — exactly the top of the C3’s ADC range, so you lose no resolution and risk no damage.
  • DO is left unconnected: it is pulled up to 5 V on the module and would need its own divider. Comparing AO in software is more flexible anyway.
  • The heater current comes from the SuperMini’s 5V pin (USB). Keep it off 3V3 — the small 3.3 V regulator cannot supply it.
  • An MQ-2 is not a certified gas alarm. For an LPG kitchen alarm treat it as an extra warning, and keep the cylinder regulator and hose checks.

Code

mq2-esp32c3.inoArduino C++Open in PlaygroundOpen in PlaygroundFlash
// MQ-2 gas/smoke sensor module on an ESP32-C3 SuperMini.
// VCC → 5V (heater needs 5 V, ~150 mA), GND → GND,
// AO → GPIO3 through a 10 kΩ / 10 kΩ divider (5 V max → 2.5 V, the top of the C3's ADC range).
// DO is not used: it swings to 5 V and would need its own divider.
// Not a certified gas alarm — use it for experiments and as an extra warning only.
constexpr uint8_t AO_PIN = 3;
constexpr float DIVIDER = 2.0f;         // 10 kΩ / 10 kΩ
constexpr int ALERT_MV = 2000;          // sensor-side mV; tune after warm-up in clean air
constexpr uint32_t WARMUP_MS = 60000;   // heater warm-up; a brand-new sensor wants 24 h burn-in

void setup() {
  Serial.begin(115200);
  delay(1500);  // let the native USB serial port enumerate
  analogReadResolution(12);
  Serial.println("MQ-2 heating up — readings settle after about 60 s");
}

void loop() {
  uint32_t sum = 0;
  for (int i = 0; i < 16; i++) sum += analogReadMilliVolts(AO_PIN);
  int sensorMv = (sum / 16) * DIVIDER;  // undo the divider
  bool warm = millis() > WARMUP_MS;
  Serial.printf("MQ-2 output %4d mV %s\n", sensorMv,
                !warm ? "(warming up)" : sensorMv > ALERT_MV ? "— GAS/SMOKE ALERT" : "— clean air");
  delay(1000);
}

Expected serial output

Serial Monitor · 115200Output
MQ-2 heating up — readings settle after about 60 s
MQ-2 output  612 mV (warming up)
MQ-2 output  418 mV — clean air
MQ-2 output 2460 mV — GAS/SMOKE ALERT

Common errors

Reading keeps falling for many minutes

Normal for a new sensor. Leave it powered for 24 h once, then set ALERT_MV from a clean-air reading.

Board resets when the sensor is plugged in

The heater is on 3V3. Move VCC to 5V. Brownout fix.

↑↓ to move · Enter to open