Buzzer (active)
An active buzzer has its own oscillator sealed inside: give it DC and it makes one tone, no driving frequency needed. It costs $1.50 and is the simplest audible output on the board — door alarms, keypad beeps, "done" chimes. The difference from the passive buzzer matters: this one plays its own pitch and only cares about on/off; the passive one plays whatever PWM you feed it.
Pins
| Pin | What it is | Type |
|---|---|---|
| + | Positive (longer leg) | passive |
| - | Negative | passive |
| Setting | Type | Range | Default |
|---|---|---|---|
kind | enum | magnetic, piezo | magnetic |
+ is the longer leg and - the shorter one. It is a two-terminal part, so it chains: pi.GPIO17 >> Buzzer() >> pi.GND.
Wiring it in circuit.py
from wiring import *
pi = Pi()
pi.GPIO17 >> Buzzer() >> pi.GND
Driving it in main.py
from gpiozero import Buzzer
from time import sleep
buzzer = Buzzer(17)
while True:
buzzer.on()
sleep(0.2)
buzzer.off()
sleep(1)
That wiring is honest but not safe: the default magnetic buzzer draws about 19 mA from the pin, over the model's 16 mA limit, so the simulator raises an overcurrent warning and an objective's damage check fails the run, even though the buzzer sounds. The fixes are a transistor, an external supply, or the low-current kind below.
Two kinds
Buzzer() is the common 12 mm magnetic buzzer: loud, but about 25 mA. Buzzer(kind="piezo") is a 3 V piezo indicator with its own drive circuit: about 9 mA, a higher 3.5 kHz tone, and safe straight from a GPIO. Use the piezo kind whenever the buzzer hangs directly off a pin.
from wiring import *
pi = Pi()
pi.GPIO17 >> Buzzer(kind="piezo") >> pi.GNDfrom gpiozero import Buzzer
buzzer = Buzzer(17)
buzzer.beep(0.2, 0.3, n=3, background=False)
print("beeped three times")beep(0.2, 1) does the same as the loop in one call. Buzzer is an on/off device: there is no note control, because the tone is fixed by the part.
Electrical notes
- Magnetic (the default): rated 3–5 V. At 3.3 V it draws about 25 mA, over a GPIO's safe 16 mA, and it starts sounding at about 2.2 V. The model is a 132 Ω resistor, so a direct connection puts roughly 19 mA through the pin and the simulator raises its overcurrent warning. Its tone is fixed at 2300 Hz, 85 dB at 10 cm.
- Piezo (
kind="piezo"): rated 3 V, works from 2 V to 5 V, 9 mA at 3 V. The model is a 333 Ω resistor, so a direct connection draws about 9 mA from a pin, well inside the limit. Its tone is fixed at 3500 Hz, 100 dB at 10 cm. - Neither kind can change its pitch.
- PWM only chops the tone: a duty below 1 lowers the volume (the model scales volume by duty and by volts ÷ 5) but leaves the pitch alone, and a duty of 0 is silent.
- The sealed back — no visible circuit board — is the quick way to tell an active buzzer from a passive one in a parts bag.
Simulator vs real hardware
- It sounds when at least its turn-on voltage (2.2 V magnetic, 2.0 V piezo) is across its pins and the duty is above 0; PWM duty reads as volume, and the tone is heard through the page's speakers (unmute the toolbar; the sound layer appears as the volume state rises).
- Each part gets a small fixed pitch offset within a ±100 Hz spread, set by the datafeed, standing in for unit-to-unit variation instead of random warble.
- Volume = the volume knob × min(1, V ÷ 5) × duty, so a weak 3.3 V drive is quieter than a 5 V one.
- Driving the magnetic kind straight from a GPIO exceeds the Pi's 16 mA safe pin current, so the model raises an overcurrent warning: the buzzer still sounds in the sandbox, but an objective's damage check fails the run. The piezo kind stays under the limit. Real buzzers also draw a switch-on current spike that the model ignores.
Going deeper
- The other half of the family: passive buzzer, which needs PWM to make a note.
- Primer: PWM compares the two buzzers and how duty is interpreted.
- Recipe: the door alarm turns one of these on when a switch opens.
Further reading
- TMB12A05 magnetic buzzer datasheet — the 12 mm buzzer the magnetic kind models.
- PUI Audio AI-3035-TWT-3V-R — the 3 V piezo indicator the piezo kind models.
- gpiozero: Buzzer —
on,offandbeep.