Arduino Based Capacitance Meter

Thirty five years ago I made a capacitance measuring meter from an article in 73 magazine. It’s built into a metal recipe card box about 3″ by 5″ and uses a timer chip similar to a 555 in different frequency ranges to apply AC to the capacitor under test. A microamp meter measures the current passed. Simple but each range has a separate pot for calibration. There’s two 9 volt batteries that seem to always be dead when you need the meter. It’s so old the Sharpie markings have faded out.

The 35 Year Old Capacitance Meter

The 35 Year Old Capacitance Meter

Some time ago I built a prototype water level sensor that uses the fact that water has a very high dielectric constant. Immersing a capacitor in water should result in a significant increase in capacitance. I’ve been looking for a reliable capacitance measuring circuit ever since.

I found an article on the Circuit Basics weblog that analyzed and tested three different Arduino techniques. They found the most promising method was a sketch from the Pic Tutorials web site in the UK. Test results indicated a range from a few picofarads to 1000 microfarads.  Best of all, it uses no external parts! Just two wires connected to the Arduino A0 and A2 pins. So this created a diversion from the water level project – building a stand alone C meter.

I tested the sketch on a Diavolino and on a 3.3 volt Pro Mini and it worked well. I adapted the code to output to a 16×2 LCD then started the build in an SAE (Standard Arduino Enclosure, Altoids tin) with selecting a pair of banana jacks from the junk box for the measurement connection. I spaced the jacks so I could use a standard two pin banana plug if needed, then discovered I didn’t have quite enough room to fit in the LCD.  I wish somebody would make a 3.3 volt, 3/4 size 16×2 LCD. So.. I ordered a 128×64 OLED display from Adafruit. It cost twice as much as an LCD but would fit easily and could display more information.

Locating the Adafruit OLED on the Altoids lid

Locating the Adafruit OLED on the Altoids lid

With the small display size, there would also be room for a couple of slide switches in the lid. While waiting for the OLED to arrive I parted out a small phone charger pack. Most of these contain a single 18650 cell and a small PC board with a charger and boost converter.  I’ve used them before, they are sometimes on sale for as little as $2.  The main problem is creating a hole for the USB jack and firmly attaching the PC board to  the box. The holes are a drill and file exercise. Here you can see the board is tack soldered at the top of the micro connector and at the side of the USB A jack.

Soldering Salvaged Charger Board Into the Altoids Tin

Soldering Salvaged Charger Board Into the Altoids Tin

I brought out the boosted five volt leads but since the final build is all 3.3 volt parts, did not use them.  The 18650 itself is fastened by a soldered tin strap. I also squirted in a bit of RTV sealant to make sure there would be no movement. Both plus and minus tabs are insulated with Kapton tape as I did not want the SAE to be grounded in this design.

Soldered Tin Strap Restrains the Battery

Soldered Tin Strap Restrains the Battery

The OLED is held in the lid by four screws and the Sparkfun Pro Mini is mounted directly on the back of the OLED by a five pin header soldered into digital 2, 3, 4, 5 and 6. These make the Data, Clock, D/C, Reset and Chip Select connections. Two wires complete the OLED power and ground – orange and green in this photo.

Showing How Pro Mini is Attached to the OLED

Showing How Pro Mini is Attached to the OLED

This is a top view of the arduino/OLED assembly. You can see power and ground wires on the right and leads to the A0 and A2 pins on the left. These are all that are required for the sketch to measure capacitance!

The Pro Mini/OLED Sandwich

The Pro Mini/OLED Sandwich

First trial with the measurement sketch. Very happy with the result.

First Test with 18650 Battery

First Test with 18650 Battery

Now to put it into the SAE. A rectangular opening was cut in the lid with a Dremel cutoff wheel, filed to fit. A thin plastic layer fits across that opening to protect the OLED, and four #2 screws attach the assembly.  Two DPDT slide switches fit between the Pro Mini and the measurement jacks, one switches the power leads between charger and the Arduino, the other switches the measurement jacks between capacitance pins and future resistance measuring pins. The black heat shrunk object is a 3 amp fuse.

Box Interior

Box Interior

Here the device is powered up from it’s internal battery and measuring a capacitor marked 4n7. Close enough for me.  I have a few 1% capacitors and did better calibration later on in the build.

Working with Capacitance Sketch

Working with Capacitance Sketch

