#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define MQ2_PIN 34
#define BUZZER_PIN 26
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
Serial.begin(115200);
pinMode(BUZZER_PIN, OUTPUT);
digitalWrite(BUZZER_PIN, LOW);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Gas Monitoring");
lcd.setCursor(0, 1);
lcd.print("System Ready");
delay(2000);
lcd.clear();
}
void loop() {
int gasValue = analogRead(MQ2_PIN);
Serial.print("Gas Value: ");
Serial.println(gasValue);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Gas:");
lcd.print(gasValue);
if (gasValue > 2000) {
lcd.setCursor(0, 1);
lcd.print("GAS DETECTED!");
digitalWrite(BUZZER_PIN, HIGH);
} else {
lcd.setCursor(0, 1);
lcd.print("Air Normal");
digitalWrite(BUZZER_PIN, LOW);
}
delay(500);
}