Hey everyone! I'm working on a project where I need to switch between two separate LEDs. While I know multicolor LEDs could work, I'd prefer using distinct ones for my project. I'm wondering if there's a simple method to toggle between these two LEDs using only one GPIO pin—I'm thinking about connecting one LED to GND and the other to VCC. I have a 2n7002 transistor on hand, could this be a viable solution? Any guidance would be appreciated!
2 Answers
If your GPIO can handle the needed current for the LEDs, you could wire them up in series with a dropper resistor on each, placing the GPIO pin in the middle. When the pin goes low, the top LED shines, and when it’s high, the bottom LED illuminates. Just a heads up: if the pin goes high impedance, both might light up dimly depending on the supply voltage in relation to their threshold voltage. Also, lower current can work fine for indicator LEDs, you don’t always need the full 20mA!
You can definitely use the GPIO pin to control two small LEDs directly! Just connect one LED from VCC to the GPIO with a resistor in series, and the other LED from the GPIO to GND with another resistor in series. When the GPIO is high, the second LED lights up while the first one stays off, and vice versa when it's low. Just keep in mind that the GPIO can only sink or source about 5 to 10mA, which is sufficient for small LEDs. If you need more current, a transistor might be necessary.

Great tips, thanks! But should I stick to using one resistor for both LEDs, or is it better to run a resistor for each one?