Use Arduino Capacitance Meter to measure Capacitance

Capacitors are used in many place where we require to store some charge. Capacitors carry the ability of storing charge in the form of Electric Field b/w its Conducting Plate. There is also dielectric inside the Plates b/w Capacitor for enhancing the value of maximum stored charge.

Let’s Suppose you are in a situation where you don’t have your multi meter (Favorite tool for electronics lovers: smart and slim). Then you are to measure the Capacitance, then how will you measure it? Basically It is awkward to think of situation where you have your Laptop and Arduino but not multi meter. But the need to learn How to measure Capacitance with the help of Arduino Capacitance meter gives you the idea How actually the Capacitance can be measured and how arduino is can be much more useful, thus clearing out your basics.

Theory behind measuring Capacitance with the Arduino Capacitance meter

We will be using the concept of “How capacitor charges and its equation“ to measure the value of Capacitance. Lets look at the basic equation of Capacitor.

Here time is equal to the RC (Resistane * Capacitance if the Voltage of the charging Capacitor is 63.2%).

So wee will use this condition to find out the value of Capacitance, when the Voltage is 63.2%.

time = Resitance * Capacitance

The t is the time taken to charge the capacitor from 0 to 63.2% which can easily be measured.

How is Arduino Helpful in this method

  1. It can measure the time required to charge the capacitor from 0 to 63.2 %
  2. It can measure the current voltage of the capacitor , that is required for checking whether capacitor has been charged to 63.2% or not ?

What Type of Pins do Arduino have?

To get familiar with the whole working of the Arduino Capacitance Meter , you need to know which type of pins does Arduino has ? ?

Pinmode(Pin,INPUT):

It is used for reading value of Sensor, We will be setting the discharge pin of the capacitor to INPUT Mode for not letting it discharge. This pin pin offers resistance.

Pinmode(Pin,OUTPUT):

It is used for giving the powersupply, that is used for turning On Led. We will be setting Charge Pin to HIGH for Charging the capacitor.

Code for Arduino Capacitance Meter (Arduino.cc)

/*  RCTiming_capacitance_meter
*   Paul Badger 2008
*  Demonstrates use of RC time constants to measure the value of a capacitor
*
* Theory   A capcitor will charge, through a resistor, in one time constant, defined as T seconds where
*    TC = R * C
*
*    TC = time constant period in seconds
*    R = resistance in ohms
*    C = capacitance in farads (1 microfarad (ufd) = .0000001 farad = 10^-6 farads )
*
*    The capacitor’s voltage at one time constant is defined as 63.2% of the charging voltage.
*
*  Hardware setup:
*  Test Capacitor between common point and ground (positive side of an electrolytic capacitor  to common)
*  Test Resistor between chargePin and common point
*  220 ohm resistor between dischargePin and common point
*  Wire between common point and analogPin (A/D input)
*/

#define analogPin      0          // analog pin for measuring capacitor voltage
#define chargePin      13         // pin to charge the capacitor – connected to one end of the charging resistor
#define dischargePin   11         // pin to discharge the capacitor
#define resistorValue  10000.0F   // change this to whatever resistor value you are using
// F formatter tells compliler it’s a floating point value

unsigned long startTime;
unsigned long elapsedTime;
float microFarads;                // floating point variable to preserve precision, make calculations
float nanoFarads;

void setup(){
pinMode(chargePin, OUTPUT);     // set chargePin to output
digitalWrite(chargePin, LOW);

Serial.begin(9600);             // initialize serial transmission for debugging
}

void loop(){
digitalWrite(chargePin, HIGH);  // set chargePin HIGH and capacitor charging
startTime = millis();

while(analogRead(analogPin) < 648){       // 647 is 63.2% of 1023, which corresponds to full-scale voltage 
}

elapsedTime= millis() – startTime;
// convert milliseconds to seconds ( 10^-3 ) and Farads to microFarads ( 10^6 ),  net 10^3 (1000)  
microFarads = ((float)elapsedTime / resistorValue) * 1000;
Serial.print(elapsedTime);       // print the value to serial port
Serial.print(” mS    “);         // print units and carriage return

if (microFarads > 1){
Serial.print((long)microFarads);       // print the value to serial port
Serial.println(” microFarads”);         // print units and carriage return
}
else
{
// if value is smaller than one microFarad, convert to nanoFarads (10^-9 Farad). 
// This is  a workaround because Serial.print will not print floats

nanoFarads = microFarads * 1000.0;      // multiply by 1000 to convert to nanoFarads (10^-9 Farads)
Serial.print((long)nanoFarads);         // print the value to serial port
Serial.println(” nanoFarads”);          // print units and carriage return
}

/* dicharge the capacitor  */
digitalWrite(chargePin, LOW);             // set charge pin to  LOW 
pinMode(dischargePin, OUTPUT);            // set discharge pin to output 
digitalWrite(dischargePin, LOW);          // set discharge pin LOW 
while(analogRead(analogPin) > 0){         // wait until capacitor is completely discharged
}

pinMode(dischargePin, INPUT);            // set discharge pin back to input
}

Inside the Coding of Arduino Capacitance Meter

To know what is going inside the Code, we just stick to the Basic theory part first. I suggest you to remind that part if you suffer from short term memory loses.

Coding Part is implantation of what the theory said:

There is statement in the while Loop

while(analogRead(analogPin) < 648){// 647 is 63.2% of 1023, which corresponds to full-scale voltage}

It is for the purpose of not allowing the program to proceed further if voltage has not reached to the 63.2%.

Then there is millis() Functions Used.

Millis() , it is used for measuring the time, it starts measuring the tie at the staring of the program.

elapsedTime = millis() – startTime;

Likewise the above Statement has been used effectively to calculate the elapsed time.