Red or green LED, with one GPIO on MCU?

Thread Starter

nardev

Joined Feb 26, 2018
26
It must be something pretty simple to do but i'm bit confused how.

I have green and red LED and i want the red one be turned on while GPIO is LOW and green turned on when i put GPIO HIGH.

What circuit should i make? : )
 

crutschow

Joined Mar 14, 2008
25,269
So much missing information. :rolleyes:
What is the GPIO output voltage and current capability?
What is your supply voltage?
What do you want for LED currents?

Likely a transistor or two would do what you want.
 

danadak

Joined Mar 10, 2018
4,057
The problem with this is typically high state, which should turn off L1, will
have enough V across it to "leak" some current thru it., Todays high bright
LEDs under this condition can potentially glow with this small current. If that
is not a problem then circuit is fine.

Look at processor datasheet, modern processors have ~ symmetrical drive
to either rail. Older species not so, typically high drive << low drive. So if you
want equal brightness out of each led then adjust individual Rs appropriately.
Note even with symmetrical drive you still have to adjust currents to get equal
brightness because of LED Vf is different for different color LEDs. And there will still
be brightness variation due to LED to LED variation.

Regards, Dana.
 

MrChips

Joined Oct 2, 2009
21,674
There is a third state. If you configure the GPIO as input, both LEDs will be turned on.
You can use a single red/green LED which would give you yellow (with some additional components or extra GPIO).
 

ApacheKid

Joined Jan 12, 2015
157
It must be something pretty simple to do but i'm bit confused how.

I have green and red LED and i want the red one be turned on while GPIO is LOW and green turned on when i put GPIO HIGH.

What circuit should i make? : )
Can you not simply drive one of the LEDs from an inverter? That will ensure one of the LEDs is always on.
 
Last edited:

John P

Joined Oct 14, 2008
1,821
This is how I've done it. It allows the LEDs to show red or green or be off, and if you use the right kind of component, with 2 LEDs in a 2-pin package, it can show a plausible yellow if you feed it a.c. I acknowledge that it draws power in every state, and more than an LED typically needs. You can improve this by replacing the resistors with an op-amp output set up as a 2.5V buffer, and then use a single 33 Ohm resistor in series with the LEDs. If you have many LEDs to drive the same way, add a transistor pair between the op-amp and the LEDs.
bicolor.jpg
 

Analog Ground

Joined Apr 24, 2019
416
This is how I've done it. It allows the LEDs to show red or green or be off, and if you use the right kind of component, with 2 LEDs in a 2-pin package, it can show a plausible yellow if you feed it a.c. I acknowledge that it draws power in every state, and more than an LED typically needs. You can improve this by replacing the resistors with an op-amp output set up as a 2.5V buffer, and then use a single 33 Ohm resistor in series with the LEDs. If you have many LEDs to drive the same way, add a transistor pair between the op-amp and the LEDs.
View attachment 196124
Here is an idea to reduce the quiescent current with LEDs off. Takes advantage of the required voltage drop across the LEDs for conduction. The 150 ohm can probably be larger but it shows the concept.DualLEDsOnePin.jpg
 

ApacheKid

Joined Jan 12, 2015
157
This is how I've done it. It allows the LEDs to show red or green or be off, and if you use the right kind of component, with 2 LEDs in a 2-pin package, it can show a plausible yellow if you feed it a.c. I acknowledge that it draws power in every state, and more than an LED typically needs. You can improve this by replacing the resistors with an op-amp output set up as a 2.5V buffer, and then use a single 33 Ohm resistor in series with the LEDs. If you have many LEDs to drive the same way, add a transistor pair between the op-amp and the LEDs.
View attachment 196124
That may work but consumes a minimum of 20 mA even if the driving pin goes high impedance...
 

John P

Joined Oct 14, 2008
1,821
I did say that it's a power hog! But I also said that if that's a problem, you can put in an op-amp as a buffer generating 2.5v (a pseudo-ground, if you want to think of it that way) and run the LEDs with a single smaller resistor in series. Boost the current drive with a couple of transistors if necessary, i.e. if you have a whole lot of the LEDs to drive.

Analog Ground, that looks good, but the circuit was originally designed to use bipolar LEDs, where you wouldn't have access to the two LEDs separately. In that application, it was also a great advantage to have one lead of each component be at the same voltage. In that case, the two-resistor design won't work anyway.
 

Analog Ground

