3

I want to make a circuit where I can control 2 LED's with one GPIO pin. But my question is if this would be possible and/or harm the Raspberry Pi because of the negative flow? Is there another way or should I just use 2 GPIO pins?

enter image description here

So what I want to do is write a HIGH and LED L2 will light up. When I write a LOW LED L1 will light up.

1
  • Take a look at Charlieplexing sometime. It's similar to what you are doing here but at a bigger scale.
    – krs013
    May 1, 2017 at 19:05

1 Answer 1

9

As shown this circuit cannot drive two LEDs the way you want it.

Consider

  • GPIO-pin high: L2 lights up, L1 does not.
  • GPIO-pin low: no LED lights up as there is no (significant) potential difference (aka voltage) between GND and the GPIO-pin, thus no current flows, no light.

There are however ways to do what you want. This tutorial (source of the figures shown below) has it outlined quite nicely. The circuit looks like this (see last paragraph on the missing current limiting resistor in these schematics, add resistor at your own discretion):

enter image description here enter image description here

Setting the GPIO to input turns off both LEDs. GPIO output, switching high/low turns on either one of them.

It is however noteworthy that it will only work if the sum of the forward voltages of the LEDs is higher than the supply voltage (tricks to work around that are in the linked page). Depending on the forward voltages and the supply voltage it is also possible that both LEDs will light up dimmly even if they're not supposed to be on. That is an unfortunate side effect of the strongly non-linear current-voltage characteristics of a LED. At voltages well below their rated forward voltage a small current is still flowing and thus a dim light can be observed.

It also requires the forward voltage of each LED to be less than the voltage level of GPIO high (i.e. it will likely not work with white LEDs).

It also relies on the fact that the current is limited by the GPIO pin itself (one may or may not choose to go with that assumption). If in doubt use a series resistor at the GPIO pin (see final figure, just skip the additional diodes if working with 3.3V at the Pi).

enter image description here

5
  • Thank you very much, The tutorial you linked is very helpfull.
    – xenorack
    May 1, 2017 at 15:03
  • You need a resistor in that circuit right?
    – Brick
    May 1, 2017 at 15:03
  • 3
    @Brick, I certainly would ;) but it's been demonstrated before that the current limiting provided by the GPIO pins make it somewhat safe to operate LEDs directly from it. Well, I still wouldn't.
    – Ghanima
    May 1, 2017 at 15:12
  • @Ghanima Thanks. I wasn't aware that you could count on the GPIO pins to limit this at all, so that's interesting in itself. At the same time, I've caused mine to "reboot" a few times by pulling too much current, so I like the resistor. Especially for the beginner.
    – Brick
    May 1, 2017 at 16:25
  • 2
    @brick, definitely - better safe than sorry.
    – Ghanima
    May 1, 2017 at 16:40

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.