// Define pin numbers
const int buzzerPin = 4; // Buzzer connected to digital pin 4
const int buttonPin = 8; // Button connected to digital pin 8
void setup() {
// Initialize the buzzer pin as an output
pinMode(buzzerPin, OUTPUT);
// Initialize the button pin as an input
pinMode(buttonPin, INPUT);
}
void loop() {
// Read the state of the button
int buttonState = digitalRead(buttonPin);
// Check if the button is pressed
if (buttonState == HIGH) {
// Turn on the buzzer
digitalWrite(buzzerPin, HIGH);
} else {
// Turn off the buzzer
digitalWrite(buzzerPin, LOW);
}
// Small delay for debounce (optional)
delay(50);
}