Buzzers
A buzzer is a piezoelectric device that generates sound. Buzzers have multiple applications, such as generating an audio signal or acting as alarms and beepers. Figure 7.7 shows a buzzer device with positive and negative signal pins:
Figure 7.7 – A buzzer
In the Micro:bit V2, a speaker is connected to the board, as shown in Figure 7.8. It is connected on the flip side of the LED array. From Figure 7.8, we can see that the speaker/buzzer is connected close to the processor:
Figure 7.8 – A buzzer on the Micro:bit board (courtesy: https://microbit.org/get-started/user-guide/overview/)
The onboard buzzer can be used directly by executing the following simple program:
import music music.play(music.ODE)
In the preceding code, the import music
module contains predefined tunes that can be used to generate sound. music.play(music.ODE)
can play the music through the buzzer:
Figure 7.9 –...