Prevent current from 5V pin when connected through USB

I have an ESP32 dev board controlling an LED matrix, both of which are powered by the same 5V switching PSU. The ESP32 is powered through the +5V pin. Everything is meant to be enclosed in a box with a USB cable running out to allow reprogramming the ESP. The issue is that when I connect the USB cable to my computer (with the PSU being switched off) it also powers the LEDs through the 5V pin. These may draw too much current in certain settings potentially damaging the USB port.

I was thinking of three options to avoid the problem:

  1. Put a Schottky diode at the +5V pin allowing the current to flow in, but not out.
  2. Cutting the +5V wire in the USB cable and reprogramming with the ESP being powered by the main PSU.
  3. Have a switch on the +5V pin to disconnect the rest of the circuit from the ESP while reprogramming (I don’t like this option due to the extra switch, but it is still a possibility)

If I go with 1), is the voltage drop going to cause problems? Could I actually take advantage of the voltage drop, connect a suitable resistor in series, and power the board through the 3.3V pin instead of the 5V pin? Lastly, is there any trickery in choosing the diode?

If I choose 2), is the computer still going to recognize the ESP32 board? Could there be any other issues?

I kind of like option 2 as I don’t even need to turn the PSU off for reprogramming.
In case you can think of another simple solution (I’m rather inexperienced, so please don’t suggest anything crazy), please let me know as well.

It should be pretty easy to put a switch in the box to disconnect the LED power during programming.

If You only connect the USB for reprogramming, can't You live with this "behaviour"? After reprogramming You disconnect the USB and all is fine?

What do you mean by "this behaviour"?

Just to clarify, the 5V pin is connected to a PSU and so are the LEDs. The issue is that if I connect the USB (with the PSU switched off), then it will also power the LEDs (via the 5V pin that the board is normally powered through). Since they may draw more current than the 500mA USB limit, something bad may happen to the USB port.

I plan to put everything in the box and keep reprogramming it quite a lot afterwards.

I thought strange things happend when running from USB. Your 500mA concern is of course good. How often do 'You reprogram the device? Is it worth installing extra switches etc.? Maybe disconnecting the most current consuming units during reprogramming is Worth the effort?

Yes, I'm actually leaning towards the extra switch despite my initial preference. This way I can tinker with the code with the PSU and LEDs switched off. I'm building a "smart" LED lamp that I want to control over bluetooth/wifi. I have the enclosure already built, electronics more or less wired, and I'm ready to put things in and close it and do the communication part of the project slowly over the upcoming weeks. I will be reprogramming it a lot as I have zero experience with bluetooth at this point.

It's called a switch, for goodness' sake! :astonished: