LED Power – Device to Power Either a Red LED or a Green LED
ioledswitching
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.
Best Answer
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.
The problem ended up being a PWM issue. (It was solved in the comments, however I've posted the following to help future readers of this.)
First switch the Red or Blue with the Green. This will determine where the problem lies. If the Red or Blue still doesn't work then the problem is with the LED (very unlikely) or somewhere in the connection. Otherwise it is a software problem, like incorrect use of PWM.
A resistor, R4, is used to pulldown VLOAD when the SPST switch, SW1, is open. This means that when SW1 is closed, VLOAD is high, and when SW1 is open, VLOAD is low.
An NPN digital logic inverter is used to provide the complement of the VLOAD signal. The input to the inverter is VLOAD, and it is powered by the voltage source. The output of the inverter is VLOADN.
D1 and D2 have shared cathodes. Since VLOADN = ~VLOAD, there is always one LED that is on while the other is off:
If SW1 is closed, the inverter input is high. D1 is on and D2 is off.
If SW1 is open, R4 pulls the input of the inverter low. D1 is off and D2 is on.
Best Answer
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.