# Not getting readings from capacitor

I'm trying to read capacitor output values as the cap discharges for a physics project, and am getting a high voltage while charging, but dropping to 0V 3000 $\mu$s after stopping the charging signal, which doesn't seem right.

Schematic:

The cap is 1mF, resistor 1k$\Omega$.

I'm trying to charge the cap by sending +5V out through the digital line for 2 seconds, and then trying to discharge by either switching the digital output line to high-impedance (by switching it into input mode, pinMode(DIGITAL_OUTPUT, INPUT);) or by writing a low signal (digitalWrite(DIGITAL_OUTPUT, LOW);).

I've tried both methods of triggering discharge, but the analog signal that I've read (analogRead(ANALOG_INPUT);) has gone from +5V while charging down to 0V 3000$\mu$s after. I was under the impression that the cap should take at least 2 seconds to fully discharge.

I assume I've messed up the circuitry somehow, and the code is actually working after enough debugging, so I haven't wasted space with 97 lines of code, but the code is in a pastebin if the circuit looks like it should work.

• Outputting a low doesn't result in a high-impedance connection. – Ignacio Vazquez-Abrams May 19 '14 at 23:41
• @IgnacioVazquez-Abrams Yes, I was saying that I tried both outputting a low and setting the pin to high-impedance in two different debugging trials. – Ryan Leonard May 19 '14 at 23:57
• @IgnacioVazquez-Abrams Changing the pin to INPUT should make it high-Z, drawing minimal current – EkriirkE May 20 '14 at 7:22
• @EkriirkE: That's correct. But some current will still leak though the S+H circuit of the analog input. – Ignacio Vazquez-Abrams May 20 '14 at 7:43

Are you sure the capacitor is 1mF (1 milliFarad) as opposed to the more common value of 1uF (1 microFarad). A 1 uF capacitor with a 1 K resistor would give you a time constant of 1000 us, so after 3000 us, you should expect to see a voltage of < 5%.

• Note that 1 mF capacitors are commonly labeled as 1000 uF. – Zuofu May 19 '14 at 23:40
• Looks like I mislabeled the components I got a few years ago. Popped in a 10uF resistor and it took a while to discharge. Now I need to figure out what these caps are... Hey, I just gave myself a good physics project! Thanks for the suggestion. – Ryan Leonard May 19 '14 at 23:53
• @RyanLeonard . Next time I need to discharge a 10uF RESISTOR, I am going to look you up. (Gentle reminder to review what you type. Others depend upon our accurate comments and answers.) – Marla May 20 '14 at 1:42
• @Marla Heh, I appreciate the reminder. I'd edit if I had a little more rep. – Ryan Leonard May 20 '14 at 12:52

A couple of things:

Is this a 1mF capacitor? That is, 1000uF? That's an awfully big one!

Put a resistor in series with your charging pin... like 10k. It will take some time to charge up, but it will lessen the effect if it's the digital pin causing the discharge to happen. You technically should have a resistor in there anyway, because there is nothing to limit the current rushing into the capacitor from the poor, abused microcontroller's digital pin.

Assuming your pin can handle about 20mA, the smallest resistor in any case should be 5v / 20mA = 250 Ohms. This will keep the capacitor from drawing too much current from the micro during the instant when the cap charging begins.

One thing you could try is to just touch the +5v line to the cap to charge it, then physically take it off, measuring the result. See if it's different than having the pin switch.

I was using a cap less than 10$\mu$F. Solved by replacing the "1 mF" cap with a 10$\mu$F cap. Oops!