#include <LiquidCrystal.h> // Include LCD library
// Initialize the LCD (RS, EN, D4, D5, D6, D7)
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// Define pin connections
const int gasSensorPin = A0; // Analog input pin for gas sensor
const int ledPin = 8; // LED connected to digital pin 8
const int buzzerPin = 9; // Buzzer connected to digital pin 9
// Threshold value (you can adjust this based on your sensor calibration)
const int gasThreshold = 300;
void setup() {
lcd.begin(16, 2); // Initialize a 16x2 LCD
pinMode(ledPin, OUTPUT); // Set LED pin as output
pinMode(buzzerPin, OUTPUT); // Set buzzer pin as output
pinMode(gasSensorPin, INPUT); // Gas sensor input
lcd.print("Gas Detector");
delay(2000);
lcd.clear();
}
void loop() {
int gasLevel = analogRead(gasSensorPin); // Read sensor value
lcd.setCursor(0, 0);
lcd.print("Gas Level: ");
lcd.print(gasLevel);
if (gasLevel > gasThreshold) {
digitalWrite(ledPin, HIGH); // Turn on LED
digitalWrite(buzzerPin, HIGH); // Turn on buzzer
lcd.setCursor(0, 1);
lcd.print("!! GAS ALERT !! ");
} else {
digitalWrite(ledPin, LOW); // Turn off LED
digitalWrite(buzzerPin, LOW); // Turn off buzzer
lcd.setCursor(0, 1);
lcd.print("Normal ");
}
delay(500); // Small delay
}