# How to control three LEDs with two uC pins using just passive components?

I only have 2 (3-state) pins available on a microcontroller and need to control 3 red LEDs, uC is running on 5V. I can only use passive components in addition.

-
Define "control". Do you need all of the LEDs fully illuminated at the same time, or just one at a time, or something else? Why do you say that you can only use passive components? –  Joe Hass Apr 10 at 15:53
Google "charlieplexing". –  John U Apr 10 at 16:43
@JohnU: Charlieplexing doesn't do anything useful with less than three pins. Two pins just gives you two LEDs. –  Dave Tweed Apr 10 at 16:44
Obviously, an I2C port expander or even some simple shift registers would allow you to control an arbitrary number of LEDs. Why are these ruled out? –  Dave Tweed Apr 10 at 16:46
@DaveTweed - The act of googling it is pretty likely to be informative though ;) –  John U Apr 10 at 16:59

To control four LEDs:

simulate this circuit – Schematic created using CircuitLab

To get both LEDs on a particular pin lit, toggle the pin at a few hundred Hz.

Note that this setup requires that the forward voltage of the LEDs be less than Vcc/2.

Note also that the resistors consume power all of the time, not just when the LEDs are on.

-
Having R1 connect only to D1 and R2 only to D2, etc. will greatly reduce quiescent current draw when the LED is off, provided that the LED voltage drops combine to VDD. –  supercat Apr 10 at 19:24
@supercat: Yes, but that's rarely true of the red LEDs that the OP specified. See Will's diagram. –  Dave Tweed Apr 10 at 19:40
Add an extra LED between the R1-D1 and D2-D2 nodes and hide it somewhere. –  supercat Apr 10 at 19:44
@supercat: See Spehro's answer. –  Dave Tweed Apr 10 at 19:48

This solution depends on the fact that 5V won't light the three LEDs in series. If necessary, you can add a silicon diode in series with one or more of the LEDs in order to increase the total forward voltage drop.

simulate this circuit – Schematic created using CircuitLab

• If both pin A and pin B are tristate, all LEDs are off.
• If pin A is driven low, D1 is on.
• If pin A is driven high and pin B is driven low D2 is on.
• if pin B is driven high, D3 is on.

To have more than one LED lit at a time, you'll have to multiplex: turn them on one at a time, rapidly enough so that they appear to be continuously lit.

-
Is there any advantage of this over Michael Karas's method? –  Will Apr 10 at 16:37
This one works with lower forward voltage drop on the LEDs. His solution is just two copies of the one-pin/two-LED version of this. –  Dave Tweed Apr 10 at 16:49
Ahh so with this if you have 2 resistors on you are dropping some voltage through 1 and some in the other, and having to burn less of in resistors? –  Will Apr 10 at 16:58
@Will: Um, no. With this scheme, only one LED is on at a time, and only one resistor at a time is dropping voltage. When both pins are tristate, no current flows at all, since it is blocked by the cumulative forward drop of the three LEDs in series. –  Dave Tweed Apr 10 at 17:02
If you tristate pin b you can drive 2 LEDs with your scheme, right? –  Will Apr 10 at 17:06

With two pins you can actually control four LEDs. To control two LEDs put a resistor from the MCU pin to limit the current and tie it to two LEDs - the cathode of one LED and the anode of the other LED. The free anode end of the first LED gets connected to the VCC of the MCU board through another resistor. The free cathode end of the second LED gets connected to GND (through another resistor). Now the LEDs will light alternately when the MCU pin is set high or low. Wire up the second MCU pin the same way and you now have control over a total of four LEDs.

To give the appearance of independent control of the each LED in the pair off the one of the port pins requires a little software work as follow.

If LED1 is the one with the anode to the port pin and LED2 is the one with the cathode to the port pin then do the following to establish the four states for two LEDs.

LED2  LED1    Action
OFF   OFF     Set the port pin to tristate level.
OFF   ON      Set the port pin low.
ON    OFF     Set the port pin high.
ON    ON      Toggle the port pin high and low at a frequency over about 120 Hz.


Repeat the same actions for the other port pin and you will be looking like you have four independent LEDs off two port pins.

This scheme works well for LEDs that have a forward voltage drop that is over half the VCC level. Red LEDs with a 2.1 VF will not work so great if the VCC is 5V for example. On a otherhand a green LED with a 2.5V VF will work great on a system with a VCC of 3.3V.

-
Is this total control, though? How do you turn them all on or all off? –  Stacey Anne Apr 10 at 15:35
One LED is on when current is flowing out of the pin, the other LED is on when current is flowing into the pin. So turn them both off you just tri-state the port pin, no current will come in or out of it, so no LEDs. Current can't flow in and out at the same time so you can not have both LEDs on at exactly the same moment. But you can create the effect of them both being on by driving the pin high then low then high then low then high then low etc –  Will Apr 10 at 16:33

So like this no current flows when they are off, and you can drive as much/little forward voltage as you need to

-
This is the same as Michael Karas' solution. It requires that the V_f of the LEDs be greater than Vcc/2, or else you can't turn them off completely. –  Dave Tweed Apr 10 at 17:20
+1 for taking the effort to present Michael Karas' solution copying Dave Tweed's CircuitLabs schematics and drawing free hand lines in it with MS Paint (or the like). –  Ricardo Apr 10 at 17:32
And it was in paint :) –  Will Apr 10 at 20:01
Ah I see what you're talking about now Dave. Current goes r1 d1 d2 r2 and nothing has to go in / our of the pin –  Will Apr 10 at 20:05

EDN published some related Ideas for Design here

Here's one of them:-

For typical values with D1 a yellow LED (2.2V on), D2 a red LED (1.9V on), and off voltages of 1.2V and 1.1V respectively, and on-currents of 8mA each, Vcc = 5.0V, the optimum values are

R1 = 300 ohms R2 = 330 ohms R3 = 1.2K ohms

Quiescent current is 2.7mA. To have both LEDs appear to be illuminated, toggle the output pin at 100Hz or greater.

I used the Excel solver in the original article, the code may be still available from EDN.

The additional degree of freedom afforded by the resistor R3 can avoid the limitations of both Dave Tweed and Michael Karas' circuits, though for the specific case of 2 red LEDs operating from a 5V supply, Dave Tweed's circuit is probably acceptable, but check the Vf carefully, it's not fine for some red LEDs, and may be marginal for others if the port pin doesn't pull all the way down or up.

-
Note: OP is asking for an all passive circuit. Also, if the MCU pin is high-Z, the inverter is forced into a linear mode of operation, which is generally going to waste power. –  Dave Tweed Apr 10 at 18:13
@DaveTweed Yes, my original posting specified a ST inverter, so I've edited to make that clear. It's not all passive, but it's simple and zero Iq. The second circuit is higher Iq but all-passive. Thanks for the comments. –  Spehro Pefhany Apr 10 at 18:20
I don't see how a Schmitt Trigger input helps; instead, I would think that it would force the circuit to oscillate. Granted, the LEDs will be off, but the inverter itself will consume significant power. –  Dave Tweed Apr 10 at 18:29
Well, since it doesn't meet the original requirement of no active parts, I'll delete it, but I believe it works okay. –  Spehro Pefhany Apr 10 at 18:31
+1 for R3, could be a useful trick. And a cheap one at that –  Will Apr 11 at 8:13