There are two kinds of buzzers active and passive ones. The difference between an active buzzer and a passive buzzer is that an active buzzer has a built-in oscillating source, so it will make sounds when electrified. But a passive one does not have such a source, so it will not beep if DC signals are used. Instead, you need to use square waves whose frequency is between 2KHz and 5KHz to drive it. Active buzzers are often more expensive than passive ones because they have multiple built-in oscillating circuits. In this tutorial we will be using an active buzzer.
The schematic diagram is as shown below:
The active buzzer has a built-in oscillating source, so it will beep as long as it is wired up, but it can only beep with fixed frequency.
Let us generate a beep tone with our Pi and an active buzzer. There a 2 possibilities to generated the required square wave signal: using PWM or toggling a pin manually. I will leave the PWM to you and demonstrate the manual mode. The functions used will be
time.sleep() and GPIO.output().
Step 1: Build the circuit
Connect the module as follows to your Raspberry Pi:
|Active Buzzer Module||Raspberry Pi|
Step 2: Write the code
Now it is your turn … rewrite the same code using PWM and share your code 🙂