The_Official_Raspberry_Pi_-_Beginner’s_Book_Vol1,_2018 (1)

(singke) #1

138 THE OFFICIAL RASPBERRY PI BEGINNER'S GUIDE


Make some noise: controlling a buzzer
LEDs are a great output device, but not much use if you’re looking in the other direction. The
solution: buzzers, which make a noise audible anywhere in the room. For this project you’ll
need a breadboard, male-to-female (M2F) jumper wires, and an active buzzer. If you don’t have
a breadboard, you can connect the buzzer using female-to-female (F2F) jumper wires instead.
An active buzzer can be treated exactly like an LED, in terms of circuitry and programming.
Repeat the circuit you made for the LED, but replace the LED with the active buzzer and leave
the resistor out, as the buzzer will need more current to work. Connect one leg of the buzzer to
the GPIO 15 pin (labelled GP15 in Figure 6-5) and the other to the ground pin (labelled GND in
the diagram) using your breadboard and male-to-female jumper wires.
If your buzzer has three legs, make sure the leg marked with a minus symbol (-) is
connected to the ground pin, and the leg marked with ‘S’ or ‘SIGNAL’ is connected to GPIO 15,
then connect the remaining leg – usually the middle leg – to the 3.3 V pin (labelled 3V3.)

+

_

+

_

a b c d e

f g h i j

3V3GP2GP3GP4GNDGP17GP27GP223V3GP10GP09GP11GNDDNCGP5GP6GP13GP19GP26GND

5V5VGNDGP14GP15GP18GNDGP23GP24GNDGP25GP8GP7DNCGNDGP12GNDGP16GP20GP21

5 Figure 6-5: Connecting a buzzer to the GPIO pins
Free download pdf