The buzzer used with the Raspberry Pi Pico consists of a membrane that vibrates thanks to the piezoelectric effect. This phenomenon occurs when certain materials deform under the influence of an electric field, thereby transforming electrical energy into vibrations. As a result, the buzzer can produce simple tones and melodies.
Buzzers are commonly found in various devices such as alarm systems, computers, and timers.
The buzzer can be very useful for adding sound to your project on the Raspberry Pi Pico.
Here is the circuit diagram to make it work:
// Define the pin number to which the buzzer is connected
const int buzzerPin = 15; // Pin D15 for the buzzer
void setup() {
// Initialize the buzzer pin as an output
pinMode(buzzerPin, OUTPUT);
}
void loop() {
// Turn on the buzzer by sending a HIGH voltage
digitalWrite(buzzerPin, HIGH);
// Wait for 500 milliseconds (0.5 second)
delay(500);
// Turn off the buzzer by sending a LOW voltage
digitalWrite(buzzerPin, LOW);
// Wait another 500 milliseconds
delay(500);
}