Arduino Forum

Using Arduino => General Electronics => Topic started by: mace on Aug 20, 2013, 07:40 pm

Title: Basic maths: 10k? resistor, 5V voltage, 100µF cap=0.76 second LED fadeout
Post by: mace on Aug 20, 2013, 07:40 pm
As an exercise in basic EE and basic maths, i want to fade out a LED with a capasitor. I wonder if anybody could peer-review my calculations?

http://www.youtube.com/watch?v=Rea1_hrf1Gw

Given i am using a 10k? resistor and a standard LED in series, and in parellel with a 100µF cap, all in a 5V circuit, shouldn't my timeout be 0.76 seconds?



Charge C = F*V
Charge C = I*t
Time t = F*V/I = 0.0001F*3.8V/(5V/10000?) = 0.76s

(http://upload.wikimedia.org/wikipedia/commons/thumb/2/2a/Georg_Simon_Ohm3.jpg/200px-Georg_Simon_Ohm3.jpg)+(http://upload.wikimedia.org/wikipedia/commons/thumb/f/fe/Gustav_Robert_Kirchhoff.jpg/200px-Gustav_Robert_Kirchhoff.jpg)=(http://i192.photobucket.com/albums/z114/Lonely_Demon9/lolcat/seal-of-approval.jpg)?
Title: Re: Basic maths: 10k? resistor, 5V voltage, 100µF cap=0.76 second LED fadeout
Post by: DVDdoug on Aug 20, 2013, 08:43 pm
Take a look at this page (http://electronics.stackexchange.com/questions/4951/how-do-i-calculate-how-fast-a-capacitor-will-discharge).

Have you had calculus yet?   A capacitor discharging through a resistor is an exponential function.  (Since the current is not constant, you cannot use C = I x t except for "one instance" in-time.)

The non-linear LED further-complicates things.    ...It's over my head, and it's been long time since I've had calculus.   It might be as simple as a discontinituity when you hit the LED cut-off voltage (with an "ideal" LED) and the current suddenly drops to zero, but I'm not sure.   Or, it might involve two simultaneous equations until you hit the discontinuity????
Title: Re: Basic maths: 10k? resistor, 5V voltage, 100µF cap=0.76 second LED fadeout
Post by: mace on Aug 20, 2013, 09:27 pm

Take a look at this page (http://electronics.stackexchange.com/questions/4951/how-do-i-calculate-how-fast-a-capacitor-will-discharge).


That was good, thanks. Stack Exchange is fantastic.

Have you had calculus yet?


LOL i admit my calculus is rubbish, after so many years since highschool. That's why i'm doing such basic math now, and also looking for peer support here. Thanks for it DVDdoug, i appreciate it! This is great exercise.

Now that the day is drawing to night, and it's getting darker, i can empirically see that the 0.76 seconds is too short a time for my LED's fadeout; it seems to be above 1 second.

A capacitor discharging through a resistor is an exponential function.  (Since the current is not constant, you cannot use C = I x t except for "one instance" in-time.)


That's right, it makes sense; the LED is fading, and that is exactly the reason why it's getting less and less bright; the current is dropping... and thus it's bleeding the charge in the cap slower and slower.

My amended calculation, assuming an exponential decay of current, is -10000?*0.0001F*ln(1.2V/5V)=1.43s. That seems to correlate better with sense-based observations. Next, maybe i should build a tool, using Arduino, a light-dependant-resistor and millis(), that would measure the time it takes for the LED to fade 8)
Title: Re: Basic maths: 10k? resistor, 5V voltage, 100µF cap=0.76 second LED fadeout
Post by: mmcp42 on Aug 20, 2013, 09:37 pm
suggest build it and just try a few values!
Title: Re: Basic maths: 10k? resistor, 5V voltage, 100µF cap=0.76 second LED fadeout
Post by: Erdin on Aug 20, 2013, 10:25 pm
I agree what mmcp42 wrote.

Some leds are very well visible with only 0.5mA or even less.
I think that one led can be 10 times longer visible than an other led.
Title: Re: Basic maths: 10k? resistor, 5V voltage, 100µF cap=0.76 second LED fadeout
Post by: AmbiLobe on Aug 20, 2013, 11:56 pm
The circuit schematic is too far away, but let me guess :
The capacitor is in parallel with the LED.
The switch is in parallel with the LED.
The resistor is not used.
Title: Re: Basic maths: 10k? resistor, 5V voltage, 100µF cap=0.76 second LED fadeout
Post by: mace on Aug 21, 2013, 12:00 pm

The circuit schematic is too far away, but let me guess :
The capacitor is in parallel with the LED.
The switch is in parallel with the LED.
The resistor is not used.


@AmbiLobe: Do you mean how my circuit was built? The resistor was used; the cap is in parellel with LED and the resistor, which are in series together. See the attached schematic.
Title: Re: Basic maths: 10k? resistor, 5V voltage, 100µF cap=0.76 second LED fadeout
Post by: AmbiLobe on Aug 21, 2013, 12:31 pm
The RC time constant is 1 second.

Thank you for the schematic diagram. The math is like this after the switch is released:
There are three nodes : S1 Anode GND
The LED Anode has about 2v as a diode drop. Treat it as a voltage source of 2v.
The resistor has 3 volts time = t = 0 seconds
The peak current at t=0 is i(0) = v/r = 3/10k = 0.3mA
The current decays exponentially

i(t) = i(0) * e^(-t/rc)
rc = 10k * 100uF = 10^4 * 10^-4 = 1 second
e = 2.7182 a constant from science education

e^-1 = 1/e = .632

e^-2 =  1/(e*e) = .632 * .632 = .40
e^-4 = .16
e^-8 = .0256

after 1 second i = .3mA * .632 = .189 mA
after 2 seconds i = .3mA*.16 = 48 micro amps (uA)
after 8 seconds i = .3mA*.0256 = 8uA

Conclusion : your math was wrong. The LED will be dim with .3mA.
Its power is 2v*.3mA = 0.6 milliwatts
This is a dim bulb.
Title: Re: Basic maths: 10k? resistor, 5V voltage, 100µF cap=0.76 second LED fadeout
Post by: MarkT on Aug 21, 2013, 06:01 pm
Quote
See the attached schematic.


You short the supply into the capacitor - add a small value resistor in series with the
switch if you want to avoid welding it shut and resetting the Arduino!
Title: Re: Basic maths: 10k? resistor, 5V voltage, 100µF cap=0.76 second LED fadeout
Post by: mace on Aug 23, 2013, 11:00 pm

Quote
See the attached schematic.


You short the supply into the capacitor - add a small value resistor in series with the
switch if you want to avoid welding it shut and resetting the Arduino!


Oh, so it's not good to let caps suck in energy as they please, without controlling it? As explained f.ex. here (http://www.electronicspoint.com/uncharged-capacitor-short-circuit-t8813.html). Hmm i guess (V=IR) if at the beginning time t0 the voltage jumps to 5V, the resistance is (theoretical) 0, then the current is infinite, until the capasitor starts to build resitance as it's charge increases. Is this it?

Thanks MarkT for bringing this to my attention!

I love these little electronics and Arduino, it's such a great way to get (back) into math and so many other wonderful things :)
Title: Re: Basic maths: 10k? resistor, 5V voltage, 100µF cap=0.76 second LED fadeout
Post by: RoyK on Aug 24, 2013, 04:19 am
This discussion reminds me of this classical problem.

The charge on a capacitor is given by q=CV
The energy stored in a capacitor is 1/2 C*V*V (one half C Vsquared)

Assuming perfect capacitors, perfect wires (0 resistance), and a perfect switch.

We charge a 1 farad capacitor to 1 volt and disconnect it from the charging source.
Its charge is then C*V = 1 coulomb and its energy is .5 * 1 * 1 * 1 = .5 joules.

Now we use a switch to connect the capacitor in parallel with another 1 farad capacitor. Since charge must be conserved our 1 coulomb of charge is now divided between the two capacitors. So the voltage on each is q/C or .5 volts and the energy stored in each is then .5 * 1 * .5 * .5 = .125 joules. So the total energy in the two capacitors is .125 * 2 = .25 joules.

Question is what happened to the missing .25 joules of energy?
Title: Re: Basic maths: 10k? resistor, 5V voltage, 100µF cap=0.76 second LED fadeout
Post by: mrburnette on Aug 24, 2013, 06:07 am
The math is all fun, but when you need to quickly play, you need SPICE

http://www.falstad.com/circuit/ (http://www.falstad.com/circuit/)

Title: Re: Basic maths: 10k? resistor, 5V voltage, 100µF cap=0.76 second LED fadeout
Post by: AmbiLobe on Aug 24, 2013, 06:45 am
"Question is what happened to the missing .25 joules of energy?"

During the time that current flowed from one capacitor into the next capacitor, a magnetic field was changed. The energy went into that magnetic field during an impulse. A resonance then occurs without damping, and the oscillation lasts forever. The missing energy is tossed about forever, outside of the capacitive energy.
Title: Re: Basic maths: 10k? resistor, 5V voltage, 100µF cap=0.76 second LED fadeout
Post by: CrossRoads on Aug 24, 2013, 07:36 am
The ESR of the capacitor also comes into play, which limits the current flow out of the cap to some extent.
Title: Re: Basic maths: 10k? resistor, 5V voltage, 100µF cap=0.76 second LED fadeout
Post by: cjdelphi on Aug 24, 2013, 07:52 am
How come you're not using a transistor ?  You can make it fade out nicely then!
Title: Re: Basic maths: 10k? resistor, 5V voltage, 100µF cap=0.76 second LED fadeout
Post by: mace on Aug 24, 2013, 09:35 pm

How come you're not using a transistor ?  You can make it fade out nicely then!


Did you refer to me? Because i want to learn this stuff :) Transistors will come later  8)
Title: Re: Basic maths: 10k? resistor, 5V voltage, 100µF cap=0.76 second LED fadeout
Post by: polymorph on Aug 25, 2013, 03:05 am
Yes, the missing 0.25j goes into RF radiation from the magnetic field changes as the charge bounces between the caps, into resistive losses in the wires, losses in the dielectric, and losses in the ESR of the capacitors.

If you had two perfect capacitors with superconducting plates and superconducting wire and no losses in the dielectric, it would take a long time to stop ringing, but eventually it would radiate away as RF.
Title: Re: Basic maths: 10k? resistor, 5V voltage, 100µF cap=0.76 second LED fadeout
Post by: Jack Christensen on Aug 25, 2013, 03:27 am
It might be interesting to connect the circuit as below, use the digital pin to charge and discharge the capacitor, and the analog pin to measure the voltage across the cap. It probably won't be perfect, but I'd bet it would come pretty close to producing the classic charge/discharge curve (example here (http://www.tpub.com/neets/book2/3d.htm)).
Title: Re: Basic maths: 10k? resistor, 5V voltage, 100µF cap=0.76 second LED fadeout
Post by: cjdelphi on Aug 25, 2013, 03:54 am
Yes mace, the led discharging through the cap gives a short pulse not so much fade. .

Using a transistor you fill a capacitor with the button press and as that slowly discharges (connected to the base of a transistor) will gently fade out the led...

If you want automatic a 555 can be used to "breathe" ..