Projects / Capacitor charge and discharge lab

Capacitor charge and discharge lab

Record the voltage across a capacitor as it charges and discharges and find the time constant.

Beginner2 hGuided buildReviewed

Build it step by step

0 of 8 done
  1. UNO

    Place the capacitor

    Plus to the junction, stripe leg to GND.

  2. UNO

    Wire the resistor

    10 kilohm from D8 to the capacitor plus.

  3. UNO

    Wire the sense line

    Capacitor plus to A0.

  4. UNO

    Wire the button

    D2 to GND.

  5. UNO

    Upload and open the serial plotter

    Waiting for a button press.

  6. UNO

    Press the button

    Three phases run, discharge then charge then discharge.

  7. UNO

    Read the measured tau

    It should be close to one second.

  8. UNO

    Swap in the 1 kilohm resistor

    Change R_OHMS and tau falls to about 0.1 second.

In short

How do you build a capacitor charge and discharge lab?

Record the voltage across a capacitor as it charges and discharges and find the time constant. You need Arduino Uno R3, Electrolytic Capacitor 100 µF, Resistor 10 kΩ, Resistor 1 kΩ, Tactile push button 6 mm and Breadboard 830 Tie Points. It takes 8 steps and about 120 minutes.

Level
Beginner
Time
About 120 min
Parts
6
See the electronics first. This build uses capacitor charging. Try a capacitor charging in the circuit builder and watch the voltages and currents before you wire it.

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
Uno D810 kilohm resistor to capacitor plusCharge and discharge path
Capacitor plusUno A0Voltage measurement
Capacitor minusUno GNDGround side, mark the stripe
1 kilohmBetween the pin D8 and the 10 kilohm junctionOptional second resistor to compare
ButtonUno D2 to GNDStart a new run

Code

When a capacitor charges through a resistor, its voltage rises quickly at first then slows down, following V = Vs x (1 - e^(-t/RC)). The product R x C is the time constant tau. After one tau the voltage has reached about 63 percent of the final value, and when discharging it has fallen to about 37 percent. With 10 kilohms and 100 microfarads, tau is one second. The sketch drives the resistor from D8, reads the capacitor voltage on A0 every 100 milliseconds, prints time and voltage in a format the serial plotter understands, and reports the measured time when the 63 percent level is crossed. Electrolytic capacitors can be 20 percent off their label, so the measured value will not match exactly, which is a good lesson in tolerance. The capacitor is polarised: its stripe marks the negative leg, which goes to GND. Stay at 5 V, well below the rated voltage. Try the 1 kilohm resistor and see tau fall to a tenth.

Runs on a virtual Arduino Uno in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

const int DRIVE = 8;               // charges or discharges the capacitor through the resistor
const int SENSE = A0;
const int START_BTN = 2;
const float R_OHMS = 10000.0;      // change to 1000.0 when using the 1 kilohm resistor
const float C_FARADS = 100e-6;     // 100 microfarads, real parts vary by 20 percent

void runPhase(bool charge) {
  pinMode(DRIVE, OUTPUT);
  digitalWrite(DRIVE, charge ? HIGH : LOW);
  unsigned long t0 = millis();
  Serial.println(charge ? "# charging" : "# discharging");
  float tauMs = -1;
  while (millis() - t0 < 6000) {
    int raw = analogRead(SENSE);
    float v = raw * 5.0 / 1023.0;
    unsigned long t = millis() - t0;
    Serial.print(t); Serial.print(','); Serial.println(v, 3);
    // one time constant: 63 percent of the way to the final value
    if (tauMs < 0) {
      if (charge && v >= 0.632 * 5.0) tauMs = t;
      if (!charge && v <= 0.368 * 5.0) tauMs = t;
    }
    delay(100);
  }
  Serial.print("# measured tau ms: "); Serial.println(tauMs);
  Serial.print("# expected tau ms: "); Serial.println(R_OHMS * C_FARADS * 1000.0);
}

void setup() {
  Serial.begin(9600);
  pinMode(START_BTN, INPUT_PULLUP);
  Serial.println("# Press the button to start a run");
}

void loop() {
  if (digitalRead(START_BTN) == LOW) {
    delay(30);
    runPhase(false);        // empty the capacitor first
    runPhase(true);         // then charge it
    runPhase(false);        // then discharge it
    Serial.println("# done");
    while (digitalRead(START_BTN) == LOW) {}
  }
}

What the serial monitor should show

Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual Arduino Uno with its sensors at their default values. Your numbers will follow your real readings, but the format should match.

# Press the button to start a run

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
10 kilohm and 100 microfaradTau about 1000 ms
1 kilohm and 100 microfaradTau about 100 ms
Capacitor reversedOdd values, fix the polarity
After 5 tauVoltage within 1 percent of the final value
Button pressed twiceSecond run starts only after the first ends

If it does not work

Tau far from expected

Check R_OHMS in the sketch and the part values.

Curve is noisy

Add short wires and keep the breadboard away from motors.

Final voltage below 5 V

Measure the board 5V pin with a meter, USB supplies can sit near 4.7 V.

Nothing happens on press

Check the button goes to D2 and GND.

Capacitor feels warm

Stop and check polarity.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the capacitor charge and discharge lab?

Arduino Uno R3, Electrolytic Capacitor 100 µF, Resistor 10 kΩ, Resistor 1 kΩ, Tactile push button 6 mm and Breadboard 830 Tie Points.

How long does the capacitor charge and discharge lab take to build?

About 120 minutes for a beginner maker, in 8 steps.

How do I know the capacitor charge and discharge lab works?

10 kilohm and 100 microfarad: Tau about 1000 ms. 1 kilohm and 100 microfarad: Tau about 100 ms. Capacitor reversed: Odd values, fix the polarity.

Tau far from expected: what should I check?

Check R_OHMS in the sketch and the part values.

Curve is noisy: what should I check?

Add short wires and keep the breadboard away from motors.

Final voltage below 5 V: what should I check?

Measure the board 5V pin with a meter, USB supplies can sit near 4.7 V.

Nothing happens on press: what should I check?

Check the button goes to D2 and GND.