The MQ gas sensor series from Hanwei Electronics is the most widely used family of gas detectors in Arduino and maker projects worldwide. These semiconductor gas sensors detect everything from cooking gas leaks (MQ-2) to alcohol breath testing (MQ-3), ambient air quality (MQ-135), and carbon monoxide (MQ-7). In this comprehensive guide, we explain how MQ sensors work, cover each sensor type, walk through Arduino wiring and calibration, and show you how to build a practical air quality monitor and safety gas leak detector.
Table of Contents
- How MQ Sensors Work
- Sensor Warm-Up Time
- MQ-2: Smoke, LPG, and Methane
- MQ-3: Alcohol Detection
- MQ-135: Air Quality (CO2 and NH3)
- MQ-7: Carbon Monoxide
- Sensor Comparison Table
- Wiring to Arduino
- Analog vs Digital Output
- Calibrating with Clean Air Baseline
- Air Quality Monitor Project
- Gas Leak Detector with Buzzer
- FAQ
How MQ Sensors Work
MQ sensors use a tin dioxide (SnO2) semiconductor as the sensing material. In clean air, tin dioxide conducts electricity poorly (high resistance). When target gas molecules come into contact with the heated sensor surface, they are adsorbed onto the tin dioxide and change its electrical properties, causing the resistance to decrease. The lower the resistance, the higher the gas concentration.
Inside the MQ sensor package you will find:
- Sensing element: A small alumina ceramic tube coated with tin dioxide and doped with catalytic materials specific to the target gas
- Heating coil: A nichrome wire that heats the sensing element to 200 to 400 degrees Celsius, which is required for the gas adsorption reaction to occur efficiently
- Electrode wires: Four connections — two for the heater circuit and two for measuring the sensing element resistance
- Stainless steel mesh: Protects the element and filters out dust and particles
The MQ sensor module (breakout board) adds a fixed load resistor in series with the sensing element to form a voltage divider, so the output voltage changes with gas concentration. The module also includes an LM393 comparator that produces a digital HIGH/LOW output when concentration exceeds a threshold set by a trimpot.
Sensor Warm-Up Time
This is the most important thing to know about MQ sensors: they require a warm-up period before giving accurate readings. When first powered on, the heater takes time to reach operating temperature and stabilise. The datasheet-specified preheat time varies by model:
- Initial power-on (cold sensor): 24 to 48 hours for complete conditioning of a brand-new sensor
- Warm-up after power-on (routine use): At least 20 minutes, ideally 30 to 60 minutes
For Arduino projects that cycle power frequently, take readings only after 2 to 3 minutes of power-on, and treat very early readings as approximate. For precise monitoring, keep the sensor continuously powered. The continuous power consumption is about 800 mW to 1 W per sensor — this is significant for battery-powered designs.
MQ-2: Smoke, LPG, and Methane
The MQ-2 is the most popular gas sensor in the series because it detects the gases most relevant to home safety in India: LPG (liquefied petroleum gas used for cooking), methane (natural gas, biogas), hydrogen, propane, alcohol vapour, and smoke.
Detection range: 300 to 10,000 ppm for LPG; 200 to 10,000 ppm for smoke
Best for: Kitchen gas leak detector, smoke alarm, biogas monitoring
The MQ-2 is a good choice for an LPG leak alarm because LPG is heavier than air and accumulates near the floor. Mount the MQ-2 sensor low on a wall (20 to 30 cm from the floor) in the kitchen for maximum effectiveness.
MQ-3: Alcohol Detection
The MQ-3 is sensitive to alcohol vapour (ethanol) with relatively low cross-sensitivity to other gases. It is used in breathalyser projects and industrial alcohol concentration monitoring.
Detection range: 0.05 to 10 mg/L alcohol in air
Best for: Breathalyser projects, industrial alcohol storage monitoring, fermentation monitoring
MQ-135: Air Quality (CO2 and NH3)
The MQ-135 detects harmful gases in the air including ammonia (NH3), nitrogen oxides, alcohol, benzene, smoke, and carbon dioxide (CO2). It is widely used as a general-purpose air quality sensor and is particularly relevant in India where indoor and outdoor air quality is a serious health concern.
Detection range: 10 to 300 ppm ammonia, 10 to 1000 ppm CO2 (approximate), 10 to 1000 ppm benzene
Best for: Indoor air quality monitor, office CO2 monitor, chemical storage area monitoring, agricultural ammonia detection
The MQ-135 cannot distinguish between different gases — it gives a composite response. For a true CO2 measurement you need a dedicated NDIR CO2 sensor (like the MH-Z19 or SCD30). However, for general air quality alerting, the MQ-135 is very useful and affordable.
MQ-7: Carbon Monoxide
The MQ-7 detects carbon monoxide (CO) — the colourless, odourless gas produced by incomplete combustion of fuel. CO poisoning is a serious risk from generators, gas heaters, charcoal stoves, and vehicle exhaust in enclosed spaces. The MQ-7 uses a unique two-voltage heating cycle (5V for 60 seconds, 1.4V for 90 seconds) to achieve good CO selectivity and reduce cross-sensitivity to hydrogen.
Detection range: 20 to 2000 ppm CO
Best for: Generator room safety, kitchen exhaust monitoring, parking garage safety, industrial CO monitoring
Sensor Comparison Table
| Sensor | Primary Target Gas | Detection Range | Best Application |
|---|---|---|---|
| MQ-2 | LPG, Methane, Smoke | 300–10,000 ppm | Kitchen gas leak |
| MQ-3 | Alcohol (Ethanol) | 0.05–10 mg/L | Breathalyser |
| MQ-4 | Methane, Natural Gas | 300–10,000 ppm | Biogas monitor |
| MQ-7 | Carbon Monoxide | 20–2,000 ppm | CO safety alarm |
| MQ-135 | CO2, NH3, Benzene | 10–1,000 ppm | Air quality index |
| MQ-9 | CO, LPG, Methane | 10–1,000 ppm CO | Multi-gas safety |
Wiring to Arduino
All MQ sensor modules have the same four-pin interface:
| MQ Module Pin | Arduino Pin |
|---|---|
| VCC | 5V |
| GND | GND |
| AOUT (Analog) | A0 |
| DOUT (Digital) | Pin 7 |
Note: MQ sensors draw 150 to 200 mA from the heater circuit. The Arduino 5V pin can typically supply 500 mA total, so powering 1 to 2 MQ sensors directly is fine. For 3 or more sensors, use an external 5V power supply.
Analog vs Digital Output
MQ modules provide two outputs simultaneously:
- AOUT (Analog): A continuously varying voltage (0 to 5V) proportional to gas concentration. Read with analogRead() for quantitative measurements and data logging. The relationship between voltage and ppm concentration is non-linear and requires calibration curves from the datasheet.
- DOUT (Digital): A clean HIGH/LOW signal based on a threshold set by the onboard trimpot. Read with digitalRead() for simple alarm applications. Turn the trimpot clockwise to increase sensitivity (lower the trigger threshold), anticlockwise to decrease sensitivity.
For alarm-only projects, use the digital output — it is simpler and more reliable. For data logging, air quality indexing, or displaying a numeric reading, use the analog output with calibration.
Calibrating with Clean Air Baseline
MQ sensor calibration involves establishing a clean-air baseline resistance (Rs/R0 ratio) and using the sensor characteristics curve from the datasheet to convert resistance ratios to ppm. Here is a simplified baseline calibration approach:
const int MQ_PIN = A0;
const float RL_VALUE = 10.0; // Load resistor on module (kohms, check your module)
const float CLEAN_AIR_FACTOR = 9.83; // MQ-135 Rs/R0 in clean air (from datasheet)
float R0 = 10.0; // Will be calculated during calibration
float getMQResistance(int rawADC) {
float voltage = rawADC * (5.0 / 1023.0);
float rs = ((5.0 - voltage) / voltage) * RL_VALUE;
return rs;
}
void setup() {
Serial.begin(9600);
Serial.println("MQ sensor calibration");
Serial.println("Keep sensor in fresh outdoor air.");
Serial.println("Warming up for 3 minutes...");
delay(180000); // 3 min warm-up
// Average 100 readings for calibration
float rsSum = 0;
for (int i = 0; i < 100; i++) {
rsSum += getMQResistance(analogRead(MQ_PIN));
delay(100);
}
float rsAvg = rsSum / 100.0;
R0 = rsAvg / CLEAN_AIR_FACTOR;
Serial.print("Calibrated R0 = ");
Serial.print(R0); Serial.println(" kohm");
Serial.println("Use this R0 value in your monitoring sketch.");
}
void loop() {}
Air Quality Monitor Project
This sketch reads from an MQ-135 and displays a qualitative air quality index on the Serial Monitor, suitable for an indoor air quality monitor:
const int MQ135_PIN = A0;
const int LED_GREEN = 9;
const int LED_YELLOW = 10;
const int LED_RED = 11;
const float R0 = 76.63; // Your calibrated R0 value
const float RL_VALUE = 10.0;
const float CLEAN_AIR = 9.83;
float getSensorRatio() {
int raw = analogRead(MQ135_PIN);
float voltage = raw * (5.0 / 1023.0);
float rs = ((5.0 - voltage) / voltage) * RL_VALUE;
return rs / R0;
}
// MQ-135 approximate ppm for CO2 (from datasheet curve)
// This is approximate — use for relative comparison only
float getRatio() {
return getSensorRatio();
}
void setup() {
Serial.begin(9600);
pinMode(LED_GREEN, OUTPUT);
pinMode(LED_YELLOW, OUTPUT);
pinMode(LED_RED, OUTPUT);
delay(120000); // 2 min warm-up
Serial.println("Air Quality Monitor Ready");
}
void loop() {
float ratio = getRatio();
// Turn off all LEDs
digitalWrite(LED_GREEN, LOW);
digitalWrite(LED_YELLOW, LOW);
digitalWrite(LED_RED, LOW);
String quality;
if (ratio > 1.5) {
quality = "GOOD (fresh air)";
digitalWrite(LED_GREEN, HIGH);
} else if (ratio > 0.8) {
quality = "MODERATE (ventilate room)";
digitalWrite(LED_YELLOW, HIGH);
} else {
quality = "POOR (open windows now!)";
digitalWrite(LED_RED, HIGH);
}
Serial.print("Rs/R0 Ratio: ");
Serial.print(ratio, 3);
Serial.print(" | Air Quality: ");
Serial.println(quality);
delay(3000);
}
Gas Leak Detector with Buzzer
For a practical LPG or methane gas leak alarm using the MQ-2, this sketch uses both the analog output for data and a buzzer for alarm. Mount the sensor low on the kitchen wall and the buzzer where it will be heard:
const int MQ2_ANALOG = A0;
const int MQ2_DIGITAL = 7;
const int BUZZER_PIN = 8;
const int LED_RED = 13;
const int ALARM_THRESHOLD = 400; // Analog threshold (0–1023)
// Lower = more sensitive
bool alarmActive = false;
void setup() {
Serial.begin(9600);
pinMode(MQ2_DIGITAL, INPUT);
pinMode(BUZZER_PIN, OUTPUT);
pinMode(LED_RED, OUTPUT);
Serial.println("Warming up MQ-2 gas sensor...");
delay(120000); // 2 minute warm-up
Serial.println("Gas leak detector ready.");
}
void loop() {
int analogVal = analogRead(MQ2_ANALOG);
int digitalVal = digitalRead(MQ2_DIGITAL);
Serial.print("Analog: "); Serial.print(analogVal);
Serial.print(" | Digital: "); Serial.println(digitalVal);
// Trigger alarm if analog exceeds threshold OR digital pin goes LOW
// (Digital pin is LOW when gas detected — active low on most modules)
if (analogVal > ALARM_THRESHOLD || digitalVal == LOW) {
if (!alarmActive) {
Serial.println("WARNING: Gas detected!");
alarmActive = true;
}
// Pulsing alarm
digitalWrite(BUZZER_PIN, HIGH);
digitalWrite(LED_RED, HIGH);
delay(300);
digitalWrite(BUZZER_PIN, LOW);
delay(300);
} else {
alarmActive = false;
digitalWrite(BUZZER_PIN, LOW);
digitalWrite(LED_RED, LOW);
delay(1000);
}
}
Safety note: When a gas leak alarm sounds, turn off the gas cylinder valve first, then ventilate the area. Do not press any electrical switches (including the alarm off button) until the room is fully ventilated, as a spark can ignite accumulated gas.
Frequently Asked Questions
Q: Can I use an MQ sensor with 3.3V (ESP32, Arduino Due)?
MQ sensors require 5V for the heater to reach operating temperature. On 3.3V systems, the heater will not get hot enough, resulting in incorrect readings. Power the MQ module VCC from 5V, and use a voltage divider (10K / 20K) on the AOUT pin to bring the signal down to 3.3V before connecting to an ESP32 ADC pin. The DOUT digital pin is typically 3.3V compatible on most modules.
Q: How long do MQ sensors last?
With continuous operation, MQ sensors typically last 3 to 5 years. They are consumable components — the tin dioxide sensing material gradually degrades, changing the baseline resistance. Recalibrate annually in clean air to maintain accuracy. Exposure to silicone vapour, high concentrations of corrosive gases, or extreme humidity significantly reduces lifespan.
Q: Why does my MQ-135 give different readings indoors vs outdoors?
This is expected. Outdoor air contains a baseline of approximately 400 ppm CO2, while a poorly ventilated indoor room with people present can reach 1000 to 3000 ppm CO2. The MQ-135 also detects cooking fumes, cleaning products, and VOCs indoors, all of which elevate the reading. Use outdoor readings as your fresh-air baseline for calibration.
Q: Can I use MQ sensors in rain or high humidity?
MQ sensors tolerate up to 95% relative humidity (non-condensing) but condensing moisture on the element significantly affects readings and can damage the sensor. Protect sensors from direct rain. In high-humidity environments like kitchens, the sensor may read higher than actual gas concentration.
Q: Which MQ sensor is best for an Indian kitchen?
For Indian kitchens using LPG cylinders, the MQ-2 is the most relevant choice as it detects LPG, propane, butane, and methane. Place it 20 to 30 cm above the floor level (LPG is heavier than air) and away from the cooking flame to avoid false triggers from combustion products.
Shop Sensors at Zbotic.in
Find sensors, modules, and components for your next project — fast delivery across India.
Add comment