// Pin definitions
const int gasSensorPin = 16; // Analog pin connected to gas sensor
const int buzzerPin = 21; // Digital pin connected to buzzer
// Threshold for alert (adjust based on sensor calibration)
const int gasThreshold = 3000;
void setup() {
Serial.begin(115200); // Start serial monitor
pinMode(buzzerPin, OUTPUT); // Set buzzer pin as output
}
void loop() {
int gasValue = analogRead(gasSensorPin); // Read gas sensor analog value
Serial.print("Gas Sensor Value: ");
Serial.println(gasValue);
if (gasValue > gasThreshold) {
tone(buzzerPin, 1000); // 1 kHz sound
} else {
noTone(buzzerPin); // stop sound
}
delay(500); // Read every 0.5 second
}
Loading
esp32-s3-devkitc-1
esp32-s3-devkitc-1