Write a program to interface buzzer with Arduino board to buzz on/off with the delay of 1sec.
Last Updated : 12 Nov 2025
Solution:
void setup(){
pinMode(4,OUTPUT); // Buzzer = pin 4
}
void loop(){
digitalWrite(4,HIGH); // Turn on the buzzer
delay(1000); // Wait for 1 second
digitalWrite(4,LOW); // Turn off the buzzer
delay(1000); // Wait for 1 second
}
OUTPUT DESCRIPTION:
The buzzer connected to pin 4 will turn on for 1 second, then turn
off for 1 second, repeatedly creating a 1-second on/off sound pattern.
Code Explaination:
-
Setup (
setupfunction):pinMode(4, OUTPUT);: Sets pin 4 as an output to control the buzzer.
-
Loop (
loopfunction):digitalWrite(4, HIGH);: Turns on the buzzer.delay(1000);: Waits for 1 second.digitalWrite(4, LOW);: Turns off the buzzer.delay(1000);: Waits for another 1 second.
Meanwhile you can watch this video
Watch Video