Measuring the RC Time Constant

Pico W with a 10 kΩ resistor from GP15 to a 100 µF electrolytic capacitor, GP26 reading the capacitor node, capacitor negative leg to the ground rail

Measuring the RC Time Constant

What You'll Learn

  • The time constant τ = RC and its units (ohms × farads = seconds).
  • Predict charging behaviour from R and C, then measure it.
  • Find experimentally when the capacitor reaches ~63.2% of its final voltage.
  • Compare measured τ with calculated τ; see that ~5τ ≈ fully charged.

What You'll Need

  • Pico W on a half breadboard, jumper wires
  • One 10 kΩ resistor and one 100 µF electrolytic capacitor, giving τ = RC = 1 s
  • Finished Measuring Capacitor Charge and Discharge, recommended

Background

In Measuring Capacitor Charge and Discharge you watched a capacitor fill through a resistor and saw the voltage rise fast at first, then ease off as it crept toward 3.3 V. Every RC circuit has its own timescale for that curve. This lesson gives that timescale a name and pins it down with a measurement.

Here's the prediction to make before you build anything. Your circuit charges the capacitor from a 3.3 V supply. Somewhere on the way up, the voltage passes 63.2% of the way to 3.3 V, which is about 2.09 V. With a 10 kΩ resistor and a 100 µF capacitor, how long do you think it takes to reach that 2.09 V mark, starting from empty? Write down a guess in seconds. You'll measure the real answer and see how close you were.

Build the Circuit

