Driving indicator LEDs safely

I’m building a unit that will indicate the state of my internet connection with LEDs, using a 3V3 controller (ESP32) driven from a USB (“5V”) charger.

In the “grounded LED” connection the intensity depends on the efficiency of the LED, the voltage on the output pin in the logic 1 state, Voh; the forward voltage of the LED, Vf; and the value of the resistor. Depending on the LED there may not even be enough forward voltage to light the LED.

I prefer the alternate configuration, with the LED connected to the supply (5V) which gives better control, due to the higher voltage margin Vcc-Vf; However I wondered if there was an issue in feeding the 5V to an output that is in the logic 1 state (3.3V approx). ?
The lowest forward voltage I have seen for an LED is 1.7V so I suspect that its not a problem, just wondering if this configuration is ALWAYS safe?

Why would you want or need to feed 5V to a pin at 3.3V ?

By the way, that link returns a 404 for me

In this configuration (2) the output pin is at around 0V to turn on the LED; and at Voh (3V3) to turn it off.

(OK an LED with a very low Vf it would be “on” - just.)

It would not; it would effectively be connecting to 5V (or thereabouts) through a VERY high value resisitor.

Controling the current through a typical InGaN LED driven from a 3V3 output via a resistor isnt really ideal, hence the need for a larger voltage margin 5V-3.3V =1.7V

OK I can add more components, but why?

What is the mysterious device labelled with an ampersand ?

It represents a digital output. EG ESP32 GPIO.

So in case 2 the pin will be at either 0V or 3.3V and VCC will be 3.3V

Sorry, but I am not seeing the problem or why you mentioned 5V

Is there a safe current that can be sunk by an I/O while it is in the HIGH state?

I don't think you are feeding 5V into the pin because an LED has a voltage drop (almost) independent of the current through it, so you are actually connecting 5V - Vf of the LED. Provided that is 3V3 or lower I don't see a problem.

Edit:
See reply #16 from @Wawa , he's pointed out a possible problem I completely missed.

To control LED brightness, you need to control current (milliAmps), not voltage.

It will probably work, but you should expect a dim glow when the LED is "off." The LED's color will affect this behavior, as it determines the forward voltage drop.

You’ll need to size your resistors appropriately. As a rough estimate, add 3.3 V to the LED’s forward voltage. Using that total and the resistor value, you can calculate the current flowing into the processor pin.

Be aware: if there isn't sufficient load, the 3.3 V rail may rise above its nominal voltage, potentially damaging the processor or other components.

I think you assume Vf of a LED is a solid value.
A 3.3volt Vf blue LED starts already lighting up at 2.5volt. A red one at about 1.3V.
No real issue driving a blue LED from a 3.3volt pin of an ESP32.
You likely don't need more than 3mA for modern small indicator LEDs.
Try driving a small blue indicator LED at 20mA. You might need sunglasses.

I don't see the need of powering an indicator LED from 5volt, or driving it at max current.
Look at the LEDs on an Uno R3. Quite annoying sometimes, and only driven with 3mA...
Leo..

No not at all. However I havent been able to find a “definitive” referenced set of forward characteristics, nor a Shockley formula for an LED.

my own tests have shown for this particular 5mm red LED the current is less than 0.1mA at 1.7V

nor was that my intention - only to provide a predictably controlled current with a single series resistor.

Also clearly connecting to a higher voltage supply than the USB 5V would not be a good idea.

Not according to OHM's law.

 This law states that electric current is directly proportional to the voltage across the conductor and inversely proportional to the resistance. 

Yes, this would be bad - current would flow through the protection diodes on the pin - much more than they are spec'ed to allow. Potentially, feeding into the 3.3V power rail and frying everything.

The Vf voltage drop of the LED MIGHT be enough to prevent this, but it still seems like a bad idea.

With modern LEDs, driving them in your first configuration (from 3.3V output) will provide plenty of brightness, even for blue/white/etc LEDs. If you need brighter, use a transistor or logic gate designed to support 5V.

Not quite.
Assuming the pin is set to output, then the high-side fet of the pin will connect the pin to VCC.
Then powering a LED/resistor from "VCC+ 1.7 volt" seems safe.
But the pin is not an output during bootup, and 5volt rises before 3.3volt.
But I'm not sure why you would want to take that risk for an indicator LED.

Do you think you are going to see a big difference if you drive a modern LED with 5 or 7mA.
In my last ESP project I turned on a blue LED with just internall pull up.
That 2mm through-hole blue Led was still quite piercing with ~30k internal pull up.
Leo..

Well spotted, I completely missed that potential problem!

Thanks; that answers th question.