What it is: The MQ-2 is a low-cost gas sensor that responds to smoke, LPG, propane, methane and hydrogen. It's the classic "gas leak / smoke alarm" hobby sensor.
How it works: A heated tin-dioxide element changes resistance when combustible gas touches it. You read that as an analog voltage on AO — higher = more gas. This sketch shows a raw 0–4095 reading mapped to a 0–100 relative level (true ppm needs per-gas calibration).
Wiring:
MQ-2 AO -> GPIO0 (analog out)
MQ-2 VCC -> 5V (the heater needs 5V — 3V3 won't heat it properly)
MQ-2 GND -> GND
OLED VCC=3V3, GND=GND, SDA=GPIO4, SCL=GPIO5
VOLTAGE WARNING: AO can swing up to ~5V, but the ESP32-C3 ADC only tolerates 3.3V. Add a divider on AO (e.g. 10k from AO to GPIO0 and 15k from GPIO0 to GND) so the max stays under 3.3V, or use a level-safe module.
Libraries: only "Adafruit SSD1306" and "Adafruit GFX Library".
On screen / Serial: a relative gas level (0–100) and the raw ADC value. Wave a lighter (unlit, gas only) nearby to see it jump.
Gotchas: The heater needs 24–48 hours of initial burn-in for stable readings, and a few minutes of warm-up each power-on. Numbers are relative, not calibrated ppm — good for "is there gas?" alarms, not precise measurement.