MQ-Series Gas & Air Quality Sensor (MQ-2 / MQ-135)
Complete engineering manual covering physical operating principles, pinout architecture, circuit schematics, non-blocking Arduino/ESP32 code, and troubleshooting.

What are MQ-Series Gas Sensors?
MQ-series gas sensors are chemiresistive electro-chemical devices based on tin dioxide (SnO2) semiconductor technology. They detect combustible gases, smoke, alcohol, and air pollution by measuring the alteration of electrical conductivity that occurs when oxidizing or reducing gas molecules interact with a heated sensing surface.
Common variations include the MQ-2 (optimized for combustible gases like LPG, propane, hydrogen, and methane), the MQ-135 (optimized for hazardous air quality, ammonia, benzene, and smoke), and the MQ-7 (optimized for carbon monoxide). Each sensor features an integrated internal micro-heater and dual analog/digital outputs.
Key Technical Specifications
Wide Gas Sensitivity
Detects LPG, butane, propane, methane, hydrogen, alcohol, and airborne smoke particles.
Integrated Micro-Heater
Maintains internal SnO2 operating temperature between 200°C and 400°C for catalytic reactions.
Dual Output (Analog & Digital)
Provides continuous analog PPM concentration levels and an adjustable digital comparator trip.
Fast Transient Response
Reaction time under 10 seconds allows rapid automated emergency alarm activation.
Long-Term Stability
Durable ceramic tube with stainless steel anti-explosion explosion-proof mesh screen.
5V DC Operation
Requires 5.0V ± 0.1V DC supply to power internal nichrome heating coil (~150 mA).
Components Required
| Component | Quantity | Engineering Purpose |
|---|---|---|
| MQ-Series Gas & Air Quality Module | 1x | Primary physical environmental sensing module |
| Arduino Uno R3 or ESP32 DevKit | 1x | Microcontroller for ADC sampling and digital processing |
| Solderless Breadboard (830 tie-points) | 1x | Prototyping circuit layout and common power rail distribution |
| Jumper Wires (Male-to-Male, Male-to-Female) | 6x | Interconnecting microcontroller GPIO, power, and ground |
| Decoupling Capacitor (100nF Ceramic) | 1x | Filtering power rail high-frequency switching transient noise |
| Pull-up / Current Limiting Resistor (10kΩ / 220Ω) | 1x | Level conditioning and bus stability |
Pin Configuration & Connection Diagram
VCC
5V DC power supply input. Powers both internal heater coil and signal conditioning.
GND
Common 0V ground connection for signal and heater power return.
DO
Digital Output pin. Active LOW when gas concentration exceeds potentiometer threshold.
AO
Analog Output pin. Outputs continuous voltage proportional to gas concentration in PPM.
| Sensor Pin | Arduino Uno | ESP32 Node | Signal Description |
|---|---|---|---|
| VCC | 5V (Dedicated rail) | VIN (External 5V supply) | 5V DC. Because the heater consumes ~150mA (800mW), do not power multiple MQ sensors from USB alone. |
| GND | GND | GND | Common electrical ground return. |
| AO | A0 | GPIO 34 (via voltage divider) | Analog voltage representing sensor surface resistance (Rs). Scales from 0.1V to 4.5V. |
| DO | D2 (Interrupt pin) | GPIO 4 | Digital alarm trigger generated by onboard LM393 voltage comparator. |
Electrical Best Practices & Noise Mitigation:
- When wiring the MQ-Series Gas & Air Quality, ensure power leads are kept short to minimize stray loop inductance and inductive bounce during rapid current draw changes.
- If using an analog sensor output with a 3.3V microcontroller like an ESP32 or STM32, verify the maximum sensor output does not exceed 3.3V. If operating from a 5V supply, insert a 2:1 resistive voltage divider (e.g. 2kΩ / 1kΩ) on the signal line.
- Place a 100nF ceramic capacitor across the sensor VCC and GND pins as close to the module package as physically possible to shunt high-frequency ripple generated by nearby motors, servos, or Wi-Fi transients.
Working Principle & Mathematical Modeling
Chemiresistive Physics & Tin Dioxide Catalytic Reaction
In clean ambient air, oxygen molecules are adsorbed onto the crystalline surface of heated tin dioxide (SnO2), attracting free conduction electrons from the semiconductor material and forming an electron depletion layer. This creates a high surface resistance barrier (Ro).
When combustible or reducing gases (such as CO, methane, or LPG) come into contact with the heated surface, they react catalytically with the adsorbed oxygen ions, releasing trapped electrons back into the SnO2 conduction band. This causes the sensor resistance (Rs) to drop sharply in proportion to the gas concentration in Parts Per Million (PPM).
Gas Concentration & Resistance Ratio Formulation:
Sensor Surface Resistance Rs = ((VCC - Vout) / Vout) × RL
Relative Resistance Ratio = Rs / Ro (Where Ro is resistance in clean air)
Gas Concentration Formula: PPM = a × (Rs / Ro)^b
Heater Power Consumption: P = V_heater² / R_heater ≈ (5V)² / 31Ω ≈ 800 mW
Note: MQ sensors require a minimum "burn-in" preheat cycle of 24–48 hours upon first use to stabilize the chemical coating, and at least 3 minutes of warm-up on subsequent power-ons before readings are reliable.
Arduino & ESP32 Implementation Code
// Production-Grade MQ-2 Gas Alarm with Non-Blocking Averaging
// Platform: Arduino / ESP32 (volt-X Lab Implementation)
const int ANALOG_PIN = A0;
const int DIGITAL_ALARM_PIN = 2;
const int BUZZER_PIN = 8;
const unsigned long PREHEAT_TIME_MS = 60000; // 60s minimum warm-up
const unsigned long SAMPLE_INTERVAL = 500; // Sample every 500ms
unsigned long startTime = 0;
unsigned long lastSampleTime = 0;
float baselineRo = 10.0; // Baseline resistance in clean air (kOhms)
void setup() {
Serial.begin(115200);
pinMode(DIGITAL_ALARM_PIN, INPUT);
pinMode(BUZZER_PIN, OUTPUT);
digitalWrite(BUZZER_PIN, LOW);
startTime = millis();
Serial.println(F("MQ-2 Gas Sensor Initialized"));
Serial.println(F("Preheating internal tin-dioxide element..."));
}
float calculateResistance(int adcValue) {
float vout = (adcValue / 1023.0f) * 5.0f;
if (vout <= 0.05f) return 1000.0f; // Guard against open circuit
// Voltage divider with 10k load resistor: Rs = ((5.0 - Vout) / Vout) * 10
return ((5.0f - vout) / vout) * 10.0f;
}
void loop() {
unsigned long now = millis();
// Enforce preheat protection
if (now - startTime < PREHEAT_TIME_MS) {
if (now - lastSampleTime >= 2000) {
lastSampleTime = now;
int secondsRemaining = (PREHEAT_TIME_MS - (now - startTime)) / 1000;
Serial.print(F("Warming up... "));
Serial.print(secondsRemaining);
Serial.println(F("s remaining"));
}
return;
}
// Active measurement loop
if (now - lastSampleTime >= SAMPLE_INTERVAL) {
lastSampleTime = now;
int rawAdc = analogRead(ANALOG_PIN);
float rs = calculateResistance(rawAdc);
float ratio = rs / baselineRo;
bool alarmTriggered = digitalRead(DIGITAL_ALARM_PIN) == LOW;
Serial.print(F("ADC: ")); Serial.print(rawAdc);
Serial.print(F(" | Rs: ")); Serial.print(rs, 2); Serial.print(F(" kOhm"));
Serial.print(F(" | Rs/Ro: ")); Serial.print(ratio, 2);
Serial.print(F(" | Alarm: ")); Serial.println(alarmTriggered ? F("🚨 LEAK DETECTED!") : F("SAFE"));
if (alarmTriggered || rawAdc > 450) {
digitalWrite(BUZZER_PIN, HIGH);
} else {
digitalWrite(BUZZER_PIN, LOW);
}
}
}Code Architecture Breakdown:
- Preheat State Machine: Guards against false alarm triggering during the first 60 seconds of cold element start-up.
- Load Resistor Resistance Formula: Accurately solves the internal resistor-divider equation to compute true surface resistance in kOhms.
- Dual Hazard Triggering: Sounds the alert if either the hardware digital comparator trips or the analog PPM ADC threshold is exceeded.
- Zero Blocking Delays: Entire loop is non-blocking, ensuring timely alert activation without freezing communication threads.
Real-World Engineering Applications
Domestic LPG & Natural Gas Leak Alarms
Monitors domestic kitchens and utility closets for explosive methane or propane buildup and triggers solenoid shutoff valves.
Commercial Industrial Smoke & Fire Detection
Early warning smoke detection for electrical server rooms and warehouses prior to open flame emergence.
Air Quality & HVAC Telemetry Monitoring
Integrates with smart thermostats to trigger air ventilation when indoor VOC and CO2 levels rise.
Automotive Exhaust Emission Testing
Field diagnostic tool for detecting unburned fuel and exhaust manifold gas leaks in combustion engines.
✅ Engineering Advantages
- Extremely high sensitivity to a broad spectrum of flammable hydrocarbons and industrial gases.
- Low cost and rugged physical construction withstand harsh industrial environments.
- Integrated comparator circuit provides immediate standalone threshold switching without MCU.
⚠️ Physical Constraints & Limitations
- High power consumption: The internal heating coil continuously draws 150–180 mA at 5V.
- Cross-sensitivity: Cannot distinguish cleanly between propane, alcohol, and butane without spectroscopic filters.
- Humidity and ambient temperature fluctuations shift baseline resistance Ro.
Diagnostic & Troubleshooting Guide
| Fault / Symptom | Probable Root Cause | Corrective Action |
|---|---|---|
| Sensor element feels physically very hot to the touch | Normal operation. The internal heating coil must reach 250°C for catalytic SnO2 operation. | This is expected behavior. However, ensure the module does not contact flammable plastics. |
| Sensor continuously triggers an alarm in completely clean room air | Comparator threshold trimpot is over-sensitized, or preheat cycle is incomplete. | Allow 5 minutes of preheating, then rotate the onboard blue potentiometer until the digital LED turns off. |
| Microcontroller crashes or browns out when the sensor is connected | Sensor heater coil inrush current exceeds the USB port 500mA rating. | Power the MQ module from an independent regulated 5V power supply and join grounds. |
Frequently Asked Questions (EE/ECE Reference)
Q: Why do MQ gas sensors get warm or hot during normal operation?
MQ sensors require an internal nichrome heating coil that maintains the tin dioxide (SnO2) sensing layer at approximately 200°C to 400°C. At room temperature, oxygen molecules cannot chemically react with target gases. The warmth is necessary for the catalytic chemical reaction that alters semiconductor conductivity.
Q: How do you calibrate an MQ-2 or MQ-135 sensor to calculate exact PPM?
To calculate parts per million (PPM), you must first determine the sensor resistance in clean air (Ro). Read the analog output in clean air to find Ro = ((5.0 - Vout) / Vout) × RL. Then, consult the sensor datasheet log-log curve for your target gas (e.g. LPG) to determine the curve slope (m) and intercept (b) for the formula PPM = 10^((log10(Rs/Ro) - b) / m).
Q: Where should an MQ-2 sensor be mounted in a room for gas leak detection?
Mounting location depends entirely on the gas you are detecting. For LPG and Propane (which are denser than air), mount the sensor 30 cm above the floor near the gas appliance. For Methane, Natural Gas, and Smoke (which are lighter than air and rise), mount the sensor 30 cm below the ceiling.
Q: Can you power an MQ sensor directly from an ESP32 3.3V pin?
No. The heating element requires 5.0V ± 0.1V to reach its catalytic operating temperature. Supplying 3.3V will leave the element under-heated, resulting in zero sensitivity. Power the sensor VCC from 5V, and use a resistor voltage divider on the analog output pin before feeding the signal into an ESP32 3.3V ADC pin.