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
























Write a program to interface Button, buzzer and LED, whenever the button is pressed the buzzer gives beep for 350ms and LED status is toggled.

Last Updated : 16 Jul 2025

Solution:

int btnstate=0;
int counter=0;

void setup(){
            pinMode(10,OUTPUT);  //led
            pinMode(11,OUTPUT);  //buzzer
            pinMode(12,INPUT);  //Button
}

void loop(){
            btnstate= digitalRead(12);
            if(btnstate == HIGH){
                digitalWrite(11,HIGH);
                delay(500);
                digitalWrite(11,LOW);
                if (counter%2==0)
                    digitalWrite(10,HIGH);
                else
                    digitalWrite(10,LOW);
counter+=1;
            }
            
}
Report an error

Meanwhile you can watch this video

Watch Video
Latest Updates