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

ampheoampheo
3 min read

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

ComponentDescription
MQ-2 or MQ-135Gas sensor module
Arduino boardUno, Nano, Mega, etc.
BreadboardFor wiring
Jumper wiresMale-to-male
Resistor (if raw sensor)10kΩ load resistor (RL)
Serial MonitorIn Arduino IDE (for data display)

🔌 2. Wiring Diagram

For MQ-x Sensor Module (with built-in RL):

MQ Sensor PinConnect to Arduino
VCC5V
GNDGND
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 sensor

  • RL = 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 / WarningWhy It's Important
Preheat sensor properlyFor stable readings
Calibrate in clean airTo get accurate R0
Each sensor is differentCalibrate each sensor individually
Temperature/humidity affect readingsBe aware of environment
Use filtering/averagingTo 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

0
Subscribe to my newsletter

Read articles from ampheo directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

ampheo
ampheo