Skip to content

Files

Latest commit

7d5496f · Sep 24, 2017

History

History
executable file
·
48 lines (31 loc) · 1.26 KB

File metadata and controls

executable file
·
48 lines (31 loc) · 1.26 KB

Buzzers

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.

Connecting a buzzer

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:

buzzer

  1. Add Buzzer to the from gpiozero import... line:

    from gpiozero import Buzzer
    from time import sleep
  2. Add a line below your creation of button and lights to add a Buzzer object:

    buzzer = Buzzer(17)
  3. In GPIO Zero, a Buzzer works exactly like an LED, so try adding a buzzer.on() and buzzer.off() into your loop:

    while True:
        buzzer.on()
        sleep(1)
        buzzer.off()
    	sleep(1)
  4. A Buzzer has a beep() method which works like an LED's blink. Try it out:

    while True:
        buzzer.beep()

What Next?

  • Continue to the next worksheet on building a traffic lights system using GPIO Zero.