There are two main types of buzzer: active and passive.
A passive buzzer emits a tone when a voltage is applied across it. It also requires a specific signal to generate a variety of tones. The active buzzers are a lot simpler to use, so these are covered here.
An active buzzer can be connected just like an LED, but as they are a little more robust, you won't be needing a resistor to protect them.
Set up the circuit as shown below:
-
Add
Buzzer
to thefrom gpiozero import...
line:from gpiozero import Buzzer from time import sleep
-
Add a line below your creation of
button
andlights
to add aBuzzer
object:buzzer = Buzzer(17)
-
In GPIO Zero, a
Buzzer
works exactly like anLED
, so try adding abuzzer.on()
andbuzzer.off()
into your loop:while True: buzzer.on() sleep(1) buzzer.off() sleep(1)
-
A
Buzzer
has abeep()
method which works like anLED
'sblink
. Try it out:while True: buzzer.beep()
- Continue to the next worksheet on building a traffic lights system using GPIO Zero.