Logo

Interfacing MQ-135 Air Quality/Gas Sensor with Arduino

MQ-135 Gas Sensor

The MQ-135 is an air quality sensor capable of detecting a wide range of harmful gases, including ammonia, nitrogen oxide, benzene, smoke, and CO2. It’s commonly used in environmental monitoring systems and IoT-based air quality applications.

Working Principle of MQ-135 Sensor

The MQ-135 works by detecting gas concentrations through changes in resistance within its internal sensing material. When exposed to gases, the sensor’s resistance changes, and these changes are converted into analog voltage output readable by Arduino.

Key Features of MQ-135 Sensor

Gas Detection Range

  • Wide detection range for multiple gases.
  • Responsive and stable output for air quality monitoring.
  • Best used in enclosed indoor spaces for air pollution alerts.

Analog and Digital Output

  • Analog output reflects varying gas levels.
  • Digital output triggers when a set threshold is crossed.
  • Can be calibrated using the onboard potentiometer.

Requirements

1. Arduino Board (UNO/Nano/etc.)

2. MQ-135 Gas Sensor Module

3. Jumper Wires

4. Breadboard (optional)

Pin Configuration of MQ-135 Module

MQ-135 Sensor Module

  • VCC: Connect to +5V on Arduino.
  • GND: Connect to GND on Arduino.
  • AOUT: Analog output to measure gas concentration.
  • DOUT: Digital output when threshold is exceeded.

Wiring MQ-135 Sensor to Arduino

To wire the MQ-135, connect VCC to 5V, GND to ground, and AOUT to one of Arduino's analog input pins (e.g., A0). If you want to use digital alerts, connect DOUT to a digital pin and adjust the onboard potentiometer to set the trigger level.

Algorithm

  1. Initialize Components

    • Connect VCC and GND of MQ-135 to Arduino 5V and GND.
    • Connect AOUT to an analog input pin like A0.
    • Optional: Connect DOUT to a digital pin for threshold alerts.
  2. Write the Code

    • Initialize the analog pin in setup().
    • Read analog values from the sensor in loop().
    • Print the readings to the Serial Monitor for testing.
  3. Display or Use the Readings

    • Display gas levels on the serial monitor or LCD.
    • Trigger alarms or fans if gas levels exceed safe limits.
    • Log data for long-term air quality analysis.
  4. Test and Calibrate

    • Upload the code and open the Serial Monitor.
    • Expose the sensor to different environments.
    • Calibrate based on output to ensure accuracy.

Arduino Code

1int mq135Pin = A0;       // Analog output connected to A0
2int airQuality = 0;      // Variable to store the sensor value
3
4void setup() {
5  Serial.begin(9600);
6  Serial.println("MQ-135 Air Quality Sensor Initialized");
7}
8
9void loop() {
10  airQuality = analogRead(mq135Pin);  // Read analog value (0–1023)
11
12  Serial.print("Air Quality Level: ");
13  Serial.println(airQuality);
14
15  delay(1000); // Read every second
16}
17

Applications of MQ-135 Gas Sensors

  • Indoor air quality monitoring
  • Smart home automation
  • Industrial safety equipment
  • Air purification systems
  • IoT-based pollution detection
  • Greenhouse gas level monitoring

Conclusion

Integrating the MQ-135 sensor with Arduino offers a powerful and budget-friendly way to monitor air quality. From detecting smoke to harmful gases, it’s an essential component for environmental monitoring and health-conscious IoT solutions.