Simple question about a draining capacitor sensing circuit

Hi Guys,

I'll start off by apologizing. I am a noob hobbyist. What I would like to know is I made a simple circuit as shown in the attachment. I am using my USB power to power my Arduino Uno Rev 3 and the circuit. All I am doing is charging up a 4700uF capacitor and powering a small green LED. What I am also doing is looking at the analog input from A0, which is going to the positive rail of this circuit. Works great.

If I break the positive rail with a switch, the LED slowly goes off and the A0 is reading in the flow of electricity as dropping, which is good.

However, if I flip the switch back over to re-connect the broken positive rail, the Arduino locks, and I hear my USB port reset (Windows makes the da-dunk noise). Until I remove my USB cable and wait a moment, then re-hook it up, is everything fine.

So my question is, what is causing this, and what component/circuit redesign would be required to resolve that?

Thanks in advance,

Closing the switch on a capacitor that size is like putting a crowbar across the 5V line to ground!
Don't do this!
Put a 330 ohm resistor in series with the switch the voltage will only get to ~2.5V then.
Why do you want to do this?

Add a resistor in series with the switch? Between the switch and the power drawing side of the circuit, or between the switch and the arduino 5V?

Eventually, I will putting in a voltage regulator with large capacitors, and I wanted a way to read when power had been pulled from them. Then I can kill processes to other things, such as writing to an SD Card, before the power totally drops out.

USB interfaces are protected against overload when too much current is drawn from them. USB is specified at 0.5A max although some will supply more.

Capacitors, when can be considered a very low impedance to ac.

When you close the switch when the cap is discharged, the cap will present an instantaneous short circuit to the USB port & the protection will kick in. If the protection did not kick in, then the cap would charge quickly & the current would drop quickly.

To stop this hapenning, you have to limit the current drawn from the USB. The easiest way is to put a small resistor in series with the switch. The question is, how big & it's not easy to answer since the USB port could be supplying current to a number of different things. If you just have the Arduino connected, then its load depends on what it's doing & what's connected to its pins. Assume it's 100mA (probably less) & that leaves 400mA to charge the cap. The LED will only draw around 10mA, (5V - 2V for the LED) / 330, so you can ignore that. If the cap has zero volts on it when the switch is closed, then teh USB will only see the series resistor. So, from ohm's law, R = V / I, we get R = 5 / 0.4 = 12.5ohms. So fit 15 ohms to be safe. You could try 10 or 12 though if nothing else is connected.

There will be a couple of downside to this as there always is in engineering.

Firstly the 12ohm resistor will cause the cap to charge slowly. You can work out the charge time using the R-C time constant: t = R x C = 15 x 0.0047 = 0.0705. Use 3 time constants to estimate the charge time so you get around 0.2s.

Second, once the cap is charged, the series resistor, plus the 330ohm & LED form a voltage divider. If you have around 2V across the LED, you then have 5 - 2 = 3V acros the divider. So you get 3 x 330 / (330 +15) = 2.87V. Add back in the 2V & you haVe around 4.87V max. You can check this because the A0 measurement will tell you.

Hope it works. Isn't analogue fun. So many sums for so few components.



Thanks for all the help guys. I decided against a voltage sense circuit to use a simpler latch circuit (4x N-Channel MOSFETs, some resistors and a filter capacitor) to simply power down gracefully instead of measuring voltage drain to determine "now is a good time to shut down"