#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <WiFi.h>
#include <HTTPClient.h>
const char* ssid = "Wokwi-GUEST ";
const char* password = "";
const char* token = "YOUR TOKEN";
// Define pins for MQ135, LEDs, and buzzer
#define MQ135_PIN 34 // Analog pin for MQ135 sensor
#define STATUS_LED_PIN 13 // Status LED
#define ALERT_LED_PIN 12 // Alert LED
#define BUZZER_PIN 14 // Buzzer
// Initialize the LCD with I2C address 0x27
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Threshold for MQ135 gas concentration level to trigger alert
const int gasThreshold = 500;
const int sensorThres = 100;
void setup() {
// Begin Serial communication
Serial.begin(115200);
// Initialize LCD
lcd.init();
lcd.backlight();
lcd.print("Air Quality:");
// Set up LED and buzzer pins as outputs
pinMode(STATUS_LED_PIN, OUTPUT);
pinMode(ALERT_LED_PIN, OUTPUT);
pinMode(BUZZER_PIN, OUTPUT);
// Turn on Status LED to show the system is active
digitalWrite(STATUS_LED_PIN, HIGH);
// Short delay for system initialization
delay(1000);
}
void loop() {
// Read MQ135 sensor value
int mq135Value = analogRead(MQ135_PIN);
Serial.print("MQ135 Reading: ");
Serial.println(mq135Value);
// Display the reading on the LCD
lcd.setCursor(0, 1); // Move to the second row
lcd.print("Reading: ");
lcd.print(mq135Value);
lcd.print(" "); // Clear extra characters
// Check if gas level exceeds the threshold
if (mq135Value > gasThreshold) {
digitalWrite(ALERT_LED_PIN, HIGH); // Turn on Alert LED
digitalWrite(BUZZER_PIN, HIGH); // Turn on buzzer
} else {
digitalWrite(ALERT_LED_PIN, LOW); // Turn off Alert LED
digitalWrite(BUZZER_PIN, LOW); // Turn off buzzer
}
delay(1000); // 1 second delay before next reading
}