Programming Examples
Arduino program to sound the buzzer on press on push button for 1 second
Create a Arduino program to connect the Buzzer with Push Button and alarm the buzzer for 1 second when button is pushed.
Solution
void setup()
{
pinMode(8,OUTPUT);
pinMode(2,INPUT);
}
void loop()
{
int signal;
signal=digitalRead(2);
if(signal==HIGH)
{
tone(8,1000);
delay(1000);
noTone(8);
}
}
Output