A buzzer is an audio signaling device that can be found in a wide range of electronic applications. It is commonly used to produce sound or alarm in electronic circuits. Buzzers can be categorized into two main types: active and passive. An active buzzer generates a sound at a specific frequency when supplied with power, while a passive buzzer requires an external frequency (AC signal) to produce sound.
Pin Number | Description | Notes |
---|---|---|
1 | Positive (VCC) | Connect to positive power supply |
2 | Negative (GND) | Connect to ground |
// Define the buzzer pin
int buzzerPin = 9;
void setup() {
// Set the buzzer pin as an output
pinMode(buzzerPin, OUTPUT);
}
void loop() {
// Turn on the buzzer at 1kHz frequency for 1 second
tone(buzzerPin, 1000, 1000);
delay(1500); // Wait for 1.5 seconds
// Turn off the buzzer
noTone(buzzerPin);
delay(1000); // Wait for 1 second
}
Q: Can I use a passive buzzer without a microcontroller? A: Yes, but you will need an external AC signal source to drive the buzzer.
Q: How do I adjust the volume of the buzzer? A: The volume is typically adjusted by changing the voltage applied to the buzzer. However, this should be done within the buzzer's specified operating range.
Q: Can I use the same code for an active buzzer?
A: Yes, the tone()
function can be used with an active buzzer, but the sound frequency is predetermined by the buzzer's internal circuitry, so the frequency parameter will not have an effect.