Capacitance Meter

35,125

444

39

Introduction: Capacitance Meter

About: I study (civil) electronics engineering at the VUB in Belgium. I have a passion for making things, both useful and cool.

Capacitors are vital components in electronics, but sometimes they are broken, or the value printed on the cap has become unreadable. Because my multi-meter does not have a capacitance measurement, I decided to make one!

The principle of measuring capacitance is quite simple. The voltage of a capacitor charging through a resistor increases with time T. The time it takes to reach a certain voltage, is related to the values of the resistor and capacitor. In this project, we'll use a 555 timer circuit as a monostable multivibrator. If that sounds like some dark magic to you, don't worry, it's quite straightforward. I'll refer to the the Wikipedia page for the details, as we'll focus on the things we really need: the schematic and formula. The time in which the capacitor C charges through the resistor R is given by: T = ln(3) x R x C = 1.1 RC. If we know the value of the resistor and the time, we can calculate the capacitance: C = T / 1.1R.

Now we need a device for measuring the time, and that is where the Arduino comes in. The time is defined by the state of the output pin of the 555 timer (pin 3). It will be HIGH when the capacitor is charging, and LOW when it's not. This means the output generates a pulse with length T.
The Arduino will be connected to pin 3 and will be detecting the rising and falling edge (transition form 5V to 0V and vice-versa). By using the function micros(), we'll know how long the pulse is, and we'll calculate the resistance.

The value of the resistor can be chosen freely. We'll take 1 MOhm for measuring low capacitance (nF range), and 10kOhm for higher capacitance (uF range). Otherwise, measurements in the uF range would take ages.

Finally, the value of the capacitor should be displayed on a screen; I chose a 4-digit 7 segment display. Those displays need a lot of inputs, so we'll multiplex them to resolve this issue. Basically: we'll drive the displays one by one, but so fast that the human eye cannot notice. We'll also use a shift register to further decrease the number of Arduino pins we need. The shift register will read the data from the Arduino over 2 wires, and then drive the display through 8 wires. This is well explained here: https://www.instructables.com/id/Multiplexing-with-Arduino-and-the-74HC595/ .

I used an ATTINY 84 instead of a full-size Arduino uno, to save some space. For a detailed guide on how to program those, take a look at this great 'able https://www.instructables.com/id/Using-the-Arduino-Uno-to-program-ATTINY84-20PU/ . It's also possible to use a bare-bone Arduino by only using the chip.

Ultimately, to power the build, I used a 9V battery and voltage regulator (LM317).

Step 1: Parts List



• IC's


• ATTiny 84 or 44 (16 pins)
• 555 timer chip
• Shift register (74HC595)
• 5V voltage regulator (LM7805) or LM317



• Resistors


• 220R x9
• 470R x4
• 10k x3
• 1M
• 1k (only for LM317)
• 330R (only for LM317)



• Capacitors

• 100nF x2
• 1uF (only for LM317, 100nF otherwise)
• Random for measuring



• Other

• Red LED
• 4-digit 7 segment display (common cathode), or seperate units with 1 or 2 digits
• NPN transistor x4
• Pushbutton
• DPDT switch
• 9V battery connector
• 9V battery





Total price < €10

Step 2: Code, Build & Test

The code is quite easy and small enough to fit on an ATTINY 44 or 84. If you want to make some modifications, be sure to keep the size in mind, as the ATTINY 44 can only store 4kB.

The loop does 3 things:

  • Detects when the output pin of the 555 timer goes HIGH, records the time and resistor value
  • Detects when the output pin goes LOW, records the time
  • If the pulse is over, calculates C and displays it

To display the number, it is first spliced into digits, and then displayed one by one. This is achieved by sending the right code to the shift register and activating the corresponding transistor, to allow the current to drain through the desired display digit.

The bytes for the numbers, defined at the beginning of the code, can be determined with the drawing of the digit. The reason I opted for this numbering scheme, which may seem quite strange, is because it was the easiest way to wire everything. I simply put the shift register next to the display and connected the adjacent wires. If your display has a different pinout, it may be handy to change the numbering scheme, and bytes.

For determining the resistor value, a 2-pole switch is used. 1 pole switches the resistor from 10k to 1M, while the other pole switches from 0V to 5V respectively. This logic level can be used by the Arduino.
We'll also light an LED while measuring.

The trigger for the 555 timer, is generated by the pushbutton. The pin is held HIGH by a pull-up resistor, pulled LOW by pressing the button, then goes HIGH again. This is the trigger for the 555 timer to start the measurement.

Try the circuit on a breadboard first, and assure it's working. You may need to change the internal clock to get the right value. When using the wrong MHz setting, your results will be completely wrong.

Now it's time to solder everything on a perfboard. Simply replace the capacitor indicated with "???" by some female header pins, so it's easy to insert the capacitors. Making your own PCB is also perfectly possible, I included the file with the schematic in Fritzing. After that, the only thing left to do is measuring some capacitors!

