# Measuring The Capacitor Range With Arduino Mega 2560

Introduction
• It can simply measure the capacitor range in the serial monitor.
Parts List
• Arduino Mega 2560
• Capacitor
• Hookup Wires
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);
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 /