Capacitor charge and discharge lab
Record the voltage across a capacitor as it charges and discharges and find the time constant.
Build it step by step
0 of 8 donePlace the capacitor
Plus to the junction, stripe leg to GND.
Wire the resistor
10 kilohm from D8 to the capacitor plus.
Wire the sense line
Capacitor plus to A0.
Wire the button
D2 to GND.
Upload and open the serial plotter
Waiting for a button press.
Press the button
Three phases run, discharge then charge then discharge.
Read the measured tau
It should be close to one second.
Swap in the 1 kilohm resistor
Change R_OHMS and tau falls to about 0.1 second.
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
Parts list
- Development BoardsBuyArduino Uno R3 × 1
- PassivesBuy
- PassivesBuyResistor 10 kΩ × 1
- PassivesBuyResistor 1 kΩ × 1
- SwitchesBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Uno D8 | 10 kilohm resistor to capacitor plus | Charge and discharge path |
| Capacitor plus | Uno A0 | Voltage measurement |
| Capacitor minus | Uno GND | Ground side, mark the stripe |
| 1 kilohm | Between the pin D8 and the 10 kilohm junction | Optional second resistor to compare |
| Button | Uno D2 to GND | Start 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.
| Check | Expected |
|---|---|
| 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 |
| After 5 tau | Voltage within 1 percent of the final value |
| Button pressed twice | Second 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 →
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.
