Introduction: Measure Capacitance With Arduino

Picture of Measure Capacitance With Arduino

This tutorial provides a guide on how to set up an Arduino to measure the capacitance of a capacitor. This can be useful if the capacitor is unlabeled or if it is self-built.

Step 1: What Is Capacitance?

Picture of What Is Capacitance?

Capacitance is an object's ability to store an electric charge. Reasonably, this object is referred to as a capacitor. A capacitor that stores this charge in an electric field between two conductive plates is known as a parallel plate capacitor. The non-conductive material that is between these two plates is known as a dielectric. Dielectrics change the amount of charge a capacitor can hold and , in practice, what the particular capacitor would be used for (e.g. high frequency circuits, high voltage circuits, etc).

The equation for the capacitance of a parallel plate capacitor is:

C = (εA) / d

where ε is the permittivity of free space or dielectric, A is the surface area of overlap between the plates, and d is the distance between the plates.

Step 2: How Is Capacitance Measured?

Picture of How Is Capacitance Measured?

An RC (Resistor-Capacitor) circuit has a property known as a "RC Time Constant" or T (Tau). The equation for which is given below:

T = RC

Tau can be simplified from a more complicated equation (shown in images above) to represent the time it takes a capacitor to be charged, through a resistor, to reach 63.2% of its total voltage. This can also be measured by the time it takes the capacitor to reach 36.8% of its total voltage upon discharging.

The Arduino will be programmed to time how long it takes for a capacitor to reach 63.2% of its total charge. It will then use the equation for Tau to calculate the capacitance since the value of the resistor is already known.

Step 3: Parts

Picture of Parts

Needed

  • Ardunio
  • Breadboard
  • Jumper Wires
  • 220 Ω Resistor
  • 10 kΩ Resistor
  • Capacitor (Unknown Value)

Step 4: Wiring

Picture of Wiring

The wiring for this project is pretty straight forward. Just follow the diagrams provided.

NOTE: Make sure the silver stripe on the capacitor (if using a bipolar capacitor) is connected to Ground.

NOTE 2: The 220 Ω resistor and the wire connected to pin 11 are not necessary, but recommended as it speeds up the discharging time.

Step 5: Upload Code & Test

Picture of Upload Code & Test

After everything is wired properly, upload the code below to your Arduino. The code is commented to allow for easier understanding of the process behind the measurement.

// Initialize Pins
int analogPin = 0; int chargePin = 13; int dischargePin = 11; //speeds up discharging process, not necessary though

// Initialize Resistor int resistorValue = 10000;

// Initialize Timer unsigned long startTime; unsigned long elapsedTime;

// Initialize Capacitance Variables float microFarads; float nanoFarads;

