How to create LED turn on immediately but fade out slowly effect with Capacitor

I know Arduino have six PWM pins and that freaking rocks.

BUT I am hoping there is a simpler way, a hardware way.

Can I like just hook a capacitor in parallel to the LED ?

Then when the power to the LED is gone, the capacitor will supply the LED with just enough power to fade off ? I don't need a long fade off, I just like a short fade off effect.

Can this be done ?

Cheap and nasty but should work. Don't forget to put the resistor in series with the LED.
But why are you asking rather than just trying your idea out to see if it works.
Experimentation is the food of enlightenment.

  1. You'd need a fairly large capacitor to provide any visible fade out effect. On the order of 1000uF, possibly more.

  2. You'd have to deal with the capacitor charging as well, and doing so without inducing a fade on effect would require additional circuitry. You most definitely do NOT want to connect such a large capacitor directly to any of the Arduino IO pins. The initial current draw to charge the cap would damage the micro. You'd have to use an additional transistor with fairly high current capacity to rapidly charge the cap in order to create the appearance of an instant on. You may also still need a current limiting resistor with the transistor, depending on it's current ratings and the ESR of the cap you're using.

Huh, never thought about that!
Like use the limiting resistor to power up the capacitor and then as the power dies down in the capacitor, the LED will fade.
The guys above me is right, you gonna wanna get something so that the capacitor doesn't destroy your hardwarez bro

BlueBlondeTard:
BUT I am hoping there is a simpler way, a hardware way.

The use of the word "hardware" suggests not using an Arduino to drive the capacitor/LED system

All these hardware talks is burning my mind.
Ok, analogWrite it shall be.

How about using the cap to feed the base of a transistor instead of the led directly? That way a smaller cap will suffice and you have better control over the discharge time. See the attachment.

When you close the switch, the led will power up immediately and the cap starts to charge. Optional R3 (a small value) prevents the cap from drawing to much current while charging. When you open the switch, a small current flows from the cap through R2 to the base of the transistor. The led slowly dims down while the cap discharges. Use the RC time calculator RC Time Calculator to find a good value for the cap.

Haven’t tested the circuit so I’m not sure if it really works.

led_dimmer.png

Oh my God no.

I am just a 40~ year old Blonde Tard.

That is too much for me.

Don’t be so hard on yourself, man!

Btw, I tested the circuit I attached in my previous post. It worked pretty much as I expected. Using Vcc=3V, D1=red led, Q1=BC639, C1=47uF, R2=10K and R1=100R (didn’t use R3) it took about 3 secs for the led to fade down.

What was the code that you used for it pekkaa?
I would really like to try that.

What was the code that you used for it pekkaa?

It's hardware, no code is involved nor any arduino.

oh cool so this is straight up hardware.

---I like

Could this be done using a thyristor? The sum total of my knowledge of thyristors is from the label “auto thyristor” on my flash units, and quickly reading the Wikipedia page. Fortunately, I don’t mind looking stupid if, in the process, I learn something. :slight_smile:

C2 is always charging through R1. When T1 turns on, it discharges through the LED and R2. T1 turns off when there is less than Vf at the LED (unless the switch is being held). The charge rate must be lower than the discharge rate, otherwise, it won’t shut off by itself, therefore R1 must be larger than R2. A more sophisticated version would use a button to trigger a pulse from something like a 555, or Arduino, to turn on the thyristor. Might be better to have more than 5V, and I’m wondering if there should be a resistor between Vcc and the gate.

ETA: Well, duh! Can’t sleep, but at least I thought of how I got that wrong. :blush: Have to put some more thought into it … later.

Have you already figured out what's wrong with your circuit? I may have a few hints for you, but I don't want to spoil the fun if you would rather solve it by yourself.

Well, the extremely DUH part is that the 'bottom' of the cap is at ground potential. :grin: After dinner and a bit of amusement, I'll fire up kicad again and hope that I can engage a few more brain cells.

pekkaa:
Have you already figured out what’s wrong with your circuit? I may have a few hints for you, but I don’t want to spoil the fun if you would rather solve it by yourself.

Okay, this looks better to me, but I could still be off in the weeds. So, on a scale of 0-4 ??? (Also, consider SW1 as a proxy for ‘trigger the thyristor’ – maybe just a switch is OK, but if I’m at least on the right track, I’ll refine that, as well as resistor values.) And sure, I’d appreciate a few hints.

thyristor_fade.jpg

Pekkaa - excellent design. Thanks for sharing!

A question however: why is it that you were able to do without R3? From the initial discussions there was the trouble of the capacitor drawing too much current from the Arduino. Is it because it's sharing the current with the LED that's it's not drawing too much current?

I didn't need R3 because I didn't power the circuit from the Arduino. It tested the circuit with and without R3 resistor.

You may not need R3 also if you already have a larger decoupling cap between Vcc and GND. If you think you need R3, pick a value that limits the current below the maximum you can draw from Vcc. If you calculate the discharge time, use R3 + R2 as the R-value in the calculation.

I commend you on your honesty... I only started into electronics about 18 months ago. Fortunatally for me I started off building my first project as a analog solution with transisters, resisitors, LEDs etc... I learned a lot from that experience... When I finally realized the power of a micro-controller I was like "DUH!!!" this is a heck of alot simpler. The point I'm trying to make is you need to do some extra homework on simple MOSFET circuits to open up your thoughts on how to do things. You could use a very small CAP designed to blead off the the 5V signal that is applided to the gate of the fet and you will get the effect you are after... Bottom line is you need to brush up on some simple hardware knowlwdge to fully enjoy the opportunity of the micro-controller... You will get up to speed faster then you think. Find the "For Dummys" version of how to use P & N channel MOSFETs... Lot's of links on the web... If it get into the technical way that FETs work move on... Find the simple explainations on how to use them...

Cheers!