Arduino capacitance meter

This was a simple project which appeared on the ARduino website – https://www.arduino.cc/en/Tutorial/CapacitanceMeter , to look at the theory visit that page. I was wanting to see how accurate this is and also wanted to test this on other variants such as the Chipkit and the MSP_EXP430G2 to compare performance between these development boards

I selected an Arduino Uno for this.

You will need a Breadboard, 10k Resistor, 220 ohm resistor and some hookup wire
Layout

arduino capacitance

Code

#define analogPin      0          
#define chargePin      13         
#define dischargePin   11        
#define resistorValue  10000.0F   
 
unsigned long startTime;
unsigned long elapsedTime;
float microFarads;                
float nanoFarads;
 
void setup()
{
  pinMode(chargePin, OUTPUT);     
  digitalWrite(chargePin, LOW);  
  Serial.begin(9600);             
}
 
void loop()
{
  digitalWrite(chargePin, HIGH);  
  startTime = millis();
  while(analogRead(analogPin) < 648){       
  }
 
  elapsedTime= millis() - startTime;
  microFarads = ((float)elapsedTime / resistorValue) * 1000;          
 
  if (microFarads > 1)
  {
    Serial.print((long)microFarads);       
    Serial.println(" microFarads");         
  }
 
  else{
    nanoFarads = microFarads * 1000.0;      
    Serial.print((long)nanoFarads);         
    Serial.println(" nanoFarads");          
    delay(500); 
  }
 
  digitalWrite(chargePin, LOW);            
  pinMode(dischargePin, OUTPUT);            
  digitalWrite(dischargePin, LOW);          
  while(analogRead(analogPin) > 0){         
  }
 
  pinMode(dischargePin, INPUT);            
}

results

I tested this with several capacitors, one thing I noticed was with a 470uF capacitor the first reading was off, 402uF reported. After that all the readings were about the 470uF mark. In the screen capture above you can see a 226uF reading

I also tested 10uF,  22uf and 47uF capacitors as well and the readings were pretty accurate. You have to factor in that all capacitiors have a level of tolerance

 

Related posts

Arduino Uno and HMC5983 magnetometer example

Arduino and PCF8563 RTC example

Arduino and Rotary encoder example

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Read More