One switch or GPIO / multiple LEDs

1 GPIO, 2 LEDs

One GPIO - two LEDs.
Figure 1. One GPIO pin can drive two LEDs.

A single GPIO1 pin can be used to light two LEDs.

How it works

  • When the output is switched low current will flow from the positive supply via R1 and the L1, green, to the output pin. L1 will illuminate. L2, red, will be shorted out and will be dark.
  • When the output is switched high current will flow from the pin through R2 and L2. The red LED will illuminate and the green will be dark.
  • If the output is tri-stated (wired as an input or disconnected by program control) a current will flow through R1, L1, R2, L2 and both LEDs will glow dimly. On a 3.3 V device the voltage wouldn’t be high enough to illuminate both LEDs significantly so they would appear dark.
  • By rapidly (> 25 Hz should be enough) alternately switching the output high and low while varying the duty-cycle the red and green can be blended to give any colour in between the two.
SunLED red-green LED.
Figure 2. A SunLED green-red integrated LED package with independent pinouts. See datasheet.
Figure 3. RGB LEDs are available in 6-pin versions without common cathodes or anodes. e.g., Kingbright LED LF79WAEMBGMBW, 8 mm, RGB, 20–30 mcd.

Note that to incorporate the 6-pin LED of Figure 3 into the circuit of Figure 1 you would control two of the three LEDs but leave the third unconnected, driven permanently or from another GPIO.


1 GPIO - 2 opto-isolators.
Figure 4. 1 GPIO – 2 opto-isolators.

The same trick can be used to switch isolated or non-isolated loads using opto-isolators. When the GPIO is high U2 will be turned on. When low, U1 will be turned on.

1 switch, 2 LEDs

1 switch or GPIO and 2 LEDs.
Figure 5. 1 switch or GPIO and 2 LEDs.

In (a) above the green LED is normally lit. There will be about 2.1 V across the LED.

When S1 is closed the red LED will turn on but since it’s forward voltage drop is only about 1.75 V the current in the green will drop very low. A look at the load-line graph shows us why.

Load-line for red and green LEDs in parallel.
Figure 6. Load-line for red and green LEDs in parallel shows that the red drops the voltage enough that little current passes through the green LED.

When the red LED is in circuit the LED voltage drops to 1.75 V or so. At this voltage the green only passes a couple of mA and will be off or dim.

If you want the circuit to operate the other way around as in Figure 5b then you need to induce further voltage drop. D1 achieves this. Now the combination of D1 and L3 will drop about 0.7 + 1.75 = 2.45 V. When the green is switched on there won’t be enough forward voltage to light the red (brightly).

The diode can be added to Figure 1a to reduce current further if the reduced current proves to be too bright.

The circuit will work with a GPIO output as shown in Figure 5c. In this case the additional diode, D2, will almost certainly be required as the GPIO will not reach +5 V when under load.


Please link to us if you find the information helpful ...<br>Tweet about this on Twitter
Twitter
Share on Facebook
Facebook
Pin on Pinterest
Pinterest
Digg this
Digg
Share on LinkedIn
Linkedin
Share on Reddit
Reddit
Share on StumbleUpon
StumbleUpon
Share on Tumblr
Tumblr
  1. GPIO = general purpose input/output. Most micros allow user configuration of the pins as either input or output or tri-state (disconnected).