#define BUZZER_PIN 8
#define BUTTON_PIN 2
void setup() {
pinMode(BUZZER_PIN, OUTPUT);
pinMode(BUTTON_PIN, INPUT_PULLUP); // use internal pull-up
}
void loop() {
if (digitalRead(BUTTON_PIN) == LOW) { // button pressed
tone(BUZZER_PIN, 1000); // 1000 Hz tone
} else {
noTone(BUZZER_PIN); // buzzer off
}
}