# DUO LED controlled by one MCU pin

I'm having trouble controlling red/green LED. I need to control it from my MCU with one pin. The pin can pull-up or pull-down and the LEDs can be with common cathode or anode. I'm flexible on that.

I tried to do with two NPN transistors but I can only get LED1 to be ON or both LED1 and LED2 to be ON. I think I should be using one NPN and one PNP transistor but I cant figure it out at this point. Should I use bipolar LED? When should bipolar LED be used and when duo led?

• Do you want to only switch between Red and Green or do you also need to be able to turn both LEDs off? – Dwayne Reid Mar 13 '16 at 23:21
• @Antonio The link doesn't show any circuitry. If you wan to post a schematic, post it as an image. Or, use CircuitLab (our built-in schematic editor). – Nick Alexeev Mar 13 '16 at 23:36
• @DwayneReid just Red and Green – CodeBreaker Mar 13 '16 at 23:49
• @NickAlexeev the link is just to show what type of LED I'm working with.. – CodeBreaker Mar 13 '16 at 23:51
• @Antonio I'm unable to see the contents of the link. Please post an image, or a link to the LED's datasheet. – Nick Alexeev Mar 14 '16 at 0:01

Here is a simple method:

simulate this circuit – Schematic created using CircuitLab

This shows a bipolar and a common-cathode LED. Common anode would be similar. You can use a single gate inverter for the inverter. The only limitation is that you must not load the microcontroller output so heavily that the output no longer presents a valid logic level to the inverter.

If you need really high current from a wimpy microcontroller output you can use a PNP and NPN like this (D1 should be the red one):

simulate this circuit

Provided that the sum of the LED threshold voltages is above the microcontroller supply voltage, you can simply place the LEDs in series and connect the microcontroller IO pin to the "middle".

You should add a current limiting resistor between the pin and the LEDs as well, of a value sufficient to limit the current below the maximum allowable for the LEDs and IO pin. 100 ohms should be a safe bet on 3.3 V.

With this arrangement, it is possible to turn one led on by driving the pin high, the other led on by driving the pin low, and both off by tri-stating the pin.

simulate this circuit – Schematic created using CircuitLab

Figure 1 and 2. Two LEDs - one GPIO.

For an efficient version I'm afraid you're going to need a couple of additional components as shown in Figure 1. R3 and Q1 invert the logic of the GPIO pin.

Figure 2 shows a simple option that may need little tweaking. R4 and R5 are biased towards half supply. Pulling the GPIO high or low will turn on one of the LEDs. The added advantage with this circuit is that both can be turned off (or flashed) by turning to GPIO to high impedance state. This arrangement is wasteful in that R4 and R5 will pass current whether the LEDs are on or not. It will probably only work well on a 5 V system and not on a 3.3 V system.

Table 1. LED control table.

GPIO         Result
Low          RED
High         GREEN
Oscillating  ORANGE
Hi-Z         OFF