Programming a piezoelectric buzzer
In this section, you will learn what a buzzer is, how to interface it with the STM32 Blue Pill, and how to write a program to build an alert sound.
A piezoelectric buzzer is a device that generates tones and beeps. It uses a piezoelectric effect, which consists of piezoelectric materials converting mechanical stress into electricity and electricity into mechanical vibrations. Piezoelectric buzzers contain a crystal with these characteristics, which changes shape when voltage is applied to it.
As has been common in these chapters, you can find a generic breakout module that is pretty straightforward to use, as shown in the following screenshot:

Figure 13.2 – Piezoelectric buzzer breakout board
This breakout board connects to the STM32 Blue Pill microcontroller board with three pins, outlined as follows:
- Input/Output (I/O): This pin must be connected to a digital output of the microcontroller. ...