Interfacing Air Quality Sensor-pollution (e.g. MQ135) - display data on LCD, switch on LED when data sensed is higher than specified value.

Computer Programming  and Technology.
By -
0

 1. Aim

To interface an MQ135 Air Quality Sensor with an Arduino UNO, display the sensor reading on a 16×2 I2C LCD, and switch ON an LED when the pollution level exceeds a specified threshold value.


2. Components Required

S. No.ComponentQuantity
1Arduino UNO1
2MQ135 Air Quality Sensor Module1
316×2 LCD with I2C Module1
4Red LED1
5220 Ω Resistor1
6Breadboard1
7Jumper WiresAs required
8USB Cable1

4. Pin Connections

A. MQ135 Sensor → Arduino UNO

MQ135 PinArduino UNO Pin
VCC5V
GNDGND
A0A0
D0Not Connected

The A0 pin provides the analog sensor output.

B. 16×2 I2C LCD → Arduino UNO

LCD PinArduino UNO Pin
VCC5V
GNDGND
SDAA4
SCLA5

C. LED → Arduino UNO

LED ConnectionArduino
Anode (+)D8 through 220 Ω resistor
Cathode (−)GND



Note: Always use a current-limiting resistor with the LED.


5. Circuit Connection

Make the following connections on the breadboard:

ARDUINO UNO
┌───────────────┐
│ │
MQ135 VCC ────┤ 5V │
MQ135 GND ────┤ GND │
MQ135 A0 ─────┤ A0 │
│ │
LCD VCC ──────┤ 5V │
LCD GND ──────┤ GND │
LCD SDA ──────┤ A4 │
LCD SCL ──────┤ A5 │
│ │
D8 ──220Ω─────┤──► LED ── GND │
└───────────────┘






6. Arduino Program

Install the LiquidCrystal_I2C library in Arduino IDE and upload the following program:

#include <Wire.h>

#include <LiquidCrystal_I2C.h>


// LCD I2C address

LiquidCrystal_I2C lcd(0x27, 16, 2);


const int mq135Pin = A0;

const int ledPin = 8;


// Pollution threshold

int threshold = 300;


void setup()

{

  Serial.begin(9600);


  lcd.init();

  lcd.backlight();


  pinMode(ledPin, OUTPUT);


  digitalWrite(ledPin, LOW);


  lcd.setCursor(0, 0);

  lcd.print("Air Quality");

  lcd.setCursor(0, 1);

  lcd.print("Monitoring...");


  delay(2000);

  lcd.clear();

}


void loop()

{

  // Read MQ135 sensor

  int airValue = analogRead(mq135Pin);


  // Display reading on LCD

  lcd.setCursor(0, 0);

  lcd.print("Air Quality:    ");


  lcd.setCursor(0, 1);

  lcd.print("Value: ");

  lcd.print(airValue);

  lcd.print("   ");


  // Display reading on Serial Monitor

  Serial.print("Air Quality Value: ");

  Serial.println(airValue);


  // Check pollution level

  if (airValue > threshold)

  {

    digitalWrite(ledPin, HIGH);


    lcd.setCursor(0, 0);

    lcd.print("Pollution HIGH  ");

  }

  else

  {

    digitalWrite(ledPin, LOW);


    lcd.setCursor(0, 0);

    lcd.print("Pollution Normal");

  }


  delay(1000);

}

7. Working Principle

The MQ135 sensor detects changes in air quality and produces an analog output.

The Arduino reads this analog output using its A0 analog input pin.

int airValue = analogRead(mq135Pin);

The Arduino then compares the sensor value with the predefined threshold:

if (airValue > threshold)

Here:

threshold = 300

Therefore:

  • If sensor value > 300 → Pollution is considered HIGH → LED turns ON.
  • If sensor value ≤ 300 → Pollution is considered NORMAL → LED remains OFF.

The sensor value/status is displayed on the 16×2 I2C LCD.


8. Procedure

  1. Collect all the required components.
  2. Connect the MQ135 sensor to the Arduino UNO according to the connection table.
  3. Connect the I2C LCD to the Arduino.
  4. Connect the LED through a 220 Ω resistor to digital pin D8.
  5. Connect the Arduino UNO to the computer using a USB cable.
  6. Open the Arduino IDE.
  7. Select Arduino UNO under Tools → Board.
  8. Select the appropriate COM Port.
  9. Install the LiquidCrystal_I2C library if it is not already installed.
  10. Upload the given program to the Arduino.
  11. Allow the MQ135 sensor to warm up for a few minutes.
  12. Observe the sensor reading on the LCD.
  13. If the reading exceeds the threshold value, the LED will turn ON.
  14. Observe the result on the LCD and Serial Monitor.

9. Expected Output

Normal Condition

Pollution Normal
Value: 180

LED: OFF

High Pollution Condition

Pollution HIGH
Value: 450

LED: ON


10. How to Change the Pollution Threshold

The threshold can be changed in the program:

int threshold = 300;

For example, to set the threshold to 400:

int threshold = 400;

Important: The threshold of 300 is only an example for this classroom practical. MQ135 gives a raw analog reading; obtaining an actual AQI or gas concentration requires proper calibration.


11. Troubleshooting

LCD is not displaying anything

Check:

  • VCC → 5V
  • GND → GND
  • SDA → A4
  • SCL → A5

If 0x27 does not work, try:

LiquidCrystal_I2C lcd(0x3F, 16, 2);

LED is not glowing

Check:

  • LED polarity
  • 220 Ω resistor
  • LED connection to D8
  • Common GND

MQ135 reading is unstable

Allow the sensor to warm up before taking readings. MQ135 modules require a warm-up period, and readings can vary with the environment.


12. Result

The MQ135 Air Quality Sensor was successfully interfaced with the Arduino UNO. The air-quality sensor reading was displayed on the 16×2 I2C LCD, and the LED was successfully switched ON when the sensor reading exceeded the predefined threshold value.



Post a Comment

0 Comments

Post a Comment (0)
3/related/default