// Control buzzer sound
#define POTENTIOMETER_PIN 35 // ESP32 pin GPIO35 (ADC0) connected to Potentiometer pin
#define BUZZER_PIN 21 // ESP32 pin GPIO21 connected to Buzzer's pin
#define ANALOG_THRESHOLD 1000
void setup() {
pinMode(BUZZER_PIN, OUTPUT); // set ESP32 pin to output mode
Serial.begin(9600); // initialize serial communication
}
void loop() {
int analogValue = analogRead(POTENTIOMETER_PIN); // read the input on analog pin
if (analogValue > ANALOG_THRESHOLD) {
digitalWrite(BUZZER_PIN, HIGH); // turn on Piezo Buzzer
Serial.println("Buzzer is ON"); // print message to serial monitor
} else {
digitalWrite(BUZZER_PIN, LOW); // turn off Piezo Buzzer
Serial.println("Buzzer is OFF"); // print message to serial monitor
}
delay(100); // delay for stability
}