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. | Component | Quantity |
|---|---|---|
| 1 | Arduino UNO | 1 |
| 2 | MQ135 Air Quality Sensor Module | 1 |
| 3 | 16×2 LCD with I2C Module | 1 |
| 4 | Red LED | 1 |
| 5 | 220 Ω Resistor | 1 |
| 6 | Breadboard | 1 |
| 7 | Jumper Wires | As required |
| 8 | USB Cable | 1 |
4. Pin Connections
A. MQ135 Sensor → Arduino UNO
| MQ135 Pin | Arduino UNO Pin |
|---|---|
| VCC | 5V |
| GND | GND |
| A0 | A0 |
| D0 | Not Connected |
The A0 pin provides the analog sensor output.
B. 16×2 I2C LCD → Arduino UNO
| LCD Pin | Arduino UNO Pin |
|---|---|
| VCC | 5V |
| GND | GND |
| SDA | A4 |
| SCL | A5 |
C. LED → Arduino UNO
| LED Connection | Arduino |
|---|---|
| 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:
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
- Collect all the required components.
- Connect the MQ135 sensor to the Arduino UNO according to the connection table.
- Connect the I2C LCD to the Arduino.
- Connect the LED through a 220 Ω resistor to digital pin D8.
- Connect the Arduino UNO to the computer using a USB cable.
- Open the Arduino IDE.
- Select Arduino UNO under Tools → Board.
- Select the appropriate COM Port.
-
Install the
LiquidCrystal_I2Clibrary if it is not already installed. - Upload the given program to the Arduino.
- Allow the MQ135 sensor to warm up for a few minutes.
- Observe the sensor reading on the LCD.
- If the reading exceeds the threshold value, the LED will turn ON.
- Observe the result on the LCD and Serial Monitor.
9. Expected Output
Normal Condition
Pollution NormalValue: 180
LED: OFF
High Pollution Condition
Pollution HIGHValue: 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.




