MQ-4 Methane Gas Sensor Tutorial: Natural Gas Detection, Calibration, and Arduino Usage
This tutorial is a comprehensive, practical guide to the MQ-4 Methane Gas Sensor Module (Leobot Product #2711). It explains exactly what the MQ-4 is designed to sense, how it differs from other MQ-series sensors, how the sensing element works, and how to use both the analog and digital outputs with Arduino for natural gas leakage detection, alarms, and monitoring projects.
1) What the MQ-4 senses (and what it does not)
The MQ-4 is specifically designed for detecting methane (CH4), which is the primary combustible gas in natural gas systems.
MQ-4 is sensitive to
- Methane (natural gas)
- Compressed natural gas (CNG)
- Biogas (methane-rich)
MQ-4 is NOT suitable for
- Carbon monoxide (CO)
- Precise ppm measurement without calibration gases
- Selective gas identification in mixed environments
2) How the MQ-4 gas sensor works
The MQ-4 uses a heated tin dioxide (SnO2) sensing layer. Methane molecules reduce the surface resistance of this layer when present.
- Clean air ? high sensor resistance
- Methane present ? resistance decreases
- Resistance change ? voltage change across load resistor
3) Methane selectivity and cross-sensitivity
The MQ-4 is tuned to be more sensitive to methane than many other gases, but it is still cross-sensitive.
- Strong response to methane
- Moderate response to hydrogen
- Lower response to LPG and propane compared to MQ-2
4) Module overview and onboard electronics
The MQ-4 module typically includes:
- MQ-4 sensing element with integrated heater
- Load resistor for voltage divider output
- LM393 comparator for digital alarm output
- Threshold adjustment potentiometer
- Status LED
This makes the module suitable for both qualitative measurement and simple alarm systems.
5) Pinout and electrical characteristics
| Pin | Label | Description |
|---|---|---|
| 1 | AO | Analog output (methane level proxy) |
| 2 | GND | Ground |
| 3 | VCC | Supply voltage (typically 5V) |
| 4 | DO | Digital output (threshold-based) |
- Heater current typically 150–200 mA
- Stable 5V supply strongly recommended
6) Heater power and warm-up requirements
The internal heater must reach operating temperature before readings stabilize.
- Initial burn-in (new sensor): several hours recommended
- Typical warm-up before use: 30–60 seconds
- Readings during warm-up are unreliable
7) Analog vs digital outputs
Analog Output (AO)
- Continuous voltage related to methane concentration
- Used for monitoring trends and calibration
- Required for meaningful analysis
Digital Output (DO)
- Comparator-based ON/OFF alarm signal
- Threshold set via onboard potentiometer
- Often active LOW when gas is detected
8) Wiring to Arduino
MQ-4 VCC ? Arduino 5V
MQ-4 GND ? Arduino GND
MQ-4 AO ? Arduino A0
MQ-4 DO ? Arduino D2
9) Arduino Example 1: Methane level reading
/*
MQ-4 Methane Sensor - Analog Read
Product #2711
*/
const int MQ4_AO = A0;
void setup() {
Serial.begin(9600);
}
void loop() {
int gasValue = analogRead(MQ4_AO); // 0–1023
Serial.print("Methane level: ");
Serial.println(gasValue);
delay(500);
}
10) Arduino Example 2: Natural gas alarm
/*
MQ-4 Methane Sensor - Digital Alarm
*/
const int MQ4_DO = 2;
void setup() {
pinMode(MQ4_DO, INPUT);
Serial.begin(9600);
}
void loop() {
if (digitalRead(MQ4_DO) == LOW) {
Serial.println("WARNING: Methane detected!");
} else {
Serial.println("Air is normal");
}
delay(300);
}
11) Arduino Example 3: Software threshold alarm
/*
MQ-4 Methane Sensor - Software Threshold Alarm
*/
const int MQ4_AO = A0;
const int BUZZER = 8;
const int METHANE_THRESHOLD = 380; // adjust after calibration
void setup() {
pinMode(BUZZER, OUTPUT);
Serial.begin(9600);
}
void loop() {
int value = analogRead(MQ4_AO);
if (value > METHANE_THRESHOLD) {
digitalWrite(BUZZER, HIGH);
Serial.println("ALARM: Methane concentration high");
} else {
digitalWrite(BUZZER, LOW);
}
delay(200);
}
12) Calibration and baseline setup
Calibration is relative and environment-specific.
- Warm sensor fully
- Record baseline reading in clean air
- Introduce controlled methane source if available
- Set alarm thresholds above baseline
13) Environmental effects and limitations
- Humidity affects sensitivity
- Temperature drift alters readings
- Cross-sensitivity to other hydrocarbons
- Sensor aging over time
14) Typical applications
- Natural gas leak detection experiments
- Biogas monitoring
- Educational gas sensor projects
- Home automation gas alerts (non-certified)
15) Troubleshooting
Always high readings
- Sensor not fully warmed up
- Residual gas in environment
- High humidity or contamination
No response to methane
- Heater not powered correctly
- Incorrect wiring
- Sensor degraded or damaged
16) Quick checklist
MQ-4 Methane Gas Sensor (#2711) Checklist
----------------------------------------
? Use stable 5V supply with enough current
? Allow warm-up before reading values
? Treat readings as relative indicators
? Expect cross-sensitivity to other gases
? Use AO for trends, DO for simple alarms
? Do not use as certified safety device
? Recalibrate periodically