The buzzer consists of a vibrating blade with the piezoelectric effect.
Piezoelectricity is a property possessed by certain minerals that deform when subjected to an electric field. It allows the transformation of electrical energy into vibration, enabling the production of simple notes and melodies.
Buzzers can be found in alarm devices, computers, timers, and more. There are two types of buzzers: Active and Passive buzzers.
There are some fundamental differences between Active and Passive buzzers:
Active Buzzer: It can generate sound when it receives a continuous voltage.
Passive Buzzer: Functions like a speaker, so an audio signal needs to be provided for it to produce sound.
To differentiate between the two, you can apply a continuous voltage to both buzzers. The one that emits sound will be the active buzzer. However, both buzzers operate similarly, which is why the programs we will propose will be the same for both types.
The electronic symbol of the buzzer is composed of two circles with a plus sign (+).
To make the program work, you need to install the library dedicated to the buzzer. This library contains all the notes playable by the buzzer. The buzzer library is in .zip format, so to install it, click on “Sketch,” then “Include Library,” and “Add .Zip Library.”
If you encounter any problems installing the library, we recommend checking out our dedicated tutorial.
There are other types of possible notes that you can play. For this, you can use the library and input the note reference as in the melody list of the program or directly input the frequency.
By directly inputting the frequency, you no longer need to add the library to your code.
As we have just seen, we can program the buzzer with or without the library.
Here is the function to program your buzzer with the library:
You will find an example of using this function in the programs below.
Here is the function to program your buzzer without the library:
You will find an example of using this function in the programs below.
Now, let’s see the circuits you need to create to use the programs. All codes work with these circuits.
Here is the schema for the passive buzzer:
Here is the schema for the active buzzer:
To replicate the schema of the active buzzer on Fritzing, you need to install the active buzzer component. We recommend our Fritzing course if you have difficulty installing the component.
We will present two codes to make your buzzer work. The first one works with the library, and the second one works without it.
Here you have a sequence of notes from low to high using the library:
Here you have an alarm without the library:
As we have seen, we can play multiple notes with our buzzer. But it’s essential to find a good melody. For this, we recommend translating the notes from a sheet music you have chosen into frequency Hz.
For example, we have translated the song “Jingle Bells” as follows: