Measure Capacitance With Arduino

31,206

372

26

Intro: 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?

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?

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

Needed

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

Step 4: 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

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.

6 People Made This Project!

Recommendations

  • Fix It! Contest

    Fix It! Contest
  • Furniture Contest 2018

    Furniture Contest 2018
  • Metalworking Contest

    Metalworking Contest

26 Discussions

0
None
Siddhi333

Question 2 hours ago on Step 5

I'm not getting anything on the serial monitor

0
None
samsonovi

9 months ago

What do the Farads determine/do in this project?

0
None
NigelinaP

1 year ago

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?

1 reply
0
None
AdityaP147NigelinaP

Reply 11 months ago

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

0
None
Tanmay Deuskar

1 year ago

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

0
None
theoriginalrage

2 years ago

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!

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.

0
None
MaximousJuarezG

Reply 3 years ago on Introduction

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.

0
None
dmhoke

3 years ago on Introduction

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

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

3 replies
0
None
Maximousdmhoke

Reply 3 years ago on Introduction

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)

0
None
Lmecanodmhoke

Reply 3 years ago on Introduction

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

0
None
bigone5500

3 years ago

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

0
None
luay.alneemi

3 years ago

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