4DVolt

MQ-2 gas sensor: pinout and wiring

The MQ-2 detects LPG, smoke, methane and other combustible gases. See the pinout of the analog and digital outputs, how to wire it to an Arduino and test the reading and threshold in the simulator.

MQ-2 gas sensor module
MQ-2 module

Specifications

Gases
LPG, propane, methane, smoke, hydrogen, alcohol
Supply
5 V
Range
200 to 10,000 ppm
Analog output
AO: voltage rises with gas
Digital output
DO: LOW above the threshold
Warm-up
24 h the first time; ≈ 2 min in normal use
Current
≈ 150 mA (heater)

Pinout

The module has four pins. The blue potentiometer on the board sets the threshold of the digital output.

MQ-2 module (4 pins)

1 VCC Power supply, 5 V
2 GND Ground
3 DO Digital output: LOW when gas passes the threshold
4 AO Analog output proportional to gas

MQ-2 simulator

Change the gas concentration and the module threshold and see the AO and DO outputs.

AO output (analogRead)
Voltage on AO
V
DO output

The AO output sits between 5 % and 95 % of the supply depending on the concentration. The DO output goes LOW when AO passes the threshold set on the potentiometer.

How to wire it

Connect VCC to 5 V and GND to ground. Connect AO to an analog input (A0) and, if you want a ready-made alarm, DO to a digital pin.

The sensor has an internal heater and needs a few minutes powered on to stabilize. The first time it is used, leave it powered for several hours.

The AO output rises with gas concentration. It measures a trend, not exact ppm: to convert to ppm you must calibrate with a known gas and the datasheet curve.

Turn the module potentiometer to set the DO threshold. The DO LED lights up and the pin goes LOW when the gas passes that value.

The heater draws about 150 mA: power it from a stable 5 V supply, not from the 3.3 V pin.

Example code (Arduino)

Sketch that reads the analog output, prints the value and warns when the digital output indicates gas.

#define AO_PIN A0
#define DO_PIN 2

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

void loop() {
  int reading = analogRead(AO_PIN);       // 0 to 1023
  bool gas = digitalRead(DO_PIN) == LOW;  // LOW = above threshold

  Serial.print("Reading: ");
  Serial.print(reading);
  Serial.println(gas ? "  GAS DETECTED" : "  clean air");
  delay(500);
}

Common mistakes

  • Reading the value in the first minutes: the sensor is still warming up and the reading rises and falls.
  • Expecting exact ppm without calibration: the analog reading is relative and changes with temperature and humidity.
  • Treating the MQ-2 as a certified safety detector: it is for projects and learning, not a replacement for an approved gas alarm.
  • Powering it at 3.3 V: the heater does not get hot enough and the reading is wrong.
  • Reading DO as HIGH when there is gas: on most modules it is the opposite, LOW means gas.

Always check the manufacturer's datasheet for your exact model: pin order can vary between modules.

Frequently asked questions

What does the MQ-2 sensor detect?

LPG, propane, butane, methane, hydrogen, alcohol and smoke. It cannot tell these gases apart: it indicates that combustible gas or smoke is present.

What is the difference between AO and DO?

AO gives a voltage proportional to the gas, read with analogRead(). DO gives only yes or no, set by the threshold potentiometer on the module.

How long does the MQ-2 need to warm up?

The maker recommends 24 hours the first time. After that, about 2 minutes already gives reasonable readings.

Does the MQ-2 work with an ESP32?

Yes, but power VCC with 5 V and use a voltage divider on AO, since the output can exceed 3.3 V.

Other components