This circuit is designed to activate a buzzer when a pushbutton is pressed. It consists of an Arduino UNO microcontroller, a resistor, a pushbutton, and a buzzer. The Arduino UNO is programmed to read the state of the pushbutton and control the buzzer accordingly. When the button is pressed, the buzzer emits a sound. The resistor is used to limit the current flowing through the pushbutton.
// Filename: sketch.ino
void setup()
{
pinMode(4, INPUT); // Set the button pin as an input
pinMode(8, OUTPUT); // Set the buzzer pin as an output
}
void loop()
{
int buttonState = digitalRead(4); // Read the state of the button
if (buttonState == HIGH) // Button is pressed when it reads HIGH
{
digitalWrite(8, HIGH); // Activate the buzzer by sending HIGH signal
}
else
{
digitalWrite(8, LOW); // Turn off the buzzer when the button is not pressed
}
}
This code is written for the Arduino UNO microcontroller. It initializes the digital pins connected to the pushbutton and buzzer. In the loop
function, it continuously checks the state of the pushbutton. If the button is pressed (reads HIGH), it activates the buzzer. If the button is not pressed, it turns off the buzzer.