Arduino Project With Active Buzzer
Active buzzers can produce sound with DC supply. Unlike passive buzzers they have a built-in oscillator. I’ll publish a more detailed difference between active buzzer and passive buzzer in later articles, but for the time being let me show you how you can build a simple project using active buzzer.
In this project when you push the button the buzzer will ring as long as the button is pushed. Once you let go the buzzer will switch off.
Components Required
- Active buzzer
- Push button
- Arduino
- Jumper cables
- Bread board
Circuit Diagram
Positive Buzzer — 13 (purple)
Negative Buzzer — GND (yellow)
Positive Push Button — 12 (green)
Negative Push Button — GND (yellow)
Note: For push buttons there are no +ve or -ve terminals. It depends upon what you are connecting the pins to, whether to an Arduino pin or GND.
Source Code
int buzzerPin = 13;
int buttonPin = 12;
void setup() {
pinMode(buzzerPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
}
void loop() {
int buttonState = digitalRead(buttonPin);
if (buttonState == LOW) {
digitalWrite(buzzerPin, HIGH);
}
if (buttonState == HIGH) {
digitalWrite(buzzerPin, LOW);
}
}