A piezo buzzer is a compact and versatile electronic sound-producing device that operates on the principle of the piezoelectric effect. When an electric signal is applied to a piezoelectric material, it deforms and generates an audible sound. Piezo buzzers are widely used in various applications such as alarm clocks, kitchen timers, computer devices, toys, and as alert signals in medical and industrial equipment due to their reliability and simplicity.
Pin Number | Description |
---|---|
1 | Positive (V+) |
2 | Negative (Ground, GND) |
// Define the buzzer pin
int buzzerPin = 9;
void setup() {
// Set the buzzer pin as an output
pinMode(buzzerPin, OUTPUT);
}
void loop() {
// Produce a 2kHz tone for 1 second
tone(buzzerPin, 2000); // Send a 2kHz sound signal...
delay(1000); // ...for 1 second
noTone(buzzerPin); // Stop the tone
delay(1000); // Wait for 1 second
}
Q: Can I use a piezo buzzer with a battery? A: Yes, as long as the battery voltage matches the buzzer's rated voltage.
Q: How can I change the sound frequency of the buzzer?
A: Adjust the frequency of the input signal. In the Arduino example, change the value in the tone()
function.
Q: Is it possible to play melodies with a piezo buzzer? A: Yes, by varying the frequency and duration of the input signal, you can create simple melodies.
Q: Can I control the volume of the piezo buzzer? A: The volume can be somewhat controlled by varying the voltage or using PWM, but piezo buzzers have limited volume control compared to other audio devices.