Measuring resistors with an Arduino is a well developed application. Construct a divider with a known resistor and the part to measure, then use an analog input to measure voltage at the junction.  I did a spread sheet analysis of quantization errors with this technique. The calculated value can be off a lot if the measurement is anywhere near the limits of the A/D reading. My code keeps the analog reading near the center by using four resistance ranges in the known part of the divider. 100 Ω, 1000 Ω, 10,000 Ω, and 100,000 Ω. This should give repeatable measurements from 10 ohms to 1 meg ohm.

Working in Resistance Measuring Mode

Working in Resistance Measuring Mode

I also added a 10k/10k divider between power and ground of the Pro Mini. This is connected to A3 to monitor battery voltage. In this photo you can see some of the resistor measuring tree tucked under the left end of the board.  The 100 Ω resistor between 11 and 12 is used to sense ground on the measurement jacks because I didn’t have a free contact on the R-C switch to tell the processor which mode it’s in. I look for a hard ground on the negative measurement jack to indicate R mode (thin blue wire). Pin 11 goes high to apply a strong pull up to pin 12 .

Note: V1.1 The sense resistor is revised to 200 Ω and connected to A7 instead of D12. This allows detection of ground in 5 milliseconds instead of 100 with no overload on the digital pins.

Pro Mini with Battery Monitor Divider and Resistance Range Tree

Pro Mini with Battery Monitor Divider and Resistance Range Tree

I calibrated with a handful of precision caps and some 3% resistors from Frys.

Calibrating

Calibrating

This is the “Calling It Done” shot. Resistance and capacitance measuring is working, that cap is marked 330 uF but that’s near the end of analog measurement range. The circuit is not very accurate above 200 uF.

Current drain with the display as pictured is about 12.5 milliamps,  a full charge on the 18650 should run the device for a week.

Final R/C Meter

Final R/C Meter


Update Jan 29:  

Added code to check battery voltage and display an on screen alarm if less than 3.0 volts. That’s complicated because the reference for analogRead by default IS the battery, which doesn’t matter to the resistance or capacitance code because they measure a ratio not an absolute voltage. So… VREF has to be switched to the stable internal 1.1 volt supply and it turns out, that’s not a straight forward process. The Arduino.cc page on analogReference says: “After changing the analog reference, the first few readings from analogRead() may not be accurate.” You have to do an initial dummy analog read to get the change started then delay at least 5 millisec for an internal capacitor to equalize.

The battery measuring voltage divider is changed to 39k on the RAW pin and 10k to the ground pin. That puts the divided voltage in range of the INTERNAL reference.


Update Jan 31:

Banana jacks and alligator clips work great for leaded parts but surface mount, not so much. I made an adapter to make it easier to measure those tiny capacitors and resistors. An old ISA prototype card was sacrificed, (didn’t think I needed one of those these days), the fingers are about the right spacing and they’re gold plated. I cut out a small section and  firmly bolted it to a two prong banana test plug.

Surface Mount Adapter

Surface Mount Adapter

 

The small bit of epoxied on wooden coffee stirrer makes a fence to help corral the part. You place the surface mount component across two of the fingers and press down with a toothpick to do a reading. One contact finger is skipped at the right end to make a wider spaced dock for larger components like electrolytic caps. In this shot I got lucky, the capacitor stayed contacted after I released the toothpick.

Adapter in Use

Adapter in Use

Now I have to find enough pill containers to sort the hundreds of surface mount parts I’ve salvaged. That will have to wait until garage sale season.

 

If you are interested, you can download the sketch and a schematic from Dropbox.
25 Jan 2019   Version 1.0 Initial build.
26 Jan 2019   Version 1.1 Changed R-C mode detect to an analog reading.
Pullup resistor increased to 200 Ω, detect time reduced to 5 Ms.
29 Jan 2019   Version 1.2 Added code to read batt voltage and alarm if < 3V

  1. Nice work, having built it yourself you’ll u derstand its measurement limitations, not that they are at all significant.

    • Yeah, capacitors are seldom critical. I am more interested in repeatability than accuracy for the sump pump water level project.

    • Ralph J Boumenot
    • January 29th, 2019

    It continues to amaze with what you stuff into an old mint tin.

  1. No trackbacks yet.

Leave a Reply

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

WordPress.com Logo

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

Google photo

You are commenting using your Google 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 )

Connecting to %s

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

%d bloggers like this: