9
\$\begingroup\$

Is it possible to control a bicolor LED with just one pin of a microcontroller?

Instinct says NO, because you can have one end grounded and the other going to the micro's pin, allowing you to turn it on or off but not change its color.

But maybe someone has a better idea?

\$\endgroup\$
1
  • 1
    \$\begingroup\$ You can do just about anything with one pin of a micro. More specific please? \$\endgroup\$
    – Nick T
    Nov 16, 2010 at 3:16

3 Answers 3

6
\$\begingroup\$

You can do this with a bi-color LED that has the two LEDs back-to-back if you connect one LED terminal to an intermediate voltage eg 2.5V on a 5V design and connect the other side to the MCU via a suitable resistor (I used 560R).

Then a low output gives one colour, high gives the other and tri-state leaves the LED off. Pulse width modulation will allow you to control brightness (switching output between active and tri-state) or mix the colours (switching output low to high).

You can adjust the intermediate voltage to compensate for different LED forward voltages too.

I used an LM2904 op-amp to provide the intermediate voltage - it works with supply voltage down to 5V. There are plenty of other devices that can operate at lower voltages and still sink and source enough current to drive the LEDs.

\$\endgroup\$
3
\$\begingroup\$

If you didn't need an off state, and your Voh was sufficiently large (edit: to overcome the forward bias voltage of the LED), you might be able to hook one end of the LED to a mid-rail voltage. Outputting a 1 gets one color, outputting a 0 gets the other color. To turn it off...ha, good luck. Maybe you could try putting a capacitor in there, and then driving the output with a PWM that the cap would smooth out to mid-rail?

\$\endgroup\$
11
  • 7
    \$\begingroup\$ I was thinking pretty much the same thing, perhaps the off state could be achieved by tristating the output pin of the micro. \$\endgroup\$
    – tcrosley
    Nov 15, 2010 at 23:32
  • 1
    \$\begingroup\$ An awesome suggestion...tri-stating the pin should turn it off without the fancy PWM. However, you must be careful about letting the input float, probably need a pull down (NOT divider, don't let the input pin see mid-rail voltages!) \$\endgroup\$
    – ajs410
    Nov 15, 2010 at 23:40
  • 1
    \$\begingroup\$ You could use a high-value (470k) resistor pulled high or low. The LED will be biased or one colour or the other, but the current flow will be so low that you won't see the LED as on. \$\endgroup\$
    – akohlsmith
    Nov 16, 2010 at 3:02
  • 5
    \$\begingroup\$ @ajs410 - I think MCUs are much more intelligently designed than a dumb logic chip. On your average 8-bit micro, the vast majority of the pins can be used as analog inputs (without explicitly configuring them as such) so there should be no ill effect (gate oscillation, excessive current draw) so long as the voltage remains within GND and VDD. \$\endgroup\$
    – Nick T
    Nov 16, 2010 at 3:20
  • 2
    \$\begingroup\$ One of the (possibly significant) downsides of this topology is that you will always have a fairly significant current draw which will (without modification) nix it for any long-term battery powered applications. \$\endgroup\$
    – Nick T
    Nov 16, 2010 at 15:32
1
\$\begingroup\$

You can Charlieplex it

\$\endgroup\$
4
  • 3
    \$\begingroup\$ but that requires a minimum of two pins. OP asked for a solution using one pin. \$\endgroup\$
    – tcrosley
    Nov 16, 2010 at 21:06
  • \$\begingroup\$ Actually, it's possible in some cases to extend Charlieplexing to provide N*(N+1) LEDs with N pins, if the supply voltage is less than twice the LED voltage drop, and one has the right combination of LED voltage drops available. Let's assume for simplicity that the goal is to control 12 LEDs with three pins; six LEDs have a 2.5 volt drop, and six have a 1.7-volt drop, and supply voltage is 3.0 volts. Goal is 5mA for the 2.5 volt diodes and 6.5mA for the 1.7-volt diodes. Put a 100ohm resistor in series with each output. Three of the 2.5-volt LEDs connect the outputs to VDD, three to VSS... \$\endgroup\$
    – supercat
    Mar 8, 2011 at 16:23
  • \$\begingroup\$ ...and the 1.7-volt LEDs connect the outputs to each other in "normal" Charlieplex form. To turn on a 1.7-volt LED, drive one output high and one low. The resistors will drop 0.65 volts, leaving 1.7 volts for the LED, and insufficient voltage for the 2.5-volt LED. To turn on a 2.5-volt led, drive one output high or low and none of the others at all. Then a 2.5-volt LED will have enough current to light. \$\endgroup\$
    – supercat
    Mar 8, 2011 at 16:26
  • \$\begingroup\$ One could add more resistors or silicon diodes to deal with different voltage scenarios if necessary, but that would add some complexity. @tcrosley: The above generalizes to using one pin to control two LED's. \$\endgroup\$
    – supercat
    Mar 8, 2011 at 16:28

Your Answer

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

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