2
\$\begingroup\$

I think I understand the Raspbery Pi GPIO pins and most of how this diagram below works, at a high level at least.

First question, it's not clear to me exactly how the middle part with the resistors and transistors works. Can anyone help explain how this works in another way? This is essentially flipping the high/low logic from the GPIO pins so a low output from the pi is non-zero voltage to the relay input?

source

https://docs.google.com/file/d/0B5-HND9HJkXWSTQtYlFTZ3VyODA/edit

another reference for the middle section

To power the LED's on the other end of the relay, I have a wall AC adapter to 28VDC, .9A that will power a 700 mA driver. The driver will connect each of the relay terminals to the LEDs. I will only need one led/relay active at a time.

My second question, if I run 8 wires from the relay terminals to power each LED, can I connect them all to the same wire for ground to return? I'd like to have some sort of quick disconnect for the LEDs so they can be easily unplugged, can you have multiple quick connect terminals spliced into a shared ground or is that a bad idea? Any recommendations for quick disconnecting plugs?

Still pretty new to all of this so I feel like I could very easily miss anything from "common sense" and "good practice" to "just completely wrong".

Here's the LEDs I was planning to use in a series to justify the 700mA current.

\$\endgroup\$

1 Answer 1

4
\$\begingroup\$

I admit the explanation about the transistor is a little misleading. I wouldn't have chosen to use the term "active low" in this scenario because you have direct control of the GPIO pin, not direct control of the relay. The GPIO pin is active high. All they're saying is you need to turn on the transistor so it can provide a path to ground for the relay's coil. And to do so, you need to drive the GPIO pin high.

Here's what the full circuit probably looks like for each GPIO/relay pair:

schematic

simulate this circuit – Schematic created using CircuitLab

When the GPIO of the RPi is driven high (in your code), the 2N222 NPN transistor is turned on. That allows current to flow from the 5V source, through the relay coil, through the transistor, and into ground, which will activate the relay. The author's description of "active low" is actually referring to the spot I marked "V1" in the circuit. When the voltage at that node is low (when the transistor is on or if you just touch a ground wire there), current will flow and the relay will activate. I think she explained it that way because that point in the circuit is physically manifested as a pin you can connect to.

R1 is a current-limiter resistor. It prevents too much current from being sourced from the GPIO pin and into the transistor's base. R2 is a pull-down resistor. It forces the base of the transistor low (and thus the transistor off) if the GPIO pin is physically disconnected or high impedance (tri-stated). When the GPIO pin is attached, R2 can be ignored. There is no signal flipping going on.

If you wire up your LEDs and current source like so, you can connect them all to the same ground wire:

schematic

simulate this circuit

I'm assuming you've got a handle on how much current these LEDs need. If you're not sure about hooking up your LEDs to a 700mA constant current source, please do more research first (or sit back and enjoy the fireworks). At no time should all of the LEDs be off - unless the current source has been safely disabled.

This circuit will work as long as you do as you said and only have one LED on at a time. If you do activate more than one at a time, the current will divide between them. And since LEDs have a negative temperature coefficient, one LED will tend to dominate the current and look brighter than the others.

\$\endgroup\$
7
  • \$\begingroup\$ From experience, those relay boards are 5V, with optocouplers between the input and the relays, active low. The transistors are also being used as level shifters from the pi's 3.3V logic level. \$\endgroup\$
    – Passerby
    Sep 23, 2014 at 12:08
  • \$\begingroup\$ Hey Dan, Great answer, but maybe include a small warning that not all current sources "enjoy" not being connected at all. It may in fact be better to turn the next LED on before turning the last off, so for a few ms they share the current for safety. Depending on the design quality of the current source of course. \$\endgroup\$
    – Asmyldof
    Sep 23, 2014 at 14:36
  • 1
    \$\begingroup\$ @g3cko, a constant current source will vary its voltage to maintain a desired current. If the current drops, it'll increase its voltage to bring the current back up. Now imagine what will happen if the current drops to zero (open circuit). Depending on how well made the current source is, it'll either just shut off (best design) or spike its voltage trying to increase the current until it fries itself and starts a fire (bad design). Only way to know what it actually will do is to consult the datasheet and/or manufacturer. \$\endgroup\$
    – Dan Laks
    Oct 19, 2014 at 2:57
  • 1
    \$\begingroup\$ @DanLaks Thanks for that explanation. Is there a specific term or keyword to look for? I'll give the datasheet a more thorough read through and maybe contact the manufacturer. \$\endgroup\$
    – g3cko
    Oct 19, 2014 at 3:20
  • 1
    \$\begingroup\$ @g3cko, it says on the website you linked in your original question "Continuous output open circuit protection". I would interpret that to mean it gracefully handles a zero-load situation. I'd still talk to the manufacturer to confirm exactly what its behavior will be. \$\endgroup\$
    – Dan Laks
    Oct 19, 2014 at 3:44

Your Answer

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

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