Capacitance Measurement With The Arduino Uno

CapTestBoard1

Have you ever found the need to measure the capacitance of a capacitor? No multimeter handy (for shame)? Well, as it turns out you can actually measure capacitance using your Arduino Uno, with no external components, and only ~20 lines of code.

[Jonathan Nethercott] does an excellent job explaining a capacitance test circuit which uses a reference capacitor to calculate the unknown capacitance. He further explains that, with the Arduino Uno, you can remove the reference capacitor from the circuit, and simply use the stray capacitance present in the board and microcontroller, which can be calculated. This results in the test circuit being as simple as plugging in your capacitor to pins A0 and A2.The code is quite simple: it sends a 5V pulse to the capacitor and measures the voltage on the other side, looping every half second, and outputting the data onto a chart.

It does, however, require calibration. [Jonathan] measured a known capacitor for a baseline, and used that data to calculate the stray capacitance in the Arduino. Once calibrated, he found that you can easily achieve a resolution of about 1% for capacitors between 3.5pF and 225pF, and around 5% for capacitors between 0.5pF and 1300pF — you can see the results of his analysis here. He plans on determining the accuracy and linearity too, but he will need some very accurate reference capacitors.

25 thoughts on “Capacitance Measurement With The Arduino Uno

    1. I was exactly thinking of that. The CapSense library on Arduino on which I’m working for two days (not enough precise for me) works the same way than this script (sort of…) but uses digital pins.
      Know I want to try with this new script ;)

    1. I think the internal pullup is about 30k, so yes that should work for capacitors between a few nF and a few uF. Getting a range of less than 1pF to more than 10uF with no external components would be pretty cool. I’ll give that a go when I get a chance… Thanks.

  1. The optimum lies in the 10-100pF range … which means you can use this technique to measure capacitive humidity sensors directly. You could even make them on the PCB as traces without solder resist.

    1. Minor suggestions for larger capacitors:
      – it might be better to sample until a certain threshold charge has been met and use the time constant to calc the capacitance.
      – alternatively, you could sample 16 values in a loop, fit the ideal curve and extract the C value. This should improve the resolution.

  2. Does anybody know how to do this for inductance? I have a Sparkfun capacitance meter which is based on a PIC and I would imagine probably works similarly to this Arduino solution. I can’t seem to find an inexpensive inductance meter that actually works though.

    1. Look for a (insert unknown brand name here) 4070L. They can be had cheaply from Amazon and Ebay, and will measure from about 50 uH to over 10 H, in theory. In practice it does a decent job on medium size inductors but isn’t precise enough to measure the really small stuff. It also measures resistance, capacitance, and includes a transistor checker. Currently $15 on Amazon:

      http://www.amazon.com/Hiyadeal-Inductance-Capacitance-Resistance-Meter/dp/B008QKJOCQ/ref=sr_1_3?ie=UTF8&qid=1390494536&sr=8-3&keywords=lcr+meter

      1. To elaborate, the total amount of energy in this case is C*U*U/2 = 0.0001*20*20/2 = 20 mJoule. Doesn’t sound like a big deal but this energy is delivered in a very small window of time and is dumped on relatively small microelectronics structures.

        The energy is dissipated by the ESD protection diodes, they redirect the current to VCC and limit the input logic to VCC+0.6.

        The behavior of protection devices is characterized in TLP (Transmission Line Pulsing) measurements and qualified in MM (Machine Model), HBM (Human Body Model) and CDM (Charged Device Model) tests that subject the device to a standardized setup that mimics real-world scenarios. For AVR you can find some numbers here:
        http://www.atmel.com/images/doc1619.pdf
        http://d1.ourdev.cn/bbs_upload782111/files_1/armok0117484.pdf

        Hooking up a charged cap like in this scenario bears close resemblance to two kind of tests: an MM test and a surge immunity test. The transient in our case will be in the ~µsecond or even 10µsec range – an order of magnitude longer than MM and as such worse. ATmega8 can suppress up to 400 in MM, which boils down to a whopping 16µJoule of energy per pulse. From whatever I can find on the internet they also test for Fast Transient Burst – bundles of 75 pulses totaling in the area of ~10mJ over a 15 ms dissipation time. The prolonged dissipation time (there are pauses between the pulses) is something that renders it incomparable to this question. Surge immunity tests are only done on power supply lines, not IO, so I can’t translate to this case.

        All tests you’ll find that qualify the IO lines wrt to pulsed overvoltage abuse are at least 1 order of magnitude lower than the scenario we’re dealing with here. And those are upper limits or limited to power supply. So yes, the input protection will go poof. It’s quite possible, though, that the damage will be restricted to the protection diodes and the logic will continue to function until the next minor pulse comes along (e.g. when you remove the cap and touch the wires).

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.