I am try to make an LED circuit that can be controlled with pything using a Pi Zero.
The problem is when I try to turn the LED off, it retains a faint glow (image).
Equipment:
- Pi Zero W
- RGB LED with common anode
- 220 Ohm resistors
I believe the circuit is wired correctly because to turn the LED "off" the output has to be set to 5V.
Best Answer
tl; dr: the LED has a leak path between 3.3V and 5V. Either don't use 5V for the LED, or add a transistor, MOSFET or true open-collector gate to isolate the GPIO and drive the LED.
What’s going on?
If you use a 3.3V GPIO pin to drive a 5V-tied LED, when the GPIO is high it will not be fully 'off': there will still be leakage current between the pin's IO protection and the LED.
Here's what that looks like, and how to fix it:
simulate this circuit – Schematic created using CircuitLab
You’d think that because 5V-3.3V = 1.7V is lower than the LED forward voltage, or Vf, that the LED would not conduct and thus not light up. This is not the case: there will still be some small leakage current that will result in a faint glow. This leakage has a name: subthreshold conduction, and is present in practically all semiconductor devices, including LEDs. Just tens of microamps can make it light.
A note:
How do I fix It?
The solution options depend on the LED's forward voltage:
All these solutions eliminate the leakage path.
Why use 5V at all?
Using 3.3V for a 3V-ish Vf LED (e.g., white, blue) isn't a good idea as it's very hard to get the current-limiting resistor right: with only 300mV or less IR drop in the resistor, a very small R value must be used, and so the LED current is very sensitive to forward voltage variation.