I fancied trying the 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 resistor and some hookup wire
Layout
Code
[codesyntax lang=”cpp”]
#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); }
[/codesyntax]
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.
We'll play about with this in future articles