int buttonPin = 2; // Pin for push button
int buzzerPin = 4; // Pin for buzzer
int buttonState = 0;
void setup() {
pinMode(buttonPin, INPUT); // Set pin 2 as input (no pull-up)
pinMode(buzzerPin, OUTPUT); // Set pin 4 as output
}
void loop() {
buttonState = digitalRead(buttonPin); // Read the state of the push button
if (buttonState == HIGH) { // If the button is pressed
tone(buzzerPin, 600, 250); // Play a 262Hz tone for 250 milliseconds
} else {
noTone(buzzerPin); // Turn the buzzer off
}
}