Find fresh tutorials related to Arduino, Raspberry Pi, 555 Timer and many more microcontrollers. Learn something new everyday!



Tuesday, 16 December 2014

Measure the capacitance of any capacitor [ARDUINO]





Here I am again with a new project in hand. This a very simple yet useful application of
Arduino in measurement.

What this project does?
Well, this will allow you to know the capacitance of any capacitor, may it be an electrolytic one or
 ceramic one. You will learn some great stuff here! For convenience, lots of comments have been
 added to the code to help you out.


Let's know the basics!
As we know, time constant of a capacitor is defined by T = RC, where R is the resistance in Ohms
 and C is the capacitance of the capacitor in Farads.
The voltage at 1 Time Constant equals 63.2% of the charging voltage.

Also, the current in an RC circuit can easily be found by differentiating the expression,
q=q`(1-e^-t/T), where q is the charge on the capacitor at any time t and q` is the product of
 Capacitance and Voltage across capacitor in steady state.

Basically, in this project we'll calculate the time required to charge the capacitor and the current
 time and we'll subtract them to find the T. Then, we'll divide this by the resistance value to get the
 capacitance. Simple.

Let's do this.

Materials Required:
1. Any capacitor (Take a few different valued ones)
2. Arduino
3. Jumpers
4. One 10K resistor or 1K resistor
5. One 220Ohm or 330Ohm resistor

Procedure:
1. Make the connections as shown:

 *  Connect the test capacitor between common point and ground
     (positive side of an electrolytic capacitor  to common)
 *  Test Resistor [1K or 10K] between chargePin and common point
 *  330 ohm resistor between dischargePin and common point
 *  Wire between common point and analogPin (A/D input)

Diagram:



2. Upload the sketch. [Scroll Down to find the Sketch]

3. Start the serial monitor on the Arduino IDE. You'll be able to see the
   capacitance of the given capacitor.

4. If you are using a 1K or any other test resistor, please modify the code in line 11


Sketch:

/*  RCTiming_capacitance_meter
 *   Nitish Dash (nitishdash95@gmail.com)
 *  Demonstrates use of RC time constants to measure the value of a capacitor 
 *  More info on eweekend.blogspot.com
 */

#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, 
                               // i.e, this is the test resistor
                    // 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
  {
  
    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
} 



How this works (Algorithm):

1. Set discharge pin to INPUT (so it can't discharge the capacitor)
2. Record the start time with millis()
3. Set charge pin to OUTPUT and make it HIGH
4. Check the voltage repeatedly in a loop until it gets to 63.2% of total voltage.
5. After the cap is charged, subtract the current time from the start
     time to find out how long the capacitor took to charge.
6. Divide the Time in seconds by the charging Resistance in ohms to find the Capacitance.
7. Report the value with serial.print
8. Discharge the capacitor. To do this:
 >> Set the charge pin to Input
 >> Set the discharge pin to OUTPUT and make it LOW
 >> Read the voltage to make sure the capacitor is fully discharged
9. Loops and does it again


Video:
Coming soon.....

Downloads:
1. Sketch.ino
2. Breadboard schematics

What else you can do?

Try these ideas to enhance your knowledge and application:
1. Try changing the resistor and capacitor values.
2. Try removing the part of the code and display all the capacitor readings
    in only picofarads
3. More advanced users can try plotting a graph of the charging phase of the capacitor.



Any doubts? Feel free to leave a comment.


0 comments:

Post a Comment

Leave your valuable feedback and suggestions.

Upcoming projects!

1. Programming ESP8266 using NodeMCU and LUA Scripts

2. IoT Applications

3. NRF42L01 2.4 GhZ module interfacing with arduino

4. ESP8266 - Everything cool about it!

Language ain't any barrier!

Get Updates!

Enter your email address:


Get the latest projects delivered into your inbox, hot!