Toggle between two LEDs.

Hi:

I need to toggle between a red and a green LEDs. When the pin is LOW the green LED must be turned on and when the pin is HIGH, it must be turned off and the red one, on.

I know this has something to do with NPN and PNP transistors but I need help on this one.

Thanks!

Are you trying to use a transistor even though you don't need one?

Because I don't see why you don't just run both LEDs from the pin, one to GND and one to 5V, so when the pin is LOW it is sinking for the 5V, and when it's HIGH it's sourcing for the GND.

As INTP says, connect the two LEDs to the pin directly.
This drawing may help if you only use one pin for driving both LEDs.

Edit: connect both LEDs to D8
select R2-3 to get the intensity you need for the different coloured LEDs.

.

INTP:
Are you trying to use a transistor even though you don't need one?

Because I don't see why you don't just run both LEDs from the pin, one to GND and one to 5V, so when the pin is LOW it is sinking for the 5V, and when it's HIGH it's sourcing for the GND.

You mean something like this?

Won't that burn the pin when it is LOW and it will get a voltage from 5V (minus the drop in the LED)?

I assumed you knew to use resistors. Sorry for not spelling it out.

INTP:
I assumed you knew to use resistors. Sorry for not spelling it out.

So one of the LEDs will be powered by the pin.

Sure, depending on what you mean by 'powered'.

LEDs = Light Emitting Diode. Keyword to focus on is "diode".

rva1945:
You mean something like this?

Won’t that burn the pin when it is LOW and it will get a voltage from 5V (minus the drop in the LED)?

With a resistor between Output digital and Led common point it is better for the Led :grin:
rectif_del1.png

68tjs:
With a resistor between Output digital and Led common point it is better for the Led :grin:
rectif_del1.png

But red and green leds drop different voltages and not making the current to each equal, you get cursed with 5 years bad luck.

If there is room use two resistors so you can achieve the brightness you need for each led.

.

But red and green leds drop different voltages and not making the current to each equal,

Yes current follows Ohm's law but what about quantum efficiency versus color? :grin:
My lack of knowledge does not allow me to affirm anything. ::slight_smile:
But I have enough knowledge to doubt it is the same in green or in red.

Anyway the first scheme did not include resistance and I would not be cursed with 5 years because I saved the diodes of a certain death :grin:

I agree that they have different brightness. For example, for navigation lights in a model boat, I must use different resistors for the red and green LEDs: a greater value for the red LED (small current needed) and a smaller value for the green one.

Thanks!

Two LEDs in series from +5volt to ground without current limiting, as in the three previous pictures?
Can’t do that with common LEDs with a Vf of ~2volt, and not wise with high brightness LEDs with Vf of ~2.4volt (red) or ~3.3volt (green).

So two LEDs on one pin, with PWM (colour change) possibility.
+5volt > green LED > green current limiting resistor > red current limiting resistor > red LED > ground.
Connect the Arduino pin to where the two resistors join.
Leo…