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.

  • \$\begingroup\$ 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? \$\endgroup\$ – Joe Hass Apr 10 '14 at 15:53
  • \$\begingroup\$ Google "charlieplexing". \$\endgroup\$ – John U Apr 10 '14 at 16:43
  • 1
    \$\begingroup\$ @JohnU: Charlieplexing doesn't do anything useful with less than three pins. Two pins just gives you two LEDs. \$\endgroup\$ – Dave Tweed Apr 10 '14 at 16:44
  • \$\begingroup\$ 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? \$\endgroup\$ – Dave Tweed Apr 10 '14 at 16:46
  • 1
    \$\begingroup\$ @DaveTweed - The act of googling it is pretty likely to be informative though ;) \$\endgroup\$ – John U Apr 10 '14 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.

| improve this answer | |
  • \$\begingroup\$ 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. \$\endgroup\$ – supercat Apr 10 '14 at 19:24
  • \$\begingroup\$ @supercat: Yes, but that's rarely true of the red LEDs that the OP specified. See Will's diagram. \$\endgroup\$ – Dave Tweed Apr 10 '14 at 19:40
  • \$\begingroup\$ Add an extra LED between the R1-D1 and D2-D2 nodes and hide it somewhere. \$\endgroup\$ – supercat Apr 10 '14 at 19:44
  • \$\begingroup\$ @supercat: See Spehro's answer. \$\endgroup\$ – Dave Tweed Apr 10 '14 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.

| improve this answer | |
  • \$\begingroup\$ Is there any advantage of this over Michael Karas's method? \$\endgroup\$ – Will Apr 10 '14 at 16:37
  • \$\begingroup\$ 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. \$\endgroup\$ – Dave Tweed Apr 10 '14 at 16:49
  • \$\begingroup\$ 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? \$\endgroup\$ – Will Apr 10 '14 at 16:58
  • 1
    \$\begingroup\$ @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. \$\endgroup\$ – Dave Tweed Apr 10 '14 at 17:02
  • \$\begingroup\$ If you tristate pin b you can drive 2 LEDs with your scheme, right? \$\endgroup\$ – Will Apr 10 '14 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.

| improve this answer | |
  • 3
    \$\begingroup\$ Is this total control, though? How do you turn them all on or all off? \$\endgroup\$ – stanri Apr 10 '14 at 15:35
  • \$\begingroup\$ 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 \$\endgroup\$ – Will Apr 10 '14 at 16:33

2 leds one pin, badly drawn

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

| improve this answer | |
  • \$\begingroup\$ 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. \$\endgroup\$ – Dave Tweed Apr 10 '14 at 17:20
  • \$\begingroup\$ +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). \$\endgroup\$ – Ricardo Apr 10 '14 at 17:32
  • \$\begingroup\$ And it was in paint :) \$\endgroup\$ – Will Apr 10 '14 at 20:01
  • 1
    \$\begingroup\$ 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 \$\endgroup\$ – Will Apr 10 '14 at 20:05

EDN published some related Ideas for Design here

Here's one of them:-

enter image description here

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.

| improve this answer | |
  • \$\begingroup\$ 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. \$\endgroup\$ – Dave Tweed Apr 10 '14 at 18:13
  • \$\begingroup\$ @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. \$\endgroup\$ – Spehro Pefhany Apr 10 '14 at 18:20
  • \$\begingroup\$ 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. \$\endgroup\$ – Dave Tweed Apr 10 '14 at 18:29
  • \$\begingroup\$ Well, since it doesn't meet the original requirement of no active parts, I'll delete it, but I believe it works okay. \$\endgroup\$ – Spehro Pefhany Apr 10 '14 at 18:31
  • \$\begingroup\$ +1 for R3, could be a useful trick. And a cheap one at that \$\endgroup\$ – Will Apr 11 '14 at 8:13

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.