# Drive a common anode bi color LED using single microcontroller pin

I have a bi color Red-Green LED with 3 legs (Common Anode).

How can I drive the LED using a single pin from microcontroller (ATtiny45) without using any external logic gates?

I only need red or green at a time mutually exclusive. Combined color/Off state not needed. They are just for status indicators and need to be as bright as possible.

Any schematic using discrete components would be helpful.

• This could be helpful: dangerousprototypes.com/blog/2011/10/24/… – Swanand Jan 2 '17 at 3:31
• Given that any solution using transistors (one or several) is probably going to take up more space than simply jumping to something like the ATTiny44 (6 extra pins), why not use the larger MCU? Alternatively, go for a bicolour 2-pin LED and use the solution @Swanand posted a link to. – Tom Carpenter Jan 2 '17 at 10:32

## 4 Answers

Given the Forward voltage differences between Red and Green LEDS allows for a very simple circuit and using your Common Anode configuration.

simulate this circuit – Schematic created using CircuitLab

You can set your LED current to any value you want, but there will always be a variation between Red - Green current that is unavoidable.

How well this works for you will depend on how the Red/Grn LEDs are built. For example with this Common Anode LED the difference between the Grn/Red VF is as shown below:

With this bi-color at any current below 30 mA through the Red LED, the Green LEED will be essentially off (uA). If you are using discrete LED's this will work for almost all devices. but note that some newer SMD bi-color LEDs use a mixed technology and the VF's are much closer together, for those devices this drive architecture may not work.

Update: after doing some tests with various LEDs, here's a way to handle diodes with no difference in Vf. In addition this can be used if you are using diode currents (typically <20 mA) that can be handled directly by a microprocessor pin.

simulate this circuit

• This won't work well. There will still be some conduction through the green LED - even a couple of mA is enough to produce a quite visible amount of light. – Tom Carpenter Jan 2 '17 at 10:24
• @TomCarpenter. Within in reasonable limits it works well. And since the LEDS are typically not separate (ie same visible channel) you see only a single color. – Jack Creasey Jan 2 '17 at 16:32

This breaks out of your parameters slightly, but I feel like it is by far the simplest solution.

If you use discrete LEDs, or LEDs with independently accessible anodes and cathodes, you can use this circuit:

simulate this circuit – Schematic created using CircuitLab

HI:          D1 On
LO:          D2 On
HiZ:         Off
Toggle fast: D1 & D2 on


Note: This will only work with a pair of LEDs whose Vf is greater than 3.3V! Even so, the LEDs may still very slightly glow all the time. You just need to evaluate this tradeoff and whether it's worth it for the low part count.

• Good one. OP should share the LED datasheet for evaluation. – Umar Jan 2 '17 at 4:06
• @Umar, they said "common anode" so their current device won't work for this. – The Photon Jan 2 '17 at 4:09
• But not a common anode bi-color pair. – Jack Creasey Jan 2 '17 at 4:12
• @ThePhoton Yes you are right too. The bicolor LEDs will mostly be common anode type or common cathode type, including the OP ones. Hence, above solution is for discrete LEDs for best – Umar Jan 2 '17 at 5:11
• LOL you beat me to this one. – Ryan Griggs Jan 3 '17 at 3:41

Wouldn't this simple circuit below work well for the required 2 color states only?

simulate this circuit – Schematic created using CircuitLab

ATtiny datasheet shows it can drive low 10 mA to 0.2V, so take advantage of that.

• Logic high = D2 turns on

• Logic low = D1 turns on

• Tristate the output = D1 is teeny tiny bit on, D2 is on

So pick the color for D2 which will be on whenever your processor is still in reset.

Also, if you want different LED currents then short Rlim and put different resistors on the LED cathodes.

For Q1, you can use a digital transistor (integrated resistors) or you can use an N-channel MOSFET without a gate resistor.

• Pstron. It works but you do have to be mindful of VCE(sat) for the BJT transistor....though this configuration would also work for an N-Channel FET and you would save a resistor – Jack Creasey Jan 3 '17 at 21:44

This is not the simplest solution, but if the other methods above don't work as expected, try the following, since the above ones (as I can see) seem to only work on certain conditions.

You can't use BJTs instead of MOSFETs in this circuit because the LED can go through the bases and they can be both unintentionally turned on at the same time.

If you don't have MOSFETs, use this circuit:

This circuit works by pulling the NPN down via the input tag to disable the green and at the same time powering the red. The diode is to prevent current going through the base and powering the red LED.