My results were quite accurate and it works great. For even more accuracy, you could use an external crystal instead of the built-in clock of the ATTINY or ATMEGA chip. One more thing would be the use of interrupts to detect the rising and falling edge, but I couldn't get that to work on the ATTINY. If you know how it's done, feel free to leave it in the comments!

To start a measurement, insert the capacitor in the header pins (remember to respect the polarity when measuring electrolytic capacitors), set the measuring range (with the 2-pole switch) and press the pushbutton.
Enjoy your home-made capacitance meter!

Share

    Recommendations

    • Creative Misuse Contest

      Creative Misuse Contest
    • Fix It! Contest

      Fix It! Contest
    • Water Contest

      Water Contest

    39 Discussions

    ehm 7segment LED with common anode? connected to NPN transistors -> to ground??? maybe COMMON CATHODE omg.

    1 reply

    Sorry if my typo hurt your feelings, mister perfect

    Hi! I been working on this one now. But well I decided to use a full arduino since programing my Atmega 8 takes a lot of time setting it up. Now, where are the pins associated from the attiny will be on the arduino?

    Although I found the analog pins from both of them but still, I don't know if I connect the pins right. My meter won't work.

    3 replies

    In this pinout diagram you can see which pins of the atmega328p (the one most commonly found on arduino uno boards) correspond to the pins you use in the code. Good luck!

    Chip-Atmega328-pinout.png

    Do you use any analog pins? In attinys, a digital pin can be a analog pin, like "pin 0" to "pin 7" from attiny 84.

    Although I found out that the code only uses the pins as digital

    Hi, thanks for the feedback.

    I looked into your remarks, and apparently I made some mistakes in the schematic.
    Pin 10 of the 595 needs to be connected to Vcc and pin 13 to GND indeed.
    As for the 7 segment display, the actual pinout is in the figure, but I will correct it on the schematic. This was a tricky component because the physical pins will map differently to the display segments for other types of 7 segment display.
    The switch I used was a DPDT, as can be seen in the parts. To avoid a cluttered schematic I used 2 switches instead.

    The 2313 would be a great idea, but my electronics store didn't have them so I went with these components.

    I hope you liked the build :)

    Hello!
    Built it and fixed a couple of mistakes.
    First of all, for the circuit to function you need to tie 595's OE (13) to ground and MR (10) to VCC. Without that, it didn't function for me and it doesn't seems it'd function for you either.

    Second thing - some disambiguation about 7-segment wiring would be great, both in the firmware and on the wiring diagram - they do not correspond to each other. Hardware diagram describes tgfedcba layout (t is the dot), but in the firmware it's btcgdeaf =) (I mean, there's no way dot bit mask is B01000000 if the dot is connected to Q0 of 595.) I understand it's hard to explain how exactly this part has to be suited to wiring choices made, but it's worth a mention because it's one of problems people will likely encounter.

    Third thing - there are actually 2 2-pole switches in the schematic, one connects the range resistor and one "tells" the MCU which of the resistors is connected (resistorPin). It even makes sense to use a DPDT, so you only use one switch for range changing instead of two.

    Other than that, great device! You could optimise some operations to make it fit on a 2313, since it's cheaper and more accessible (you could also use additional pins and add a crystal), but it's great this way too. Thank you!

    It just means that R4 and R5 are both 10k ohm.

    Hey pretty damn awesome!!! I'm looking forward to build this on my birthday (which is TWO DAYS from now!) and I think I'm having problems with that Attiny IC.

    Can I use Attiny2313 instead? Although this might not work (is does not have ADC for analog) Well, we can have the ATMega, but what code it should have? (ATMega8L, 128, 169, etc, you get the picture...)

    I hope my local store called "Alexan" has Attiny44/84 so the problem's solved. ;_;

    1 reply

    Thanks! The Attiny 2313 has not enough memory for the program, the 4313 should work; because you don't need the ADC. I wish you good luck with the build and a happy birthday :P

    There's a 1µF capacitor in the parts list, but nowhere in the schematic.

    1 reply

    Hi. Just curious as to what the range of capacitance you can measure with the design as it is? I'm especially wondering about the low end. I know that you cannot make the charge resistors (R2 and R3 in your circuit) arbitrarily large, because the 555 needs to have some minimum currents into pins 2, 6, and 7.

    3 replies

    It works from 9999uF (limited by the display) to about 10nF. When I go lower than that, the pulse becomes too short to detect reliably. I guess 10M Ohm would also be possible, but I don't need those low caps very often.

    Thanks, Thomas. 10nF is 0.01uF, which is actually a pretty big cap. I guess that is not surprising for this 555-based concept. For measuring smaller capacitors, in the 10pF to 1000pF range, some other technique would be needed. Anyway, this is an interesting Arduino project. Thanks for posting it.

    It was just about the accuracy. Measuring lower capacities was possible, but not as accurate. I just tried with a 10M Ohm resistor, and that worked fine in the 10pF range. So you can easily adjust that if you want :)

    0
    None
    mauG

    2 years ago

    Very interesting