0

I'm trying to wire my Raspbery Pi 1 Model A (hereafter RPi) to a simple 6VDC buzzer and here is my best attempt:

enter image description here

  • So the 3.3V power pin from the RPi is connected to the breadboard's top-most rail via a red jumper (note this isn't actually used by the rest of the circuit but I don't believe it harms anything, right?)
  • A GPIO output pin is connected to the breadboard via yellow jumper; which is then connected (same column) to the buzzer via the buzzer's red wire
  • The buzzer's black (GND) wire is then connected to the 2nd rail on the breadboard, which in turn is connected to the RPi's GND pin

To begin with, if anything about the circuit looks incorrect, please begin by correcting me! However I don't think I need anything else (resistors, capacitors, etc.) in order for this to work. When my software (running on the RPi) fires a signal to the buzzer via GPIO output pin, the buzzer will sound, etc.

The only thing I'm currently on the fence about is whether or not I need to set the internal pin resistance (so, pull up resistor vs. pull down resistor at the software layer)

My question: when does one need to set the internal pin resistance (pull up vs pull down) when working with IO devices such as buzzers, LEDs, switches, etc.? And why?! I happen to be using pi4j which uses wiringPi under the hood, but this question is more about knowing & understanding when to set pin resistors at the software layer.

  • Do not do that. I will have an explanation for you in a minute. – goldilocks Sep 20 '17 at 15:17
3

That is not so good.

So the 3.3V power pin from the RPi is connected to the breadboard's top-most rail via a red jumper (note this isn't actually used by the rest of the circuit but I don't believe it harms anything, right?

Correct, it is pointless that way.

When my software (running on the RPi) fires a signal to the buzzer via GPIO output pin, the buzzer will sound, etc.

Maybe. Also maybe you will fry the GPIO, since that buzzer looks a lot like this one, which "[carries] a maximum 45mA". The GPIOs (excluding power pins, which are not actually GPIOs) are rated at 15 mA. Although a lot of people will report doing okay at 20-25 mA, 45 is very likely too much.

You probably need a resistor to limit the current, at least initially -- the buzzer itself will have resistance as well. Realistically it looks a bit beefy to be controlled this way. You would be better off feeding it 5V toggled with a transistor.

pull up resistor vs. pull down resistor

You've misunderstood the purpose and circuitry of a pull-up/pull-down resistor. They aren't in line with the pin to protect it, they are in line with ground or a voltage source in order to prevent an input pin's value from floating in a high impedance state. Here's a pull-up circuit:

schematic

simulate this circuit – Schematic created using CircuitLab

Whatever the GPIO would be attached to would go bottom left. Notice that means the resistor is not in between it and whatever; it is between it and an internal 3.3V source. This is used to "pull-up" (i.e. to digital "high") when whatever it is attached to is in high impedance (i.e., connected neither to ground nor a voltage source). The purpose here is to keep the pin high until the whatever (say a button) pulls it to ground (i.e., digital "low") -- in which case you'd want a smaller resistor in line to prevent a short.

You are using the GPIO as an output, and need to protect against too much current draw. For 20 mA:

3.3 / 0.020 = 165 Ohms

A bit bigger would be wise, but no smaller.

However, this does not take into account the resistance of the buzzer itself, which may in fact be too much for this to work at all.

  • Thanks so much @goldilocks (+1) - I have a few questions regarding your statements about my buzzer wiring/setup. When you say "Realistically it looks a bit beefy to be controlled this way. You would be better off feeding it 5V toggled with a transistor." I'm not following you 100% here. Are you saying I need to use the 5V power pin, or are you saying that its a bit beefy/overkill to drive the buzzer from a GPIO pin and from the software? Thanks again! – smeeb Sep 21 '17 at 0:36
  • 1
    The other way around; the buzzer looks a bit beefy to attach to a GPIO. They aren't intended to power things, they're intended for signalling or sensing. – goldilocks Sep 21 '17 at 12:17
  • Thanks @goldilocks (+1 again) but have a look at Page 2 of this CanJam EduKit tutorial...the buzzer is wired directly to a GPIO pin. So is the buzzer in that tutorial really just that different from the one in my question? Or is the tutorial total nonsense and unsafe?! I guess I'm looking for the path of least resistance here (no pun intended): – smeeb Sep 21 '17 at 17:13
  • 1
    That's a smaller piezo; they are common and inexpensive. I think I've done that before...I'm not an expert on electronics, BTW, my answer was mostly to correct you about the pull-up, pull-downs. So looking around a bit, I think they do have resistance, and can be damaged by overcurrent (you won't do that with a GPIO to your large buzzer), and conversely could draw too much. Unless you can find someone who's used a buzzer like that on the pi w/o a resistor, I still think you should use a resistor. – goldilocks Sep 21 '17 at 18:18
  • 1
    Also, a buzzer and a piezo aren't necessarily the same thing. It may not work without more voltage; the thing I mentioned about using a transistor is you use the transistor as switch, controlled by the GPIO, to sink or source a separate power supply (e.g., the 5V rail on the pi) to the buzzer. – goldilocks Sep 21 '17 at 18:22
1

When a GPIO set as an input has no definite voltage attached it is said to be floating and will randomly return 0 or 1.

The purpose of the internal pull-ups and pull-downs is to stop a GPIO set as an input from floating by connecting to ground (pull-down) or 3V3 (pull-up). That means it will return a consistent result until overridden by such as a button press.

There is no point in setting a pull-up down or up on a GPIO set as an output (unless you are doing some esoteric electrical tests).

  • Thanks @joan (+1) that makes a lot of sense on understanding pin resistance (pull ups vs pull downs). What about my wiring of the buzzer itself though? Do you concur with what goldilocks is saying? Thanks again! – smeeb Sep 21 '17 at 0:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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