Many multi meters (like mine) don't have the functionality of measuring capacitance. This is especially annoying as one has no way of determining how accurate a capacitor is. If you doubt your resistor you can easily measure it, but not so for the capacitor (if you have a multi meter like mine). So in this instructable I'm going to show you how to create a capacitance meter using an Attiny 85/45. This tester also has a 7 segment display to show the value.
Step 1: Components
• Attiny 85/45
• 4026 IC (for the seven segment display)
• 7 Segment display (common cathode)
• 7805 voltage regulator
• 470 E resistor
• 9V battery clip
• 2* 510 K resistors (basically requires 1M or slightly above. My 1M was of bad quality threfore I used 2* 510K resistor in series. If your resistor's value is different you will have to change code a directed in the upcoming steps)
• 1* N/C tactile switch (for reset which is optional)
• 1* N/O tactile switch (for discharging the capacitor which is also optional)
• 1* 100K resistor (as a pull down resistor. Even 10K would do the job.)
• 2* LEDs (different coloured)
• Arduino/Attiny programmer (for programming the Attiny)
• perf board
• bread board (for prototyping)
• stack headers (2 piece)
• A box for enclosing the circuit
Although this may seem like a long list the project's circuitry is very easy to follow and the parts are cheap as well. The project would have been easier if I used an Arduino, but would have been harder to make into a finished project, much more expensive and larger. The project cost me totally around Rs 200 (India). In US it will probably cost $7 or so.
NOTE: If you are going to be using arduino to upload sketches to Attiny 85/45 you will also need a 10 uF capacitor. An Attiny programmer makes uploading sketches much easier but you need to additionally buy it.
Step 2: The Working Principle
The working principle of the circuit is as follows:
The time taken for the capacitor to charge to 63% of the supply voltage is known as a RC Time Constant. (Refer to the accompanying graph)
The equation for RC Time Constant is:
RC Time Constant (in seconds) = Capacitance (in Farads) * Resistance (in Ohms)
Which means: Capacitance = RC Time Constant / Resistance
So, in essence, we charge the capacitor (through ATtiny85 digital pin) and measure the time taken to take it up to 63% of the supply voltage. That time is the RC Time Constant of the circuit. We already know the resistance, so from the above equation, we can find out the capacitance.
For example, if it takes 10 ms to charge the capacitor to 63% of the supply voltage, and if our resistance is 1MΩ then the capacitance can be calculated as:
Capacitance = 0.01 (seconds) / 1000000 (Ω) = 0.00000001 (F) = 10nF
In the actual code, you will see that I am charging the capacitor to a different value than 63% of the supply voltage (sometimes 22%, sometimes 86%). This corresponds to 0.25 RC Time Constant or 2 RC Time Constants respectively. If you want to know the reasoning behind this, please check the last step. Also, note that doing this is achieved through code and results in no change in the circuitry.
For more info please refer to this place
Step 3: How the Circuit Works and Setting Up the ATtiny85
The working of the circuit is quite simple. The ATtiny85 charges the the capacitor through the 1.02M resistor through D0. While charging, it continuously checks for the voltage across the capacitor by measuring the analog value at A1. It stops the charging once the charge reaches the desired percentage; and it measures the time required to do so.
Once the capacitance is computed, it finds out its order of magnitude (i.e. whether it is uF, nF or pF). For example, if the capacitance as 0.000000237, then it finds out the value as 237 and unit as nF. Then, since only one 7 segment display can be used (due to lack of available digital pins on the ATtiny85), it flashes the numbers 2, 3 and 7 one after another, while lighting up specific LED to indicate nF as the unit. (It lights up LED connected to D3 to indicate uF, D4 to indicate nF and no LED to indicate pF)
IC 4026 is used to drive the 7 segment display. When the 7 segment is connected to the IC as shown in the schematic and when a HIGH pulse is given to pin 1 (clock pin) the IC automatically shows the next digit (if the number shown is 0 when pulsed the number goes to 1). So if the Attiny wants to show seven it quickly pulses 7 times (if the number shown is 0). So, if currently it is showing 3 and the next digit to be shown is 7, then the ATtiny85 sends 4 pulses.
In order to program the ATtiny85/45 a few basic steps need to be taken. Please refer to the link below by MIT media lab:
or watch the below video on the programming by MAKE.
or watch the below video on how to make an ATtiny shield by Lyle Rodericks. (I personally used this one)
Step 4: Breadboarding the Circuit
Now to breadboard the circuit. Assemble the circuit as shown in the fritzing or eagle schematic. Use whichever schematic you find more convenient. As shown in the schematic the N/C switch is used for resetting the circuit. The other (N/O) switch is used for discharging the capacitor (It basically shorts the capacitor).
After that, upload the sketch given below. Also, if you happen to be using a different resistor please change the value of the resistance in line 6 of the code to your resistor in Ω. How to upload sketches to ATtiny is given in the previous step.
In order to test the capacitor, place the capacitor in the stack headers (make sure you place the capacitors in the right direction - if polarized). Then turn on the power. Keep in mind that when you connect the battery to the clip there might be some noise and the display might show random numbers, so it is a good idea to discharge (using N/O switch) and reset (using N/C switch). In fact, I highly recommend that you do so even if you don't actually see the noise.
Supposing you are testing a 10uF capacitor. Then for the first couple of seconds the display will show '0' (while the capacitor is charging), then once it is charged it will show '1' then two seconds later the display will whiz through and then show '0'. Also the LED connected to D3 (Red LED in fritzing) will light up. (The initial charging time can vary from under a second to a few seconds depending upon the value of the capacitor.)
Step 5: Perf Boarding and Enclosing the Circuit
Now, to make the project usable, cut the perf board to the dimensions of the your box. Solder all the components as shown in the fritzing/Eagle schematic. After you are done soldering the circuit on perfboard test the circuit out. Once you have it working, place the circuit in the box and cut out the holes required for the switches, the battery clip and the stack headers. Since my box was transparent I didn't need to make holes for the display and the LEDs. Once you have finished making the circuit, test it by inserting a capacitor in the headers. Switch it on. In my case it was a 100uF capacitor and so, after charging the display showed 1, then two seconds later whizzed through 1-9 quickly and settled on 0 and 2 seconds later whizzed through the numbers to show the last 0; while lighting D3 LED.
And that's it! It is a little bit annoying because you have to wait for a bit for the capacitor to charge, but never the less it works great and has a pretty good accuracy.
Step 6: Additional Info - Why We Don't Always Charge the Capacitor to 63%
As you saw in the step "The Working Principle" we don't actually charge the capacitor to 63%, we either charge it to 86% (2 Time Constant) or 22% (0.25 Time Constant). Let's see why it is done this way.
Say we are measuring a 100 pF capacitor with 1M resistor, then the Time Constant would be;
TC = 0.0000000001 * 1000000 = 0.0001 s = 100 micro seconds.
That means that in 100 micro seconds, the capacitor would be charged to 63% of the supply voltage. But ATtiny85 doesn't give accurate time measurement (using function 'micros') for such small values. In fact, the larger the duration, the more accurate the readings. So, instead of going up to 1 TC, we go up to 2 TC (86% of supply voltage). In fact, we may even be tempted to go to 3 TC, but then we hit another problem - the capacitor gets charged to 93% at 3TC and then 95% at 4TC. So, if we are looking to charge the capacitor to 93%, we may not be able to measure it and time it accurately because the charging graph flattens out. We found 2TC to be a good balance.
You may then ask, why not always use 2TC? The reason is that for larger capacitors like uF ones, with 2TC the charging time is ridiculously high. For ex for a 10uF capacitor and 1M resistor the charging time would be-
0.00001 * 1000000 * 2 = 20s
and 20s for just a 10uF capacitor, for a 100uF it would take 200s and so on. Now, no one wants to wait for 200s to measure a capacitor. So, to solve this 1/4 TC is taken (which is 22% of supply voltage). This decreases the charging time by 8 times (compared to 2TC). For the 10uF capacitor the charging time would be 2.5s.
The ATtiny also needs to determine whether to charge the capacitor to 1/4 TC or to 2 TC (For small capacitors it needs to take 2 TC and for large capacitors it needs to take 1/4 TC). If the capacitor takes 10ms or greater to charge to 22% of supply voltage (i.e the capacitor needs to be greater than 40nF) then the ATtiny stops charging and takes 1/4 TC for finding the capacitance. If the charging time to 22% is lesser than 10ms, it charges the capacitor to 86% and then stops charging to find the capacitance. That is how the capacitor tester works.
I hope you enjoyed this instructable. Please feel free to give advice on how I can improve my instructable/project and do take a look at my other instructables.