Wednesday, 8 May 2019

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-builtCapacitance 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) / dwhere ε 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 = RCTau 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.
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 = RCTau 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.

Ardunio

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



KOD:


// 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.

No comments: