# Capacitor discharging after power supply is turned off

I am actually a computer engineer trying to get a feet into the embedded world starting by learning basic circuit stuff using 5 V or 3.3 V provided by Elegoo power supply.

I built the following circuit, hoping that the LED would remain bright for a few seconds when I turn the power off. However, the LED immediately goes off and a multi-meter also shows an immediate decrease of voltage.

simulate this circuit – Schematic created using CircuitLab

I noticed that the LED actually remains bright for many seconds if I open the circuit before power off.

simulate this circuit

I don't understand this behavior. What am I missing?

Thanks

EDIT: According to SamGibson's answer adding a diode solved my technically my problem but I have two more questions.

• I noticed that the higher the resistance, the slower the discharging of the capacitor. It makes sense as the current flow decreases. Am I right to say that when the power supply is off it acts as a wire without resistance?

• Before I started experimenting with a capacitor I calculated 330 ohm as a resistance for the LED. However, using 330 ohm the capacitor discharges also (almost?) immediately. Using 100 kohm the LED is not very bright but noticeable bright. Is there any way to put 15 mA on the LED and still using a capacitor?

• "Is there any way to put 15mA on the LED and still using a capacitor?" Yes, using a bigger capacitor: the time constant is R*C. Apr 20, 2022 at 9:06

What am I missing?

The capacitor is discharging quickly into the power supply, if the power supply is turned off while it is still connected. That is why...

I noticed that the LED actually remains bright for many seconds if I open the circuit before power off.

Exactly - with the power supply disconnected, the capacitor cannot discharge back into that, so its charge can supply the LED.

The solution is to add a small diode in series with the power supply to your circuit, like this:

simulate this circuit – Schematic created using CircuitLab

Any diode will work as D1. A schottky diode would have a lower forward voltage drop, but greater leakage (though I doubt that will make a difference here).

You show R1 as 100 kΩ but that will only result in something like 2 uA LED current. So since you say the LED is bright, I guess that value is a placeholder for a lower actual value.