Measuring The Capacitor Range With Arduino Mega 2560

In this article I will explain about measuring the Capacitor Range with Arduino Mega 2560.

Introduction
  • In this article I will explain about measuring the Capacitor Range with Arduino Mega 2560.
  • It can simply measure the capacitor range in the serial monitor.
Parts List
  • Arduino Mega 2560
  • Capacitor
  • Hookup Wires
  • Bread Board
Capacitor
  • A capacitor (originally known as a condenser) is a passive two-terminal electrical component.
  • It is used to store electrical energy temporarily in an electric field.
  • In the two terminal it can have the postive and negative terminal
      Figure 1: Capacitor

Connection

Step 1: Connecting From Arduino to capacitor.
  • Connect the postive terminal to the digital pin of A1 to the board
  • Connect the negative terminal to the A0 of the board
Programming:
  1. const int OUT_PIN = A1;  
  2. const int IN_PIN = A0;  
  3. //Capacitance between IN_PIN and Ground  
  4. //Stray capacitance is always present. Extra capacitance can be added to  
  5. //allow higher capacitance to be measured.  
  6. const float IN_STRAY_CAP_TO_GND = 24.48; //initially this was 30.00  
  7. const float IN_EXTRA_CAP_TO_GND = 0.0;  
  8. const float IN_CAP_TO_GND = IN_STRAY_CAP_TO_GND + IN_EXTRA_CAP_TO_GND;  
  9. const int MAX_ADC_VALUE = 1023;  
  10. void setup()  
  11. {  
  12.     pinMode(OUT_PIN, OUTPUT);  
  13.     //digitalWrite(OUT_PIN, LOW); //This is the default state for outputs  
  14.     pinMode(IN_PIN, OUTPUT);  
  15.     //digitalWrite(IN_PIN, LOW);  
  16.     Serial.begin(9600);  
  17. }  
  18. void loop()  
  19. {  
  20.     //Capacitor under test between OUT_PIN and IN_PIN  
  21.     //Rising high edge on OUT_PIN  
  22.     pinMode(IN_PIN, INPUT);  
  23.     digitalWrite(OUT_PIN, HIGH);  
  24.     int val = analogRead(IN_PIN);  
  25.     //Clear everything for next measurement digitalWrite(OUT_PIN, LOW);  
  26.     pinMode(IN_PIN, OUTPUT);  
  27.     //Calculate and print result  
  28.     float capacitance = (float) val * IN_CAP_TO_GND /  
  29.         (float)(MAX_ADC_VALUE - val);  
  30.     Serial.print(F("Capacitance Value = "));  
  31.     Serial.print(capacitance, 3);  
  32.     Serial.print(F(" pF ("));  
  33.     Serial.print(val);  
  34.     Serial.println(F(") "));  
  35.     while (millis() % 500 != 0);  
  36. }  
Explanation
  • In this article I explained about the measuring the range of the capacitor.
  • It can print the value in the serial monitor.
Output

                                             Figure 2: Output