The Elegoo Passive Buzzer is an audio signaling device that can be used to generate sound waves in a variety of tones. Unlike active buzzers, which have an internal oscillator and generate a tone when powered, passive buzzers require an external signal to produce sound. This makes them more versatile, as they can be used to create different tones and melodies by controlling the frequency of the input signal. Common applications include alarm devices, timers, confirmation or alert sounds in user interfaces, and simple music or sound effects in DIY projects.
Pin Number | Name | Description |
---|---|---|
1 | VCC | Connect to the positive supply voltage (5V recommended) |
2 | GND | Connect to the ground of the circuit |
// Define the buzzer pin
int buzzerPin = 9;
void setup() {
// Set the buzzer pin as an output
pinMode(buzzerPin, OUTPUT);
}
void loop() {
// Play a tone on the buzzer for 1 second
tone(buzzerPin, 1000); // 1000 Hz frequency
delay(1000); // Delay for 1 second
noTone(buzzerPin); // Stop the tone
delay(1000); // Delay for 1 second
}
Note: The tone()
function generates a square wave of the specified frequency (in Hz) on a pin. The noTone()
function stops the generation of a square wave on a pin.
Q: Can I use the passive buzzer with a 3.3V microcontroller? A: Yes, the passive buzzer can operate at voltages as low as 1V, but the sound output may be quieter at lower voltages.
Q: How do I change the tone produced by the buzzer? A: Change the frequency of the PWM signal sent to the buzzer. Higher frequencies will produce higher-pitched tones, while lower frequencies will produce lower-pitched tones.
Q: Can I play melodies with the passive buzzer? A: Yes, by varying the frequency of the input signal in a sequence that corresponds to the melody, you can play simple tunes with the passive buzzer.