What is a Smoke Sensor MQ-2? Interfacing with Arduino Uno

Introduction

The MQ-2 smoke sensor is a versatile and reliable module designed to detect a variety of gases, including methane, LPG, carbon monoxide, alcohol, propane, and hydrogen. Widely utilized in safety, security, and environmental monitoring projects, the MQ-2 is ideal for building smoke alarms, gas leak detectors, and air quality monitoring systems. Whether you're a student, hobbyist, or professional, the MQ-2 sensor offers affordability, accuracy, and ease of use for your innovative projects.

The MQ-2 smoke sensor is a gas detection module that employs a semiconductor-based sensing element to identify the presence of harmful or flammable gases.

MQ-2 smoke sensor module with Arduino UNO

Dual Output Modes

Analog Output (AO)

Provides a continuous voltage signal proportional to gas concentration for precise monitoring.

Digital Output (DO)

Delivers a simple HIGH or LOW signal when the gas concentration exceeds a predefined threshold, perfect for triggering alarms.

Wide Range of Detection

Capable of detecting gas concentrations from 300 ppm to 10,000 ppm.

Technical Specifications

  • Operating Voltage: 5V DC
  • Current Consumption: ≤150mA
  • Response Time: ≤10 seconds
  • Preheating Time: a few minutes to warm up — the readings stabilise as the sensor heats up; for the most stable readings the datasheet recommends a longer burn-in (up to 24 hours)
  • Detection Range: 300 ppm to 10,000 ppm

Pin Configuration

The MQ-2 sensor module comes with four essential pins:

  1. VCC: Connects to the 5V power supply.
  2. GND: Ground connection.
  3. AO (Analog Output): Provides variable voltage proportional to gas concentration.
  4. DO (Digital Output): Outputs HIGH/LOW signals based on gas concentration.

MQ-2 smoke sensor pin configuration — VCC, GND, AO, DO

How Does the MQ-2 Smoke Sensor Work?

The MQ-2 operates via a gas-sensitive resistor that changes resistance when exposed to gas molecules. This resistance variation is converted into an electrical signal, enabling accurate gas concentration monitoring.

Interfacing the MQ-2 Sensor with Arduino Uno

Required Components

ComponentPurposePrice / link
MQ-2 smoke sensor moduleDetects smoke and gasesAvailable on order — message us on WhatsApp
Arduino UnoMain controllerArduino UNO R3 DIP — Rs 1,200
Jumper wiresConnectionsRs 180
BreadboardPrototypingMB102 — Rs 250
5mm LEDVisual indication (optional)Rs 6

Wiring Instructions

MQ-2 pinArduino
VCC5V
GNDGND
AOA0
DOD2
LED (optional)D13 (the UNO's built-in LED — no extra wiring needed)

MQ-2 smoke detector interfacing with Arduino UNO

Arduino Code for Smoke Detection System

The digital output of the MQ-2 is active-low: DO is HIGH when the air is clean, and goes LOW when the gas concentration passes the threshold set by the onboard potentiometer. That is the one thing students get wrong most often — if your code checks for HIGH, the LED lights up when there is no gas and goes out when there is gas.

int analogPin = A0;  // Analog pin connected to AO
int digitalPin = 2;  // Digital pin connected to DO
int ledPin = 13;     // LED connected to digital pin 13

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(digitalPin, INPUT);
  Serial.begin(9600);
}

void loop() {
  int analogValue = analogRead(analogPin);
  int digitalValue = digitalRead(digitalPin);

  Serial.print("Analog Value: ");
  Serial.println(analogValue);
  Serial.print("Digital Value: ");
  Serial.println(digitalValue);

  if (digitalValue == LOW) {      // LOW = gas detected (active-low output)
    digitalWrite(ledPin, HIGH);   // Turn on LED if gas is detected
  } else {
    digitalWrite(ledPin, LOW);    // Turn off LED if no gas is detected
  }

  delay(1000);
}

This code reads the analog and digital values from the MQ-2 sensor. It lights up the LED if the gas concentration exceeds the threshold while displaying values on the Serial Monitor.

Applications of the MQ-2 Sensor

The MQ-2 sensor is highly versatile and finds applications in:

  • Smoke Alarm Detectors: Early warning systems for fire hazards.
  • Gas Leak Detectors: Monitoring LPG, methane and other flammable gases.
  • Home Security Systems: Detecting hazardous gas leaks.
  • Environmental Monitoring: Measuring air quality.
  • Science and Engineering Projects: Ideal for school and final-year projects.

For a related fire-detection project, see our flame sensor guide — it uses the same active-low digital output idea. And if you want the alarm to switch a siren or a fan, our relay module guide shows how a relay safely switches a bigger load.

Troubleshooting Common Issues

  • Check the wiring and power supply if the sensor isn't detecting gas.
  • If false alarms occur, adjust the sensor's sensitivity with the onboard potentiometer.
  • If the LED lights up with clean air and goes out with gas, your code has the logic backwards: the MQ-2 digital output is active-low, so the gas condition must be digitalValue == LOW, not HIGH.
  • If the readings drift in the first minutes, that is normal — the sensor needs a few minutes to warm up before its readings stabilise.
  • Remember this is a student learning project, not a certified gas alarm — never rely on a DIY Arduino sensor for life safety.

Where to Buy the Parts

The Arduino UNO R3 DIP (Rs 1,200), jumper wires (Rs 180), MB102 breadboard (Rs 250) and 5mm LED (Rs 6) are available at QKZEE Technologies, Shop 20, 1st Floor, Al-Khalil Center, Hall Road, Lahore, and online at qkzeetech.com with delivery all over Pakistan — see the links above. The MQ-2 smoke sensor module is available on order — message us on WhatsApp and we will arrange it for you.

Still Stuck?

If the sensor does not detect gas, or the LED lights up with clean air, message us — tell us whether the DO pin reads HIGH or LOW with clean air, what the analog value on A0 is, and whether the sensitivity potentiometer has been adjusted, and we will help you find the fault.

WhatsApp Us YouTube

FAQs

Why does the LED light up with clean air and go out with gas?

Because the MQ-2 digital output is active-low: DO is HIGH with clean air and LOW when gas passes the threshold. If your code treats HIGH as "gas detected", the LED is on all the time and goes out exactly when it should come on. The condition must be digitalValue == LOW.

Why does the sensor not detect gas?

Check the wiring (VCC to 5V, GND to GND, AO to A0, DO to D2), then turn the sensitivity potentiometer slowly while exposing the sensor to the gas. Also give the sensor a few minutes to warm up — cold readings drift.

Can I use the analog output (AO) instead of DO?

Yes — read it with analogRead() on A0. The value rises as the gas concentration rises, so you can set your own threshold in code instead of using the potentiometer. That gives you a concentration reading, not just gas / no gas.

What gases can the MQ-2 detect?

Methane, LPG, carbon monoxide, alcohol, propane and hydrogen, in the range of about 300 ppm to 10,000 ppm. It cannot tell you WHICH gas it detected — only that the concentration of one of them has risen.

Can this replace a real gas alarm?

No. This is a student learning project. A real gas alarm must be a certified, professionally installed device — never rely on a DIY Arduino sensor for life safety.

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

A few minutes before its readings stabilise. For the most stable readings the datasheet recommends a longer burn-in (up to 24 hours) — for a classroom demo, a few minutes of warm-up is enough.

Conclusion

The MQ-2 is a cheap, versatile gas sensor that turns an Arduino into a smoke and gas-leak detector. Remember the two things that matter most: the digital output is active-low (LOW means gas), and the sensor needs a few minutes to warm up before its readings settle. That is the whole project, and it works.