Capacitance Measurement with the Arduino Uno


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.


  1. Jasper says:


  2. Hyratel says:

    if you don’t immediately try this with an arduino you have on your desk after seeing this writeup, i’m surprised

  3. F says:

    Possibly one could attach one of those tiny Arduinos right onto a pair of those cheap SMT tweezers? What about stray capacitance from the user’s hand, etc. ??? Could be very nice.

    • Shakipu says:

      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 ;)

  4. Scott says:

    You can use the internal pullup to charge a cap and time it.
    Should work for larger caps when this method peters out.

    • Jonathan says:

      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.

  5. juno says:

    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.

  6. cr0sh says:

    Or, you can make it test (nearly) anything:

    Note that the above (as it notes in the comments) is a port of this project (originally done using an ATMega8, if I read it correctly):

    If you are lazy, you can go on Ebay and find this tester being sold all over the place from Shenzhen vendors…

  7. Me says:

    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.

  8. Darren says:

    So what happens when that 100uf cap has a 20v charge on it? That can’t be too good for the arduino.

    • DainBramage1991 says:

      Always short the caps first, simple enough. It’s the same thing you should do with any other capacitance tester.

    • Rob says:

      No, it would not do the Arduino any good, but it would likely increase Arduino sales by one.

      • genki says:

        Where’s the like button? ;)

      • juno says:

        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:

        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).

  9. JimBob says:

    So where d do you get a precision cap for calibration?

  10. wail says:

    this is my first time i’ll by a microcontroller (arduino uno) and i’m a beginner.Please, would you mind telling me is good or not for me this arduino

  11. mahsa says:

    can arduino be used as a Measurment device for NFC devices?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

Join 96,382 other followers