Capacitance Meter

2.5K238

Intro: Capacitance Meter

This instructable describes how to measure the value of an unknown capacitor using an Arduino Uno R3 and a resistor.

The circuit is unusual in that it uses the Arduino interrupt to determine the capacitance.

A wide range of capacitance values, from zero picofarads (pF) to microfarads (uF), may be measured using a single resistor.

To reduce the time to measure large capacitors the meter has two capacitance ranges:

  • below 1uF
  • above 1uF

Construction is simple.

Accuracy is excellent.

Excluding the Arduino, the cost of this project is less than $10.00.

Images

  • The cover photo shows how the meter is constructed.
  • The video demonstrates the meter in operation.


STEP 1: Circuit

Operation

The capacitor under test is connected between interrupt pin2 and ground.

The 10M ohm resistor is for capacitance values less than 1 microfarad. When the switch is open the capacitor is charged via the 10M ohm resistor.

The 10K ohm resistor is for capacitance values greater than 1 microfarad. When the switch is closed the capacitor is charged via the 10K ohm resistor.

At some point in time the voltage across the capacitor will trigger the Arduino interrupt.

The capacitance value is directly proportional to a fixed fraction of the elapsed charge time. The capacitance formula is derived in the Theory section which follows.

The 270 ohm resistor limits the peak discharge current to a safe value of 18.5 millamps


Construction

Photo 2 shows how the components are wired to a pair of Arduino header-strips.

  • One end of each resistor is connected to Ardino pin 2.
  • The other end of the 10M ohm resistor is connected to Arduino pin D8.
  • The other end of the 10K ohm resistor is connected to Arduino pin D9.
  • The other end of the 270 ohm resistor is connected to Arduino pin D10.
  • The switch is connected between Arduino pin D11 and ground.
  • The test leads are connect to Arduino pins D2 and ground.

STEP 2: Theory

When a capacitor is charged via a series resistance the instantaneous voltage across the capacitor may be found using the following formula [1]

v = Vin*(1-e^(-t/CR)) …………………………………………. (1)

where:

  • v = instantaneous capacitor voltage
  • Vin=applied voltage
  • e=2.7182818284590452353602874713527
  • t=time in seconds
  • C= capacitance in farads
  • R=series resistance in ohms


When the exponent t/CR = 1 the capacitor voltage is:

v = Vin*(1 – e^(-1))

v = Vin*(1 – 0.368)

v = 0.632 * Vin


Rearranging t/CR=1 we get

C=t/R ………………………………………………………….... (2)


Polling Method

Equation (2) can be used to calculate the value of an unknown capacitor if we continuously sample (poll) the capacitor voltage with an ADC (analog to digital convertor) and note how long it takes for the capacitor voltage to reach 63.2% of the applied voltage.

For large value capacitors this method is reasonably accurate, as the polling loop-time is a small fraction of the capacitor charging-time which means the error is small.

But for small value capacitors, which charge quickly, the fixed ADC loop-time becomes a large fraction of the capacitor charging time which means the error can be large.

The following method eliminates polling which means that low value capacitors can be measured accurately.


Interrupt Method

Instead of polling, I use the Arduino interrupt to detect when the capacitor becomes fully charged.

In theory a capacitor may be regarded as fully charged when t/CR = 5

v = Vin*(1 – e^(-5))

v = Vin*(1 – 0.007)

v = 0.997 * Vin


Rearranging the exponent we get

C = t/(R*5) …………………………………………………...….. (3)

where

  • C = capacitance in farads
  • t = elapsed charge time in seconds
  • R= series resistance in ohms


In practice the Arduino interrupt will trigger at a lower voltage in which case equation (3) becomes:

C = t/(R*Constant) ……………………………………………… (4)

where

  • C = capacitance in farads
  • t = elapsed charge time in seconds
  • R= series resistance in ohms
  • Constant between 0..5 (determined experimentally)


A typical value for the Constant is around 0.8.


Examining equation (4) we see that the capacitance C is directly proportional to a fixed fraction of the elapsed time.

To calibrate we simply connect a known value of capacitance between pin 2 and ground and adjust the numeric Constant value for a correct capacitance reading.

Since the interrupt trigger level and series resistance don’t change, the Constant is valid for all capacitor measurements.

This allows capacitor values from zero picofarads (pF) to several hundred microfarads (uF) to be measured using a single resistor.


Observation

When measuring small capacitance values, a large series resistance improves the resolution by extending the trigger time.

Unfortunately, this also extends the time to measure large capacitors. This time interval can be reduced by using a lower value resistor. In my circuit this is achieved by means of a switch connected between Arduino pin 11 and ground.


Reference

[1]

https://mechatrofice.com/circuits/charging-capacitor-derivation

STEP 3: Software Installation

Method:
  •  Download the attached file “capacitance_meter.ino”
  • Copy the contents into a new Arduino sketch. (Use a text editor such as Notepad++ ... not a word processor.)
  • Save the sketch as "capacitance_meter" (without the quotes)
  • Compile and upload the sketch to your Arduino.

STEP 4: Calibration & Measurements

Low value capacitors

Step 1

  • Open the switch

Step 2

