Fading an LED with hardware
November 13, 2010
I am trying to get an LED (attached to the i/o port of a microcontroller) to fade in and fade out without using PWM. I hooked up a resistor and LED pair in parallel with a large-ish polarised capacitor, thinking that as the cap charged it would prevent some current getting to the LED, resulting in a fade up to full brightness. When power was removed the cap would then slowly empty it's charge through the LED, resulting in a fade out. It worked for the fade out but not the fade in; it simply went to full brightness when power was applied.
I realised I would need another resistor between power and the cap to limit the speed at which he cap could charge. I set this up (see figure below) and it is kind of working; I get both a fade in and a fade out. But the fade in speed is not the same as the fade out speed.
I'm wondering if anybody knows if there is a way to calculate what resistor/capacitor values will give different fade in/out speeds? I'm also curious if it's possible to calculate how much current is passing through the LED? I used a 220 ohm to set a current of 20mA when supplied with 5V, but I'm guessing this all goes out the window now that the cap and extra resistor are attached.