This is the same RC circuit you built in Measuring Capacitor Charge and Discharge: a resistor from a driving pin to the capacitor, with an analog pin reading the capacitor's voltage. If it's still on your breadboard, you can reuse it as-is. If not, wire it up again:

  1. Place the 10 kΩ resistor so one leg is in hole f24 and the other in f23.
  2. Connect the Pico's GP15 to the resistor leg in row 24. This end drives the circuit.
  3. Place the 100 µF capacitor with its positive leg in row 23 (the same net as the resistor's other leg) and its negative leg in row 22. Row 23 is the node you measure.
  4. Connect the Pico's GP26 to the capacitor's positive leg. GP26 is analog input ADC0.
  5. Connect the capacitor's negative leg to the negative power rail.
  6. Connect a Pico GND pin to that same negative rail.

Warning: The electrolytic capacitor is polarised. Its negative leg (usually the shorter one, marked with a stripe) goes to ground. Putting it in backwards can damage it.

The measured node only ever charges from 3.3 V through the resistor, so its voltage stays between 0 V and 3.3 V — safely inside the ADC's limit, which must never see more than 3.3 V.

Pico W with a 10 kΩ resistor from GP15 to a 100 µF electrolytic capacitor, GP26 reading the capacitor node, capacitor negative leg to the ground rail

Write the Code

This program starts with the capacitor empty, then drives GP15 high to charge it through the resistor. While it charges, it prints the voltage many times a second for the plotter, and it also watches for the moment the voltage first crosses 63.2% of 3.3 V (about 2.09 V). That crossing time is your measured time constant. At the end it prints a short summary comparing the measured τ with the calculated τ = R × C = 1.0 s. Type it in and run it.

Python

from machine import Pin, ADC
import time

drive = Pin(15, Pin.OUT)   # GP15 drives the RC network through the 10 kOhm resistor
adc = ADC(26)              # GP26 / ADC0 reads the voltage on the RC node

SAMPLE_STEP = 0.02          # seconds between readings (~50 samples per second)
CHARGE_TIME = 5             # seconds to watch the capacitor charge (~5 tau)

SUPPLY = 3.3                # volts driven onto the network
TARGET_FRACTION = 0.632     # one time constant reaches ~63.2% of the final voltage
TARGET_VOLTS = SUPPLY * TARGET_FRACTION   # ~2.09 V at a 3.3 V supply

CALCULATED_TAU = 10_000 * 100e-6   # R * C = 10 kOhm * 100 uF = 1.0 second


def read_volts():
    # read_u16() gives 0-65535; scale it to the 0-3.3 V the ADC measures
    return adc.read_u16() * SUPPLY / 65535


# Start from empty: drive GP15 low for a few seconds so the capacitor discharges fully.
drive.value(0)
time.sleep(CHARGE_TIME)

# Charge: drive GP15 high so the capacitor fills up through the resistor.
drive.value(1)
start = time.ticks_ms()
measured_tau = None   # filled in the first time we cross TARGET_VOLTS

while time.ticks_diff(time.ticks_ms(), start) < CHARGE_TIME * 1000:
    t_ms = time.ticks_diff(time.ticks_ms(), start)   # milliseconds since charging began
    volts = read_volts()
    print("{},{:.3f}".format(t_ms, volts))            # CSV: t_ms,volts

    # The first sample at or above 2.09 V marks one time constant.
    if measured_tau is None and volts >= TARGET_VOLTS:
        measured_tau = t_ms / 1000   # convert milliseconds to seconds

    time.sleep(SAMPLE_STEP)

# Compare what we measured against the value we calculated from R and C.
if measured_tau is not None:
    print("# measured tau = {:.2f} s, calculated tau = {:.2f} s".format(
        measured_tau, CALCULATED_TAU))
else:
    print("# never reached {:.2f} V - charge longer or check the wiring".format(
        TARGET_VOLTS))

Each data line prints two numbers: the milliseconds since charging began, then the measured voltage. Turn on the plotter's timestamp toggle so it uses that first column as the time axis, and watch the line sweep up toward 3.3 V. The final line, the one starting with #, is a note for you rather than the plotter: it shows the time the voltage first reached 2.09 V (your measured τ) next to the calculated τ = R × C = 1.0 s. They should land close to each other. New to the plotter? See Using the Plotter.

How It Works

The code sets up GP15 as an output that drives the network and GP26 as the analog pin that reads the capacitor's voltage. It first holds GP15 low to empty the capacitor, then drives it high and starts a clock. On every pass through the loop it prints the elapsed time and the voltage, and the first time the voltage reaches 2.09 V it records that instant as the measured time constant.

Now that you have the plotted curve in front of you, here's the idea that describes it. The speed of that curve is set by a single number called the time constant, written with the Greek letter τ (tau). For a resistor and capacitor it is simply the two values multiplied together:

τ = R × C

The units work out cleanly: an ohm times a farad is a second. So you don't need to convert anything exotic — multiply resistance in ohms by capacitance in farads and you get a time in seconds. For this circuit:

τ = 10 kΩ × 100 µF = 10,000 Ω × 0.000100 F = 1 second

τ is the natural yardstick for the curve. After one time constant, the capacitor has charged to about 63.2% of the supply — that's the ~2.09 V mark your code watches for. It's not a special property of this circuit; every charging RC circuit reaches ~63.2% of its final voltage after exactly one τ. That's why the crossing time you measured should land close to the 1 second you calculated from R × C.

The curve keeps climbing after that, but ever more slowly. Each additional time constant closes most of the remaining gap: about 86% charged after 2τ, 95% after 3τ, and by roughly 5τ the capacitor is at about 99% of the supply — close enough that we call it fully charged. That's why the code watches for about 5 seconds: five time constants of 1 second each is enough to see the curve flatten right out.

Try It

Run the program and watch the plot sweep upward toward 3.3 V, steep at first and flattening as it goes — the same shape you saw before, but now you're timing it.

  • Find where the line crosses 2.09 V (63.2% of 3.3 V). Read the time at that point off the plot, or read it from the summary line the code prints: that time is your measured τ.
  • Compare your measured τ with the calculated τ = R × C = 1 second. They should be close. A small difference is normal — real parts vary from their labelled values, and the sample rate only catches the crossing to within one reading.
  • Look at where the curve has nearly flattened. That should be around 5τ, roughly 5 seconds in, where the voltage sits near 3.3 V and barely moves. That's the capacitor effectively fully charged.

If your measured τ came out much larger or smaller than 1 second, check that you're using a 10 kΩ resistor and a 100 µF capacitor and that the capacitor is the right way round.

Challenge

Predict, then measure. Pick a different resistor or capacitor — say a 22 kΩ resistor instead of the 10 kΩ, or a larger capacitor if you have one. Before you change anything, calculate the new τ = R × C and write down the time you expect the voltage to reach 2.09 V. Then swap the part, run the program again, and compare your measured τ to your prediction. Did a bigger R or C stretch the curve out the way you expected?

Review

  • What is the formula for the time constant, and what are the units of R × C?
  • At one time constant, what fraction of the supply voltage has the capacitor reached? What is that in volts for a 3.3 V supply?
  • Roughly how many time constants does it take for the capacitor to be essentially fully charged, and about what percentage is that?