← all lessons
Components · #5 of 48

Capacitors + RC Time Constant

Charging, Filtering, Timing

Why it matters

Capacitors store energy, filter noise, and create time delays. The RC time constant (τ = R × C) tells you how fast they charge/discharge.

The idea

What Is a Capacitor?

A capacitor stores electrical energy in an electric field. Think of it as a tiny rechargeable battery that charges/discharges very quickly.

flowchart LR
    V["Voltage"] -->|Charges| C["Capacitor"]
    C -->|Discharges| R["Resistor"]
    R -->|Time Constant| Tau["τ"]

Time constant: τ = R × C

RC Time Constant

When charging through a resistor: τ = R × C

Why It Matters

Capacitors are used for:

Demo

Adjust Resistance and Capacitance to see how the charging curve changes.

Watch for:

τ = 1.00 5τ ≈ 5.00 (≈99%)

Key takeaways

Going deeper

Capacitors have ESR (Equivalent Series Resistance) and leakage current. For power supply filtering, use ceramic capacitors (low ESR, good for high frequencies) and electrolytic capacitors (high capacitance, good for low frequencies). For timing, use film or ceramic capacitors (stable, low leakage).

Math details

RC charging equation:
  V(t) = V_final × (1 - e^(-t/τ))

  Where:
  τ = R × C (time constant in seconds)
  t = time
  V_final = final voltage

At t = τ:
  V(τ) = V_final × (1 - e^(-1)) ≈ V_final × 0.632

At t = 5τ:
  V(5τ) = V_final × (1 - e^(-5)) ≈ V_final × 0.993

Example:
  R = 10kΩ = 10,000Ω
  C = 100µF = 0.0001F
  τ = 10,000 × 0.0001 = 1 second

  After 1 second: ~63% charged
  After 5 seconds: ~99% charged

Implementation

LLM Prompt: RC Charging Simulator

Write a Rust function that simulates RC charging given R, C, V_final, and time.
Return voltage at that time using V(t) = V_final × (1 - e^(-t/τ)).
Include helper function to calculate time constant τ = R × C.

Lab Exercise: Hardware Debounce

  1. Build RC circuit: Button → 10kΩ resistor → 100nF capacitor → GND
  2. Connect capacitor to GPIO input (with pull-up enabled)
  3. Press button rapidly — observe smooth transition (no bounce)
  4. Measure time constant: τ = 10kΩ × 100nF = 1ms
  5. Compare to software debouncing (which is easier but uses CPU)

full glossary →