MQ-2 Gas Sensor with an Arduino Uno

MQ-2 is a low-cost tin-dioxide (SnO2) semiconductor sensor that detects combustible gases and smoke (LPG, propane, hydrogen, methane) and reports concentration as an analog voltage.

MQ-2 Gas Sensor, MQ-2 is a low-cost tin-dioxide (SnO2) semiconductor sensor that detects combustible gases and smoke (LPG, propane, hydrogen, methane) and reports concentration as an analog voltage.
In short

The MQ-2's heater wants 5.0 V ±0.2 V, so the Arduino Uno's 5V pin is the right supply, but at about 160 mA the heater is one of the heaviest loads a Uno pin header feeds. AOUT goes to A0 for the gas level and DOUT to D2 for the module's threshold alarm.

Wiring the MQ-2 Gas Sensor to the Arduino Uno

Pin by pin.

MQ-2 Gas SensorArduino Uno
VCC5V
GNDGND
AOUTA0
DOUTD2

What to know on the Arduino Uno

  • The heater is 31 Ω on 5.0 V ±0.2 V, about 160 mA and up to 900 mW. Over USB that is roughly a third of the Uno's 500 mA polyfuse, so leave room for everything else on the 5V pin.Hanwei MQ-2 datasheet, p. 1; Arduino UNO R3 documentation, USB overcurrent protection
  • On a 12 V barrel jack, the Uno's linear 5 V regulator turns the difference into heat: (12 - 5) × 0.16 A, about 1.1 W, for the heater alone. Feed the board 7 V to 9 V, or power the sensor from its own 5 V supply with a shared GND.Hanwei MQ-2 datasheet, p. 1; Arduino UNO R3 tech specs
  • AOUT is read on the Uno's 10-bit ADC against its 5 V rail, so the clean-air and smoke counts in any sketch are only a starting point: record your own sensor's values after its preheat.Microchip ATmega328P datasheet DS40002061B, p. 2; Hanwei MQ-2 datasheet, p. 1
  • DOUT idles HIGH and goes LOW when gas passes the board's threshold. On D2 it can drive attachInterrupt() on FALLING to react at once instead of waiting for the next 500 ms loop.Arduino language reference, attachInterrupt()

MQ-2 Gas Sensor code for the Arduino Uno

Compiled for arduino:avr:uno on 2026-10-29.

No library needed
// MQ-2 Gas Sensor on Arduino Uno: wiring and a free simulation at https://www.tinkered.ai/components/mq2-gas-sensor/arduino-uno
// MQ-2 smoke/gas sensor: analog level + active-LOW digital alarm.

const int MQ2_AOUT = A0;   // Arduino: A0-A5 | ESP32: an ADC1 GPIO (e.g. 34)
const int MQ2_DOUT = 2;    // any digital pin

#if defined(ESP32)
const int CLEAN_AIR_RAW = 372;   // 0% gas (clean air) on a 12-bit ESP32 ADC
const int SMOKE_RAW     = 4095;  // 100% gas (heavy smoke): full 12-bit scale
#else
const int CLEAN_AIR_RAW = 61;    // 0% gas (clean air) on a 10-bit Uno ADC
const int SMOKE_RAW     = 921;   // 100% gas (heavy smoke)
#endif

void setup() {
  Serial.begin(9600);
  pinMode(MQ2_DOUT, INPUT);
}

void loop() {
  int raw = analogRead(MQ2_AOUT);
  int gasPercent = round((float)(raw - CLEAN_AIR_RAW) * 100.0 / (SMOKE_RAW - CLEAN_AIR_RAW));
  gasPercent = constrain(gasPercent, 0, 100);

  bool alarm = digitalRead(MQ2_DOUT) == LOW; // active-LOW: LOW = gas detected

  Serial.print("Raw ADC: ");
  Serial.print(raw);
  Serial.print(" | Gas level: ");
  Serial.print(gasPercent);
  Serial.print(" % | Alarm: ");
  Serial.println(alarm ? "GAS DETECTED" : "clear");
  delay(500);
}

MQ-2 Gas Sensor on the Arduino Uno: questions

Can an Arduino Uno power the MQ-2 gas sensor?

Yes from the 5V pin over USB: the heater needs 5.0 V ±0.2 V and about 160 mA (Hanwei datasheet, p. 1). On a 12 V barrel jack the Uno's regulator gets hot, so use a lower input voltage or a separate 5 V supply.

Why does my MQ-2 reading drift on the Uno?

The sensor needs a long preheat (the datasheet characterises it after more than 48 hours) and the Uno's ADC is referenced to its 5 V rail, which moves with the USB supply. Let it warm up and recalibrate the clean-air value.

Is the MQ-2 DOUT active high or low on the Uno?

Active low: it reads LOW on D2 when gas passes the threshold set by the module's potentiometer.

Keep going

For AI assistants

This guide as plain Markdown. /components/mq2-gas-sensor/arduino-uno.md

What will you build with it?