loading

Capacitance measurement with the Arduino Uno

Step 1: Capacitance Measurement With the Arduino Uno

There are lots of examples of how to do this on the internet, but I’m going to suggest an incredibly simple way to it. Let’s start with the theory.

arduino code

const int OUT_PIN = A2;
const int IN_PIN = A0;

//Capacitance between IN_PIN and Ground //Stray capacitance is always present. Extra capacitance can be added to //allow higher capacitance to be measured. const float IN_STRAY_CAP_TO_GND = 24.48; //initially this was 30.00 const float IN_EXTRA_CAP_TO_GND = 0.0; const float IN_CAP_TO_GND = IN_STRAY_CAP_TO_GND + IN_EXTRA_CAP_TO_GND; const int MAX_ADC_VALUE = 1023;

void setup() { pinMode(OUT_PIN, OUTPUT); //digitalWrite(OUT_PIN, LOW); //This is the default state for outputs pinMode(IN_PIN, OUTPUT); //digitalWrite(IN_PIN, LOW);

Serial.begin(9600); }

void loop() { //Capacitor under test between OUT_PIN and IN_PIN //Rising high edge on OUT_PIN pinMode(IN_PIN, INPUT); digitalWrite(OUT_PIN, HIGH); int val = analogRead(IN_PIN);

//Clear everything for next measurement digitalWrite(OUT_PIN, LOW); pinMode(IN_PIN, OUTPUT);

//Calculate and print result

float capacitance = (float)val * IN_CAP_TO_GND / (float)(MAX_ADC_VALUE - val);

Serial.print(F("Capacitance Value = ")); Serial.print(capacitance, 3); Serial.print(F(" pF (")); Serial.print(val); Serial.println(F(") "));

while (millis() % 500 != 0) ; }

Thank you

<p>You say &quot;Let&rsquo;s start with the theory&quot; but then go on to the code. Perhaps you could go back and explain the theory. If you are not entierly comfortable in English just use what ever language you want and then use Google ( or let the reader use Google ) to get to the desired language.</p>
<p>This will make your code readable once you are a pro.</p><p><a href="https://www.instructables.com/id/Put-Your-Code-in-a-Box-Properly-Indented-on-Instru/">https://www.instructables.com/id/Put-Your-Code-in-a...</a></p>
<p>The formatting of your code is a bit messed up from being pasted in this Instructable. There are missing line returns which causes some executable code to get mixed up with comments. You might want to try attaching a .ino file.</p>

About This Instructable

622views

19favorites

License:

More by alikarkuki:Arduino Lcd Counter   arduino  capacitances measure Arduino Relay Circuit  
Add instructable to: