int gasSensorPin = A0; // Analog pin A0 connected to the gas sensor
int buzzerPin = 12; // Digital pin 12 connected to the buzzer
int threshold = 300; // Gas detection threshold value (adjust based on
your sensor and environment)
void setup() {
pinMode(buzzerPin, OUTPUT); // Set buzzer pin as output
Serial.begin(9600); // Initialize serial communication
}
void loop() {
int gasLevel = analogRead(gasSensorPin); // Read gas level from sensor
Serial.print("Gas level: ");
Serial.println(gasLevel); // Print gas level to the Serial Monitor
if (gasLevel > threshold) { // If gas level exceeds the threshold
digitalWrite(buzzerPin, HIGH); // Turn on the buzzer
} else {
digitalWrite(buzzerPin, LOW); // Turn off the buzzer
}
delay(1000); // Wait for 1 second before checking again
}