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 a positive and negative terminal

Figure 1: Capacitor
Step 1: Connecting From Arduino to a 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
- const int OUT_PIN = A1;
- 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);
- }
Explanation
- In this article, I explained about measuring the range of the capacitor.
- It can print the value in the serial monitor.
Output

Figure 2: Output

Sr KarthigaPosted May 25, 2016, 8:07 AM
thank you raja sir
RajaPosted May 24, 2016, 2:43 AM
Good one
Sr KarthigaPosted May 22, 2016, 9:54 PM
thank you munesh sir
Sr KarthigaPosted May 22, 2016, 9:53 PM
Thank you prasanna
Munesh SharmaPosted May 22, 2016, 10:55 AM
good one
Prasanna MuraliPosted May 21, 2016, 11:37 PM
Nice one....