Device to power either a red LED or a green LED

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):

schematic

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.


schematic

simulate this circuit – Schematic created using CircuitLab

You could also try this.

schematic

simulate this circuit

This would also work.

schematic

simulate this circuit


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.

enter image description here

Tags:

Io

Switching

Led