void setup() { pinMode(chargePin, OUTPUT); digitalWrite(chargePin, LOW); Serial.begin(9600); // Necessary to print data to serial monitor over USB }

void loop() { digitalWrite(chargePin, HIGH); // Begins charging the capacitor startTime = millis(); // Begins the timer while(analogRead(analogPin) < 648) { // Does nothing until capacitor reaches 63.2% of total voltage }

elapsedTime= millis() - startTime; // Determines how much time it took to charge capacitor microFarads = ((float)elapsedTime / resistorValue) * 1000; Serial.print(elapsedTime); Serial.print(" mS ");

if (microFarads > 1) // Determines if units should be micro or nano and prints accordingly { Serial.print((long)microFarads); Serial.println(" microFarads"); }

else { nanoFarads = microFarads * 1000.0; Serial.print((long)nanoFarads); Serial.println(" nanoFarads"); delay(500); }

digitalWrite(chargePin, LOW); // Stops charging capacitor pinMode(dischargePin, OUTPUT); digitalWrite(dischargePin, LOW); // Allows capacitor to discharge while(analogRead(analogPin) > 0) { // Do nothing until capacitor is discharged }

pinMode(dischargePin, INPUT); // Prevents capacitor from discharging }

After the code is done uploading, open the Serial Monitor (Tools > Serial Monitor) to view the measurement of the unknown capacitor.

The first value is how long it took the capacitor to reach 63.2% of it's total charge. The second value is the calculated capacitance in either "nano" or "micro" farads.

The program will repeatedly test the capacitor and values may vary slightly. It is best to take the average of these values.

NOTE: This sensor is most accurate for capacitance values between 1 μF to 3500 μF.

Step 6: References

The majority of the code was used from Arduino and can be found here.

Comments

NigelinaP (author)2017-02-26

Hi I'm currently trying to make this but I would need to measure 100F -300F Capacitance is there a way or does anyone have any suggestion for such large Capacitance?

AdityaP147 (author)NigelinaP2017-10-13

LCR meter will be easiest way to measure high capacitances. If you have access to autolab GCD curve will guide you to best resolutions

StevenW11 made it! (author)2017-10-07

Simple process. Useful instructable.

Tanmay Deuskar (author)2017-04-21

Really useful instructable. My multimeter cannot measure capacitance and so this will surely help me. Thanks for posting!

Tecwyn Twmffat made it! (author)2016-10-26

I used some of your ideas - thanks!

theoriginalrage (author)2016-07-19

I just found your instructable and imediatly favorited it. It's really cool that you included the math behind it, that really helps. Now I'm off to measure capacitors!

mariusroets made it! (author)2016-04-28

Works like a charm. See the instructable on "How to get an Arduino micros() function with 0.5us precision"

https://www.instructables.com/id/How-to-get-an-Ardu...

to get a slightly more accurate time measurement

t

JaredE made it! (author)2015-08-07

I am currently working on getting this code to work with an LCD1602. I have built this version and it works great.

JaredE (author)JaredE2015-08-15

Here is my capacitor tester with an I2C 1602 LCD connected.

Maximous (author)JaredE2015-08-21

Wow, that looks great.

Maximous (author)JaredE2015-08-08

Glad to hear it. The LCD compatibility would make it great for a portable measuring device.

JaredE (author)Maximous2015-08-16

Here is my code:

#include <LiquidCrystal_I2C.h> // Includes the Liquid Crystal I2C library.

#include <Wire.h> // Includes the Wire library.

LiquidCrystal_I2C lcd(0x27, 16, 2); // Creates an LCD object and sets the I2C address along with Cols, Rows.


int analogPin = 0; // Initialize Pins
int chargePin = 13;

int dischargePin = 11; //speeds up discharging process, not necessary though


int resistorValue = 10000; // Initialize Resistor


unsigned long startTime; // Initialize Timer
unsigned long elapsedTime;


float microFarads; // Initialize Capacitance Variables.
float nanoFarads;

void setup()
{
lcd.begin();

lcd.backlight(); // Turns on the backlight. Probably not needed though. If your board supports it, you can set a brightness level from 0 to 255 in the().

pinMode(chargePin, OUTPUT);
digitalWrite(chargePin, LOW);

Serial.begin(9600); // Sets the baud rate for the serial monitor
}

void loop()
{
digitalWrite(chargePin, HIGH); // Begins charging the capacitor

startTime = millis(); // Begins the timer

while(analogRead(analogPin) < 648)
{
// Does nothing until capacitor reaches 63.2% of total voltage
}

elapsedTime = millis() - startTime; // Determines how much time it took to charge capacitor

microFarads = ((float)elapsedTime / resistorValue) * 1000;

lcd.setCursor(0,0); // Sets the cursor to column 0, row 0.

lcd.print(elapsedTime); // Prints the variable 'elapsedTime' to the LCD.
lcd.print(" mS "); // Prints 'mS' after the above.

Serial.print(elapsedTime); // Prints 'elapsedTime' to the serial monitor.
Serial.print(" mS "); // Prints 'mS' after the above.

if (microFarads > 1) // Determines if units should be micro or nano and prints accordingly
{
lcd.setCursor(0,1); // Sets the cursor to column 0, row 1.

lcd.print((long)microFarads); // Prints the variable 'microFarads' to the LCD.
lcd.print(" microFarads"); // Prints 'microFarads' after the above/

Serial.print((long)microFarads); // Prints the variable 'microFarads' to the serial monitor.
Serial.println(" microFarads"); // Prints 'microFarads' after the above.
}

else
{
nanoFarads = microFarads * 1000.0;

lcd.setCursor(0,1);

lcd.print((long)nanoFarads);
lcd.print("nanoFarads");

Serial.print((long)nanoFarads);
Serial.println(" nanoFarads");

delay(500);
}

digitalWrite(chargePin, LOW); // Stops charging capacitor

pinMode(dischargePin, OUTPUT);

digitalWrite(dischargePin, LOW); // Allows capacitor to discharge

while(analogRead(analogPin) > 0)

{
// Do nothing until capacitor is discharged
}

pinMode(dischargePin, INPUT); // Prevents capacitor from discharging
}
andrew.larson.14289 (author)2015-07-30

Quick question on aurdino, if one of those cables broke of the tip while attatch to board. how can i gert it out

Maybe a sharp needle prying it out?

There is not really an easy solution to that. First make sure that everything is unplugged and that there is no current flowing through any of the wires. Then get the smallest pair of tweezers you can find and try to pull it out.

Alex in NZ made it! (author)2015-08-12

I had the same behaviour as DoguTheCreator, until I realised that I'd misconnected the Pin 13. Once that was connected to the 10K all well and...

It works!!! Yay. Thanks for a great instructible :-)

JuarezG (author)2015-07-16

Amazin... have a send results in Display LCD?

Maximous (author)JuarezG2015-07-21

I don't have a display LCD, but it wouldn't be too hard to implement. Just change where the value is being sent to.

DoguTheCreator made it! (author)2015-07-20

I believe I have done everything right but the code just reads 0 and then 99 nanoFarads even when I change the capacitor

Maximous (author)DoguTheCreator2015-07-21

What is the capacitance of the small capacitor on your breadboard supposed to be? This set up works best for ranges between 1 μF to 3500 μF so it could be possible that it's value is too low/high to properly register.

dmhoke (author)2015-07-10

1. Great ! ! ! How can it be modified for more accuracy with lower values??

2. How about an instructable for measuring inductance simply as this??

Maximous (author)dmhoke2015-07-12

I agree with what Lmecano pointed out. You can change to the 10 kΩ resistor for something else to help fine tune the circuit a bit. It should be possible to measure inductance with an Arduino though I have yet to do it (I may look into it and make a tutorial about it later). What you would need to do I believe (from my head) is build a simple RL circuit. You then want to send current through the circuit at a known frequency. The equation for inducatnce would then be:

L = SquareRoot (3) * R / (2* PI * f)

JuarezG (author)Maximous2015-07-16

have a send data to dysplay?

Lmecano (author)dmhoke2015-07-11

Really nice how to.

1. Not sure that we can. The main improvement will be on the CAN resolution. For lower values, you'll need to change the resistor I guess.

2. Not as easy as for a capacitor:

https://en.wikipedia.org/wiki/RLC_circuit

bigone5500 (author)2015-07-15

Now to make it display the reaults to an lcd. Nice instructible!

luay.alneemi (author)2015-07-15

Hello Dear!
help me to convert 120vAC to 120vDC.

AhmedE41 (author)2015-07-14

Nice Work

Akshay Jha (author)2015-07-14

Great work

andrew.hyder.71 (author)2015-07-10

Very well thought out and explained! Great instruct able for beginners in capacitance/Arduino amateurs

Maximous (author)andrew.hyder.712015-07-12

Thanks, I'm glad you enjoyed it.

torusbrane (author)2015-07-12

Very informative! I actually need this setup, as I need to find out if the capacitor I have is a 1 uf (I've looked up all the codes on the cap, but nothing is telling as to what size it is, doesn't say '105' on it or anything like that). I've seen other people do this setup on an Arduino Uno before, but this explains everything in great detail, plus it's a refresher for me. So next week, when I get a chance to actually try this out, I will let you know how well it works for me! Thanks for posting this Maximous!

Maximous (author)torusbrane2015-07-12

You're very welcome. Please let me know how it turns out for you. I'm glad I could be of help!

Maximous (author)2015-07-12

The 220 Ω Resistor doesn't get changed, but there is a spot in the code to change the 10 kΩ resistor. Changing that should allow for a different range of capacitors to be measured. A 1F capacitor however is a huge amount of charge. Normal hobby capacitors are measured in "nano" and "micro" farads so I am not sure if an Arduino would be able to handle that.

Antzy Carmasaic (author)2015-07-12

That's a great idea.

About This Instructable

26,177views

365favorites

License:

More by Maximous:Control a Camera with an Arduino and RS232 ShieldPrint Conductive Circuits With An Inkjet PrinterMeasure Capacitance with Arduino
Add instructable to: