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.

Provides a continuous voltage signal proportional to gas concentration for precise monitoring.
Delivers a simple HIGH or LOW signal when the gas concentration exceeds a predefined threshold, perfect for triggering alarms.
Capable of detecting gas concentrations from 300 ppm to 10,000 ppm.
The MQ-2 sensor module comes with four essential pins:

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.
| Component | Purpose | Price / link |
|---|---|---|
| MQ-2 smoke sensor module | Detects smoke and gases | Available on order — message us on WhatsApp |
| Arduino Uno | Main controller | Arduino UNO R3 DIP — Rs 1,200 |
| Jumper wires | Connections | Rs 180 |
| Breadboard | Prototyping | MB102 — Rs 250 |
| 5mm LED | Visual indication (optional) | Rs 6 |
| MQ-2 pin | Arduino |
|---|---|
| VCC | 5V |
| GND | GND |
| AO | A0 |
| DO | D2 |
| LED (optional) | D13 (the UNO's built-in LED — no extra wiring needed) |

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.
The MQ-2 sensor is highly versatile and finds applications in:
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.
digitalValue == LOW, not HIGH.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.
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.
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.
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.