How to calibrating and using MQ-series gas sensors (like MQ-2, MQ-135) with Arduino?


Here's a manual for calibrating and using MQ-series gas sensors (like MQ-2, MQ-135) with Arduino, written in clear and practical English.
📘 Arduino Manual for MQ Gas Sensor (MQ-2, MQ-135, etc.)
✅ 1. What You'll Need
Component | Description |
MQ-2 or MQ-135 | Gas sensor module |
Arduino board | Uno, Nano, Mega, etc. |
Breadboard | For wiring |
Jumper wires | Male-to-male |
Resistor (if raw sensor) | 10kΩ load resistor (RL) |
Serial Monitor | In Arduino IDE (for data display) |
🔌 2. Wiring Diagram
For MQ-x Sensor Module (with built-in RL):
MQ Sensor Pin | Connect to Arduino |
VCC | 5V |
GND | GND |
AO (Analog) | A0 |
DO (Digital) | Optional (e.g., D2) |
Use AO for real gas readings and calibration.
🔧 3. Basic Arduino Code (Read Analog Value)
cpp
const int MQ_PIN = A0;
void setup() {
Serial.begin(9600);
}
void loop() {
int rawValue = analogRead(MQ_PIN);
float voltage = rawValue * (5.0 / 1023.0);
Serial.print("Raw ADC: ");
Serial.print(rawValue);
Serial.print(" | Voltage: ");
Serial.print(voltage);
Serial.println(" V");
delay(1000);
}
🧪 4. Calibrating the Sensor (Manual Method)
Step 1: Burn-in / Preheat
Power the sensor for 24 to 48 hours
Keep in clean air during this period
Step 2: Calculate Rs (Sensor Resistance)
Use the formula:
plaintext
Rs = RL × (5.0 - Vout) / Vout
Where:
Vout
= analog voltage from the sensorRL
= load resistor (usually 10kΩ)
Arduino Code to Estimate Rs:
cpp
float RL = 10.0; // kΩ
int adc = analogRead(MQ_PIN);
float Vout = adc * (5.0 / 1023.0);
float Rs = RL * (5.0 - Vout) / Vout;
Serial.print("Rs = ");
Serial.print(Rs);
Serial.println(" kΩ");
Step 3: Measure R0 in Clean Air
In clean air, average Rs over several readings
Set:
cpp
float R0 = Rs / Ro_clean_air_ratio;
Datasheet values:
MQ-2: clean air Rs/R0 ≈ 9.83
MQ-135: Rs/R0 ≈ 3–10 (approximate)
5. Estimating Gas Concentration (PPM)
Use log-log curve approximation from datasheet:
cpp
// Example for LPG (MQ-2)
float ratio = Rs / R0;
float ppm = pow(10, (-0.47 * log10(ratio)) + 1.70);
You can also plot log(Rs/R0)
vs log(PPM)
in Excel to fit your own line (y = ax + b
).
6. Example Output (Serial Monitor)
makefile
Rs = 2.34 kΩ
R0 = 0.25 kΩ
Rs/R0 = 9.36
Estimated PPM: 350
Tips and Warnings
Tip / Warning | Why It's Important |
Preheat sensor properly | For stable readings |
Calibrate in clean air | To get accurate R0 |
Each sensor is different | Calibrate each sensor individually |
Temperature/humidity affect readings | Be aware of environment |
Use filtering/averaging | To reduce noise in real-time data |
Optional Enhancements
Add an OLED or LCD to show real-time PPM
Use EEPROM to store R0
Add buzzer or relay for alarms
Subscribe to my newsletter
Read articles from ampheo directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
