is it possible to add this speaker to Raspberry pi 3 via GPIO to get indicated by beep on error.

enter image description here

How should I plug it in where on GPIO ?

  • Try this connect the red wire to a GPIO pin and black to ground.then toggle the GPIO pin just like you would flash an LED. Sep 1, 2016 at 5:29

1 Answer 1


An expansion on Steve's comment on OP

This is the pinout of the Pi3's GPIO, it's oriented so that if you have the USB and ethernet ports at the bottom, the top right pin (5v, pin 02) will be at the top-right of the Pi.

Pi3 40-pin pinout

Choose a GPIO pin (one with GPIOnn in the name, green in the pinout) and connect the red wire to it, and then connect the black wire to any ground pin (marked in black on the pinout)

Then to make the speaker sound, here's an example in Python (unable to test so feel free to edit). For this example, the red wire is connected to pin# 11 (GPIO17)

import RPi.GPIO as GPIO #Import the GPIO library
import time #Used for waiting between beeps

speakerPin = 17 #Use GPIO numbers for Python, not pin numbers
GPIO.setup(speakerPin,GPIO.OUT) #Sets the speakerPin as an output pin
GPIO.output(speakerPin,GPIO.HIGH) #Turns the speaker ON
time.sleep(1) #waits a second
GPIO.output(18,GPIO.LOW) #Turns the speaker OFF

By using this (or equivalent in another language) wherever an error may occur in your program, you should achieve what you're looking for.

Hope this helps!

  • well if you look at image closely between red and black pins there are two wholes minding that i had to connect red one to GPIO21 i.e. pin 40 and pin 34 for black wire and using these values beeper didn't made a sound Sep 1, 2016 at 13:03
  • @Ciastopiekarz don't use the connector, stick hook-up wires from the connector into the GPIO pins
    – Luke Moll
    Sep 1, 2016 at 13:06
  • 1
    Do note that this will not play a sound. You'd have to rattle the GPIO on and off very quickly.
    – Distjubo
    Jan 14, 2017 at 16:27
  • 1
    Also note that you might not get a very smooth sound out of the Raspberry PIs GPIO pins if your system is under load. If you want really good quality sound, you need dedicated hardware or a realtime operating system.
    – Distjubo
    Jan 14, 2017 at 16:39
  • 3
    Also also note that you might want to add a resistor between the speaker and the GPIO, to prevent too much current flowing. Without a resistor, you might permanently damage the speaker and the raspberry pi.
    – Distjubo
    Jan 14, 2017 at 16:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.