265Views5Replies

### Author Options:

I am trying to have a red LED fade off after it is switched on. I know I would need a capacitor, the question is, what value would be needed and would the cap be placed across + and - with the LED (and current limiting resistor) going from + to - as per usual if you see what I mean? Any suggestions would be greatly appreciated.
Many thanks, kind regards

Tags:

The forums are retiring in 2021 and are now closed for new topics and comments.

If you wanted to use a microcontroller, the pseudo code would be as follows:

declare energy as dec
energy = 0
pin (whatever number pin you want here) analog resistor value

up:
pin (whatever number pin you want here) = energy
energy = energy + 1
pause 100
if energy < 100 then go to up else go to down

down:
pin (whatever number pin you want here) = energy
energy = energy - 1
pause 100
if energy > 0 then go to down else go to up

That code (which you would have to translate into whatever code you need for your microcontroller) would create an endless loop of fading up and down. You can then add different variables to go into and out of the sequence, change the fade time (by adjusting the pause length), etc.

I know this isn't exactly what you were asking, but I decided to post it just in case it could be useful. :) Good luck with your project!

that's brilliant. I didn't think about using a microcontroller. Nevertheless I appreciate the idea and will have a mess around on my programmer.
Many thanks again

No problem! :)

I am going to start by assuming you have a capacitor, a resistor, and an LED, all in series, with the initial voltage on the capacitor Vc0, and the characteristic drop across the LED Vd.  Moreover I will assume that Vc0, the initial voltage of the capacitor,  is the voltage of your supply, whatever that is.  So that you have probably already picked an R to go in series with this LED.

The initial current through the LED will be:  I(t=0) = I0 = (Vc0 -Vd)/R

Upon disconnecting the supply from the capacitor, at t=0,  the LED current will fall to 1/e its previous value every R*C seconds, according to:

I(t)  = I0*exp(-t/(R*C))

To make this fading LED current slow enough to see, choose R*C equal to a few seconds or so.

For example, if the resistor in series with this LED is 1K (1000 ohms), and you want R*C = 2 seconds, that works out to C= 2e-3 F = 2000e-6 F = C =  2000 microfarads.

Let me know if you want me to draw you a picture of this, or otherwise explain what I am saying in greater detail.

Thanks for that. It makes sense to me. I thought something along the 2000mf route but just wanted to be sure.
Thanks again