Zero out the system time

  • Change code line 95 to read: Time_taken = Stop_time – Start_time;
  • Upload the code change to your Arduino
  • Disconnect the capacitor
  • Open your Serial Monitor at 115200 bauds
  • Note the Time_taken value shown in microseconds … let’s assume it’s 320us [1]
  • Change code line 95 to read: Time_taken = Stop_time – Start_time – 320;
  • Upload the code change to your Arduino
  • The Time_taken value should now show 0us with the capacitor disconnected

Step 3

Adjust the Constant

  • Connect a 150nF (nanofarad) capacitor between Arduino pin2 and ground. [2]
  • Change the numerical value of Constant_10M in the header section until a reading of 150nF is displayed.
  • Replace the capacitor with one you wish to measure ... the new reading is the value of the chosen capacitor


Large value capacitors

Step 4

  • Close the switch.
  • Repeat steps 2 & 3 but this time change the equation in code line 120 and the value for Constant_10K in the header.


Notes

[1]

The Arduino system timer uses a 32-bit register so a number such as 4294967294 equates to FF FF FF FE in hexadecimal which is -1 decimal in two’s complement arithmetic.

If you see a large number, such as 4294967294, change the code line to read

Time_taken = Stop_time – Start_time + 100;

Upload this new code to your Arduino and note the reading … let’s assume that you see 60us

Subtract this new reading from 100

100-60 = 40

Change the code line to read

Time_taken = Stop_time – Start_time + 40;

Upload this new code to your Arduino … the Time_taken value should now show 0us with the capacitor disconnected.


[2]

The actual capacitance value used for calibrating is not critical providing you know its value.

STEP 5: Summary

This instructable describes how to measure the value of an unknown capacitor using an Arduino Uno R3 and a resistor.

The circuit is unusual in that it uses the Arduino interrupt to determine the capacitance.

A wide range of capacitance values, from zero picofarads (pF) to microfarads (uF), may be measured using a single resistor.

To reduce the time to measure large capacitors the meter has two capacitance ranges:

  • below 1uF
  • above 1uF

Construction is simple.

Accuracy is excellent.

Excluding the Arduino, the cost of this project is less than $10.00.

  Click here   to view my other instructables.


6 Comments

Dear Lingib,
Thanks for the clear and easy to follow instructable! I like the simple
circuits, but I suggest to add few more parts to protect ports of Arduino. You discharge
the capacitors for 0,5 sec, then charge them with 5V for 0,1 sec without any
current limiter. To charge and discharge capacitors (especially big capacitors)
without current limiter can burn out the ports of the controller. Theoretically the
current would be infinity. Of course, the internal resistances and the USB power
source will reduce the current. The UNO is quite durable, but e.g. the Nano
much less so. The solution for discharging is simple: just connect a resistor (e.g.
110 Ohm) between A0 and A3; another between A2 and A4, then discharge the capacitors
with LOW A1, A3 and A4. It will be safe. Have a nice coding! Gyuri
Hi Gyuri,
Thank you for your comment :)

I think your post refers to my instructable https://www.instructables.com/Simple-Capaitance-M... ... if you check Step 1, Operation, in this instructable you will see that I say "The 270 ohm resistor limits the peak discharge current to a safe value of 18.5 millamps". But I take your point.

My thinking when designing my "simple capacitance meter" follows:
According to the ATMeg328P datasheet the output voltage at 85C falls to 4.3 volts when sourcing 20mA continuous. This infers an internal resistance of (5-4.3)/0.02=35 ohms which means the peak short circuit current is in the order of 5/35=143mA. Since my circuit has a 1:5 duty cycle the average current will be 143/5=28.6mA which is within the 40mA continuous sink/source current rating for an I/O port.

Some further thoughts ... any heating effect should be negligible. The capacitance of two series connected capacitors is always less than the smallest capacitance which means the circuit, worst case, comprises a 10nF capacitor in series with a 35 ohm resistor regardless of the size of the capacitor under test. In practise the charging current in an RC circuit stops after 5 time constants which means we only have current flow for 1.75us.

Connecting each of the capacitors to individual discharge resistors, as you suggest, would definitely ensure that the discharge currents remain within safe limits.

To be absolutely safe we would also need to restrict the charging current. Since the capacitors don't need to be fully charged ... we just need the voltage ratio ... this could be done by charging the series-connected capacitors via a separate resistor and measuring the voltage across each capacitor using two ADCs .

To date I've had no problem with my current circuit but appreciate your suggestion and will experiment with this alternate design.
Regards
Lindsay
I applaud your effort, your knowledge, and your skills. A simple 555 timer IC in monostable (one-shot) mode can also indicate the value of a capacitor by counting seconds until the capacitor reaches 2/3 of fully charged. Specific resistance ranges can be selected for reasonable ranges for counting the number of seconds the IC is “on.” And, a 555 costs much less than an Arduino. Some have made capacitance meters using a 555 timer IC in astable mode and paired with a multi-meter for the readout.
Thank you for commenting :)
There are many circuits for measuring capacitance.
The method outlined in my instructable is different.
For someone with an arduino the cost is a few cents for the resistors and header pins.