int buzzpin = 6; // Pin connected to the buzzer
int voltpin = A1; // Pin connected to the potentiometer
int potvalue;
void setup() {
Serial.begin(9600);
pinMode(voltpin, INPUT);
pinMode(buzzpin, OUTPUT);
}
void loop() {
// Read the potentiometer value
potvalue = analogRead(voltpin);
Serial.println(potvalue); // Print the potentiometer value for debugging
delay(500); // Add a small delay to slow down the serial output
// Check if the potentiometer value exceeds 1000
if (potvalue > 1000) {
tone(buzzpin, 1000); // Generate a 1kHz sound
} else {
noTone(buzzpin); // Stop the sound
}
}