Driving a bi-color LED from one MCU pin

Thread Starter

ilium007

Joined Aug 24, 2013
139
I have been looking for a solution for this for hours and have posted on the Arduino forums but posting here also in the hope I can get some different views on the topic.

I don't want to use addressable LED's as I'm trying to learn more about analogue electronics via this project and not just hacking something together 'maker style'.

I have to drive about 60 red/green LED's (34 in the first round of the project) and the ones I can get here in Australia are the two lead inverse parallel bi-color (actually called bi-colour over here :D ) type.

I have seen a stack of responses for this problem stating I should use a NPN transistor and a voltage divider circuit, but in all of these I can see the drive voltage being shunted to ground through the the voltage divider when one of the LED's is off (ie. all of the time) and this seems like a waste of power to me.

I found an article written some time back that proposes this circuit and would like to give it a go as it has very little quiescent current drain.

Can anyone please shed some light on how this works and maybe propose some components (I can't source the BSS101 or BAS15 here in Australia) that I can use to prototype this.


Using discrete components, another circuit offers an inexpensive approach that avoids the other circuits' disadvantages (Figure 3). When the microcontroller's output port goes high, current flows through the green (upper) LED, R2, D2, and FET Q2, which the port's high level turns on. When the microcontroller's output port goes low, transistor Q1 turns on and delivers current to the port pin through R2 and the red (lower) LED. The circuit operates symmetrically because silicon diode D2's forward-voltage drop is present regardless of whether the microcontroller's port pin goes high or low. VCC may vary during operation but must remain higher than 3V.
You can individually adjust the LEDs' currents to equalize brightness or compensate for a difference between the microcontroller's power-supply voltage and the LED-driver circuit's VCC. Replace R2 with two resistors connected in series between Q1's emitter and D2's anode. Connect the midpoint of the two resistors to the LEDs.
With the microcontroller's port pin configured as an "input with pullup," the port delivers a small current to the green LED. However, pullup-resistor values of 22 kΩ or higher do not cause misleading light output from LEDs in the off-state. When the input signal from the port pin floats--that is, with VCC at 5V and the port configured as an input with no pullup resistor--the circuit draws no additional current, and the quiescent current, which R1 determines, averages less than 100 µA.
 

dendad

Joined Feb 20, 2016
4,476
Do you want to drive them fast (PWM) or just switch then on and off?
There are a few ways of doing this.
The above circuit may work, (I wont be figuring it out) but only for one LED as the port pin is driving the LED and has very limited current capability.
What is your supply voltage going to be?
 

Thread Starter

ilium007

Joined Aug 24, 2013
139
I only want red/green on or off ie. one LED will always be on. If I drive the pin high I get green, low I get red.

The pin will either be an output off a shift register or an MCP23S17 SPI I/O expander IC.

Supply voltage will be 5v.
 

Thread Starter

ilium007

Joined Aug 24, 2013
139
Thats the same circuit (from that same website!!) that comes up all the time as I research this. Looking at it there will always be current being sunk to GND from VCC via that voltage divider, surely this just generates heat and is wasteful.

The LED datasheet I am looking at gives a 2v forward drop on one colour and 2.2v on the other. At 5v that gives (at 15mA) an R1and R2 of about 220ohms. This means 440ohms from Vcc to GND which is 11mA draining to GND via that voltage divider doesn't it ?
 

dendad

Joined Feb 20, 2016
4,476
Are you going to have one port pin driving all 60 LEDs, or 60 port pins? I was drawing out an idea for only on pin for them all but it is sounding like you will be using multiple port pins.
 

Thread Starter

ilium007

Joined Aug 24, 2013
139
I would be like one pin per red/green LED pair. I am still trying to work out if it will be via a shift register or an I/O expander (MCP23S17) either one wont support all pins sinking / sourcing 20mA each for LED's so I need some type of transistor / small MOSFET (such as the 2n7000) to handle the LED load.

But yes, 60 pins for 60 red/green LEDs.

In case it is of interest, this is for a train layout controller for my Dad. Each set of points will be driven by a solenoid actuator and have the red/green feedback LED's on a control panel. This is the first stage - there are another 30 sets of points to go into a siding / shunting yard !

 

dendad

Joined Feb 20, 2016
4,476
One way to easily get the 3 states, Red, Green and Off from one pin is to use 4 "LEDs" in series like so...
PinDrive.jpg
The 4 LEDs (2 are LEDs in optos) have a higher than 5V drop so when the pin is open (input) no LEDs are on.
High will turn on Opto2, and Low Opto1.
You can use the opto outputs to drive whatever you like.
You could even use 4 optos so have an H bridge made up of the opto transistors.

(I've used the 4 LEDs in series as Christmas lights for years. A HEX Schmitt trigger IC running 6 oscillators then runs 24 LEDs.)
 

Thread Starter

ilium007

Joined Aug 24, 2013
139
So one thing I read about whilst researching this is that having a way to adjust current for each LED is a good idea as the different colours have different forward voltages. Given that this is on a control board I don't want the green LED's being dimmer than the red ones.

It looks to me like the circuit above would source / sink via the 220 ohm resistor which will mean one of the leds will be dimmer (maybe).
 

dendad

Joined Feb 20, 2016
4,476
So one thing I read about whilst researching this is that having a way to adjust current for each LED is a good idea as the different colours have different forward voltages. Given that this is on a control board I don't want the green LED's being dimmer than the red ones.

It looks to me like the circuit above would source / sink via the 220 ohm resistor which will mean one of the leds will be dimmer (maybe).
Easy fix.
Remove the 220R and add separate Rs from the bottom optos Emitters to GND.
 

dendad

Joined Feb 20, 2016
4,476

Thread Starter

ilium007

Joined Aug 24, 2013
139
Yes - I'm trying to decide between the MCP23S17 and the TPIC6B595 (for outputs) / 74HC165 (for inputs) which I can drive via SPI.

The MCP23S17 can't drive all 16 outputs with LED's at 20mA at once, the TPIC6B595 can. So if I went with the MCP23S17 I would have to use a small MOSFET such as the 2N7000 on the current sinks to be able to run the LED's but then I immediately limit what the board can do. I have to choose between inputs and outputs. I am designing SMD PCB's for this project so maybe I could just build 16 channel input boards and 16 channel output boards both based around the MCP23S17 and make them 'stackable'. I don't know enough yet about SPI to understand what I need to do to expand / terminate the signals when connecting multiple IC's.

Its just these LED's that are driving me spare.
 

Thread Starter

ilium007

Joined Aug 24, 2013
139
I could just build enough boards to get double the outputs and then find three lead red/green LED's and use two pins per LED. Would be easier than trying to get the 2 lead ones working but wastes a lot of I/O.
 
Top