🚀 Hurry! Offer Ends In
00 Days
00 Hours
00 Mins
00 Secs
Enroll Now
X
Questions
























Write a program for Interfacing Air Quality Sensor-pollution (e.g. MQ135) to Arduino board and display dots generated by sensor on LCD.

Last Updated : 16 Jul 2025

Solution:

#include <LiquidCrystal.h>

#define mq135pin A1       // MQ135 sensor pin
const int rs = 11;      // RS pin for LCD
const int en = 10;      // EN pin for LCD
const int d4 = 9;       // Data pin 4 for LCD
const int d5 = 8;       // Data pin 5 for LCD
const int d6 = 7;       // Data pin 6 for LCD
const int d7 = 6;       // Data pin 7 for LCD

LiquidCrystal lcd(rs, en, d4, d5, d6, d7);  // Initialize LCD

void setup(){
    lcd.begin(16, 2);      // Set up LCD with 16x2 display
}

void loop(){
    int airquality = analogRead(mq135pin);     // Read MQ135 sensor value
    int dot = map(airquality, 0, 1023, 0, 16);  // Map sensor value to number of dots

    lcd.clear();  // Clear the display before printing new data
    for (int i = 0; i < dot; i++) {
        lcd.print(".");  // Print dots based on air quality
    }
    delay(5000);  // Wait 5 seconds before the next reading
}
Report an error

Meanwhile you can watch this video

Watch Video
Latest Updates