Joined Apr 24, 2019
416
That may work but consumes a minimum of 20 mA even if the driving pin goes high impedance...
The quiescent current with both LEDs off is not the problem. This current is less than the designed LED current. So, this current does not increase the requirements on the power supply. The issue is the added current when one of the LEDs is on. This is the voltage drop of the LED divided by 120 ohms. The resistor shunts the LED voltage. This shunt current added to the LED current determines the max load on the power supply.
 

Analog Ground

Joined Apr 24, 2019
416
In that application, it was also a great advantage to have one lead of each component be at the same voltage. In that case, the two-resistor design won't work anyway.
I don't understand your point here which is probably a good one. Could you explain it more?
 

John P

Joined Oct 14, 2008
1,821
I don't understand your point here which is probably a good one. Could you explain it more?
Sigh. OK, this is in the important field of model railroads. I found these bicolor LEDs, and thought they'd be a good way to make a device called a "searchlight signal". This has a single lens and light bulb (though there are often as many as 3 signal heads on a single mast) which has a movable filter that can make the displayed light red, green or amber. These LEDs can show all 3 colors, if you aren't too fussy about the actual hues that appear--there are actual standards for railroad signals, and the most common LEDs aren't right! What I wanted to do was to bend one lead of an LED into a hook which I'd solder around the mast, and that would provide a firm support and also an electric contact. The other lead would have a wire attached, which would bring the current to the signal, positive, negative or alternating.

It should be clear that to make this work, all the LEDs on a particular mast must have a common lead. That could be ground, but then I'd need a negative supply, which I wanted to avoid, so I set up the pseudo-ground at 2.5V. I feed that to the signal mast, and apply 0V or 5V or an alternating voltage to each of the LEDs. There has to be a resistor in series with each line, but not a large one, because the voltage is only 2.5, from the pseudo-ground to either Vcc or ground. 33 Ohms seems to be about right. So here are a couple of pictures, showing the back of a signal and then the front. Aren't you glad you asked?signal_back.jpgsignal_front.jpg
 

ApacheKid

Joined Jan 12, 2015
157
More can be found
Sigh. OK, this is in the important field of model railroads. I found these bicolor LEDs, and thought they'd be a good way to make a device called a "searchlight signal". This has a single lens and light bulb (though there are often as many as 3 signal heads on a single mast) which has a movable filter that can make the displayed light red, green or amber. These LEDs can show all 3 colors, if you aren't too fussy about the actual hues that appear--there are actual standards for railroad signals, and the most common LEDs aren't right! What I wanted to do was to bend one lead of an LED into a hook which I'd solder around the mast, and that would provide a firm support and also an electric contact. The other lead would have a wire attached, which would bring the current to the signal, positive, negative or alternating.

It should be clear that to make this work, all the LEDs on a particular mast must have a common lead. That could be ground, but then I'd need a negative supply, which I wanted to avoid, so I set up the pseudo-ground at 2.5V. I feed that to the signal mast, and apply 0V or 5V or an alternating voltage to each of the LEDs. There has to be a resistor in series with each line, but not a large one, because the voltage is only 2.5, from the pseudo-ground to either Vcc or ground. 33 Ohms seems to be about right. So here are a couple of pictures, showing the back of a signal and then the front. Aren't you glad you asked?View attachment 196153View attachment 196154
More can be found here.
 
Last edited:

JohnInTX

Joined Jun 26, 2012
4,237
How about this? It solves the quiescent power issue. When GPIO = 0, the RED LED is on and shunts the GREEN LED to less than its Vf. When GPIO = 1, the RED LED is back biased (can also use HIz) and the GREEN turns on.
RedGrn.png
 

ApacheKid

Joined Jan 12, 2015
157
The BBC has blocked me from watching this. I am in the UK and I have a BBC TV licence. WTF?
How c
Ou, you have written more than i expected : ) I need some time to read all of this :D Thnx guys.
Again, why not simply add an inverter? Feed the GPIO into a CMOS inverter then drive one LED from the GPIO and the other form the output of the inverter, each LED having a series resistor. Only one LED will every consume current at any one time and all of that current will be through the LED, nothing wasted.

INV1.jpg
 
Last edited:

MrChips

Joined Oct 2, 2009
21,674
1578420395246.png

There is absolutely nothing wrong with this circuit.
It has the advantage that you can have both LEDs turned on at the same time by configuring the GPIO as input.

There is no problem with the fact that the circuit will be drawing current. One LED has to be on all the time.

You can do the same thing with a dual red/green LED between the GPIO pin and a 2-resistor voltage divider.
1578422876673.png
 
Top