#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Initialize the LCD
LiquidCrystal_I2C lcd(0x27, 16, 2);
class MQ135 {
public:
MQ135(int pin) : _pin(pin) {}
float getPPM(int value) {
// Simplified conversion formula for illustration
return value * (500.0 / 1023.0);
}
private:
int _pin;
};
// Initialize the MQ-135 sensor
#define MQ135_PIN A0
MQ135 mq135_sensor(MQ135_PIN);
void setup() {
// Initialize serial communication
Serial.begin(9600);
// Initialize the LCD
lcd.init();
lcd.backlight();
// Display initial message
lcd.setCursor(0, 0);
lcd.print("Air Quality");
lcd.setCursor(0, 1);
lcd.print("Monitoring...");
delay(2000);
lcd.clear();
}
void loop() {
// Read the MQ-135 sensor value
int sensorValue = analogRead(MQ135_PIN);
// Convert the analog value to ppm (Parts Per Million)
float ppm = mq135_sensor.getPPM(sensorValue);
// Print the values to the Serial Monitor
Serial.print("Sensor Value: ");
Serial.print(sensorValue);
Serial.print(" - PPM: ");
Serial.println(ppm);
// Display the values on the LCD
lcd.setCursor(0, 0);
lcd.print("PPM: ");
lcd.print(ppm);
// Add a delay before the next reading
delay(2000);
}