# Capacitance Meter Based on Arduino

This project shows how to build a capacitance meter based on Arduino board where the value of capacitor capacitance is displayed on 16×2 LCD screen and on the laptop through serial monitor software (for example Arduino IDE serial monitor).

Working Principle:
When a capacitor is connected in series with a simple resistor (series RC circuit) and by applying a certain voltage VS, the capacitor voltage VC increases exponentially towards VS according to the following equation:

RC Called time constant (Tau) which is time when VC = 0.632VS where R is in Ω and C in Farads.
So, from the previous function, if we know VS, VC, R and t we can calculate the value of C.

The Arduino microcontroller ATmega328P (uno, Nano, Mini …) has a built-in analog comparator which will be used in this project to detect the voltage of the capacitor when it goes above VS/2 (approximately 2.5V).
When VC = 0.5VS the capacitance value C = t/[R x ln(0.5)]
Timer1 module is used to count time t between VC = 0 and VC = VS/2.
To get a voltage of VS/2 we may use voltage divider using 2 similar resistors.

Project Hardware Required:

• Arduino board
• 1602 LCD screen
• 2 x 4.7k ohm resistor
• 100k ohm resistor
• 10k ohm resistor
• 1k ohm resistor
• 220 ohm resistor
• 330 ohm resistor
• 10k ohm variable resistor or potentiometer
• Jumper wires

Arduino capacitance meter circuit:
Project circuit diagram is the one below.
warning: the capacitor should be fully discharged before placing it in the circuit!

The circuit shown above is for an autoranging capacitance meter, the capacitor under test is connected to the Probes terminals + and . The terminal is directly connected to Arduino GND pin.
The capacitor under test is charged using one of the three resistors: 1k, 10k or 100k. The Arduino initiates the charging of the capacitor through one resistor according to its capacity. The 220 ohm resistor is used for discharging the capacitor.

With these resistors the Arduino outputs a maximum current of 5/1k = 5mA (while charging the capacitor) and sinks a maximum current of 5/220 = 22.7mA (while discharging the capacitor).

The reference voltage (approximately 2.5V) comes from the 2 x 4.7k resistors voltage divider, it’s connected to Arduino digital pin 6, this is AIN0 pin of the Atmega328P MCU which is analog comparator positive input pin.

The capacitor positive terminal is connected to Arduino analog channel 5 (A5). This pin is used as negative input of the analog comparator and also to read capacitor voltage during discharge.

The 1602 LCD screen (2 rows and 16 columns) is used to display temperature values in degrees Celsius and degrees Fahrenheit where:
RS —> Arduino digital pin 2
E   —> Arduino digital pin 3
D4 —> Arduino digital pin 4
D5 —> Arduino digital pin 5
D6 —> Arduino digital pin 8
D7 —> Arduino digital pin 9
VSS, RW, D0, D1, D2, D3 and K are connected to Arduino GND,
VEE to the 10k ohm variable resistor (or potentiometer) output,
VDD to Arduino 5V and A to Arduino 5V through 330 ohm resistor.

VEE pin is used to control the contrast of the LCD. A (anode) and K (cathode) are the back light LED pins.

Arduino capacitance meter code:
Hints:
Capacitor discharge pin is Arduino analog pin 1 (A1) and it’s connected to the capacitor positive terminal through 220 ohms resistor. Capacitor charging pins are A2, A3 and A4 and they’re connected to the capacitor positive terminal respectively through 1k, 10k and 100k. All those pins are defined in the code as shown below:

The 3 resistors (1k, 10k and 100k) are used in a table (array) of 3 elements as shown below:

At the beginning, the Arduino starts discharging the capacitor by writing logic low to discharge_pin until the capacitor is fully discharged through the 220 ohms resistor. While the discharge_pin is low, the ADC module keeps checking capacitor voltage (channel 5).

After the capacitor is fully discharged, the ADC module is disabled and analog comparator interrupt is enabled, a charging voltage is applied to the capacitor through one series resistor (1k, 10k or 100k) and Timer1 module starts counting until the analog comparator interrupt occurs. This interrupt tells the microcontroller that the capacitor voltage is approximately equal to the reference voltage which is equal to 2.5V.

So, we can calculate capacitance value since we know the values of the supply voltage (5V), series resistance (1k, 10k or 100k) and time.
Note that Timer1 module is configured to increment by 1 every 62.5 microseconds (prescaler = 1).

Full Arduino code:

The video below shows my protoboard circuit tests with some different capacitors:

Related Project:
Arduino Based Auto-Ranging Ohmmeter

### Discover more from Simple Circuit

Subscribe to get the latest posts sent to your email.

### 5 thoughts on “Capacitance Meter Based on Arduino”

1. Thanks

2. Thank you for this tutorial. I made it, but can’t measure capacitor 104 (100000pf). It came with 005pf as a result

3. Are you considering making an inductance meter?

4. nice application congratulations.

5. Can I use stm32f103 with this code?

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

Scroll to Top