# Device to power either a red LED or a green LED

I have a green LED and a red LED. I want a sort of switch to turn either the red LED or the green LED on. For example:

Where if the switch is off, the red LED is on but if the switch is on, the green LED is on. • Use a changeover switch aka SPDT and make sure each LED has a resistor in series. Nov 23 '20 at 18:52
• one resistor is enough if you have the changeover switch. Nov 23 '20 at 19:03
• @user287001 I would recommend separate resistors. The forward voltages are pretty different, and red LED's tend to appear very bright compared to green with the same current. The red LED will likely need a much larger resistor then green. Nov 23 '20 at 21:15
• I'm surprised only one person has brought up the trick that exploits the different forward voltages. If you put these LEDs in parallel, the red one will turn on; disconnect the red one, and the green one will turn on. (Note: may need to check your specific LED datasheets - but that answer also added a diode to the green one to increase it further) Nov 24 '20 at 11:34

A collection from another thread, posted here for the middle schematic. Pin 6 would be the GPIO pin. For better brightness matching, swap the red and green LED positions. • Circuit 2 (or 3) is a trick to use less parts, by exploiting the fact that the green LED has a higher forward voltage, and adding another diode to make it even higher. Good idea. Nov 24 '20 at 11:33
• Please provide a link or citation for the "another thread" where you found these images. We need to give credit to the original creator. Nov 25 '20 at 14:22
• I am the original creator. Those a re my schematics. Nov 25 '20 at 14:30

You mention an IO pin; this is how you could do it with one IO pin if you are using a microcontroller (assuming one that uses 5V logic): simulate this circuit – Schematic created using CircuitLab

When the IO pin is 5V, D2 will light up; when the IO pin is 0V, D1 will light up.

Note that you will have to calculate the actual resistor values; different types and colours of LED require different resistors. There are plenty of examples about that show how to calculate these values.

Also, make sure you don't sink/source too much current; the maximum current an IO pin can handle varies from microcontroller to microcontroller.

• Note that in this scenario, there are situations where both LEDs will turn on (if the microcontroller is reset, for example) Nov 23 '20 at 21:32
• @BeB00: Yes, if the IO pin goes high impedance about 5mA will flow through both LEDs for the LEDs I assumed in the example. Nov 23 '20 at 21:39
• @BeB00 That could be considered a feature! Set the pin to input if you want to turn on both LEDs. Nov 24 '20 at 19:23
• But you can't turn off both LEDs with this solutions without removing power. Nov 25 '20 at 9:47
• @NStorm: That's another feature; it doubles as a power-on indicator. But seriously, I don't think turning off both LEDs and have independent currents while power is on is doable with one IO pin without extra components. Easy with two IO pins, though. Nov 25 '20 at 13:59 simulate this circuit – Schematic created using CircuitLab

You could also try this. simulate this circuit

This would also work. simulate this circuit

• This is cool but if you are using two IO pins you can just use one to control each LED separately. Seems like that would be more straightforward. Also, I do recommend using different resistors for the two LED's because they have different forward voltages, and also, it will probably be better to run more current through the green LED than the red one. Nov 23 '20 at 22:44
• @mkeith You are correct. I changed my answer to reduce it back down to one IO pin. Nov 23 '20 at 23:03

On editing your question, I see that what you really want to do is to switch the LEDs from a microprocessor output.

The easiest way to do that is in your program. Use two GPIOs, and always switch one off when the other is on.

If you can't change the program, then you could do something like this: simulate this circuit – Schematic created using CircuitLab

That turns the green LED on when the GPIO is high, and it turns the red LED on when the GPIO is low. Only one or the other will be on, never both.

What you need is a single pole double throw (SPDT) switch.

The circuit looks like this: simulate this circuit

One LED will always be turned on.

The resistors are not optional. You must have them to keep the LEDs from burning out. There are plenty of posts on this site about calculating the resistor values given the battery voltage, the LED forward voltage, and the LED current - I'm not going to go into that here.

The resistors are useful for a second reason, as well.

Red and green LEDs don't light equally bright for the same current. With separate resistors, you can tweak the current to make the LEDs approximately equally bright. Good challenge for other solutions! If one of the two LEDs will always 'on' I suggest another circuit:

A) the two LEDs connected in parallel but in opposite polarity; B) two resistors (chose the value) connected in series between +V and GND; B) one side of the couple of LED is to be connected to the GPIO; C) the other side of the LED couple is to be connected to the middle of the resistors series.

Only if the GPIO turn in 'Z' state, none LED will be light; the will current continue to flow in the two resistors but at a reduced intensity, depending by the sum of the two resistors, surely lower than when a LED is ON.

• I don't think you actually want there to be a direct connection from R1 to R2. You need to break that wire. Which makes this solution almost the same as ocrdu's answer. Nov 23 '20 at 23:01
• @mkeith: this avoids the situation that both light up when the GPIO is high impedance. It's the way I have done it when needed. Although it is probably more wasteful of power. Nov 24 '20 at 4:55
• It is not just wasteful of power, it constrains the solution space so that the currents are not independent. With the resistor values you have shown, R1, R2 and the supply can be converted into a Thevenin equivalent where Vthev is 2V, and Rthev is 132 Ohms. It is a very strange way to do it. But I guess it could work in some cases. Nov 24 '20 at 5:58
• No, no, no! You are wrong. I'm not I that must change my circuit, but are you that need to look at it with more attention. The solution in the ocrdu's answer, the current continue to flow in both LED if you release the GPIO to the 'Z' state. If you pay attention to my solution, this not happens. In my solution the LED cannot be lighted together! In my solution, the only bad thing is that when GPIO is in 'Z' state, a reduced current flows anyway but only through in the resistors in series between themselves. So, the two resistors are to be left as in my design and is easy understand why. Nov 25 '20 at 11:12
• There is not energy wasted! The question was: how to light a LED or another alternatively! So, there must be ALWAYS a LED in ON condition and this is the way to sink energy. The case of High Impedance (ASA 'Z' state) is a condition out of the terms of the question, but is a condition that I want declare for correctness: a condition that will never true. So how you can tell that this condition will be a waste of energy? My circuit never falls in this condition if (as declared) one LED at least it's ON. Nov 25 '20 at 11:12