🚀 Hurry! Offer Ends In
00 Days
00 Hours
00 Mins
00 Secs
Enroll Now
X
Questions
























Write a program to interface buzzer with Arduino board to buzz on/off with the delay of 1sec.

Last Updated : 15 Jul 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 (setup function):

    • pinMode(4, OUTPUT);: Sets pin 4 as an output to control the buzzer.
  • Loop (loop function):

    • 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.
Report an error

Meanwhile you can watch this video

Watch Video
Latest Updates