What Is PID Control? P, I, and D Explained with Live Circuits

An air conditioner settles right at the set temperature. Cruise control holds your speed up a hill. A drone shrugs off a gust of wind and levels itself again. Behind all of these sits the same workhorse mechanism: PID control — the standard way machines chase a target and quietly pull back whenever they drift off it.

The name sounds like it must stand for something intimidating. In reality, PID is nothing more than a simple controller that grew, one fix at a time, into a very practical stack. In this article we start from the crudest possible controller — plain on–off switching — and add one term at a time: P, then PI, then PID. At every step you can watch how the response changes in live circuits running right on this page.

💡 Tip

Fig. 1Fig. 5 are all interactive — real simulations, not videos. Feel free to play with the figures first and come back to the text later. The charts respond the instant you move a slider.

One note before we start: the circuit itself is not the point this time. It plays the role of a stand-in for any device that responds to a command with a lag — a heater warming a room, a motor spinning up, water coming to temperature. Most of the physical world behaves this way, and that lag is exactly why control takes some skill.

1. First, the Vocabulary of Control

The goal is always the same: bring the actual value to the value you want, and hold it there. The recipe for deciding what command to send the device is what we call control. This article uses the standard symbols of the field.

If you would rather get a feel for the real behavior first, skip ahead — → Fig. 1.

SymbolFull nameMeaning
SPSet PointThe value you want. The gray dashed line in the charts.
PVProcess ValueThe value actually being measured — here, the capacitor voltage. The solid blue line.
MVManipulated VariableThe command pushed into the device — here, the voltage SoftMV. The solid yellow line.
eErrorHow far off you are: \(e = SP-PV\). The controller looks at nothing but this e when deciding MV.
SP gray dashed = target PV blue = actual MV yellow = command Dist red = disturbance (Fig. 5)

And here is where we are headed — PID control is this single line. It looks at the error e through three different lenses — how big it is now (P), how much of it has piled up over time (I), and how fast it is changing (D) — and adds the three answers together to form the command.

\[ MV = K_p\, e + K_i \int e\, dt + K_d \frac{de}{dt} \]

Don’t try to absorb it all at once. We are going to grow this equation one term at a time, from the left — starting from no equation at all (on–off control), and adding a term each time we run into something the current controller can’t do. The finish line of that process is the formula above.

Our stand-in “device” is a 100 Ω resistor feeding a 47 µF capacitor. Command a voltage MV and the capacitor voltage PV catches up gradually, with a time constant of \(\tau = RC = 100 \times 47 \times 10^{-6} \approx 4.7\,\mathrm{ms}\) — a classic first-order lag. Its step response is the familiar curve below, and the “can’t change instantly” character is right there in the math.

\[ PV(t) = MV \left( 1-e^{-t/\tau} \right) \]

ℹ️ How to read the figures

In each figure, the upper chart shows SP (gray dashed) and PV (blue); the lower chart shows MV (yellow). The trick is to read them as a pair: “how close does blue get to gray?” on top, and “how hard is yellow working to make that happen?” below. When a figure’s center scrolls out of view, its simulation pauses automatically (see sim=run/pause in the status line).

2. All or Nothing (Fig. 1: On–Off Control)

Start with no tools at all. Below the target? Switch on, full power. Above it? Switch off. This is the controller everyone invents on their first try — and it is genuinely everywhere: the thermostat in an iron, an electric kettle, or a space heater still works exactly this way.

Implemented naively it would chatter on and off at high speed right at the target, so in practice we add a hysteresis band (dead band) of width h. Written out as conditions:

\[ MV = \begin{cases} MV_{\max} & \left( PV < SP - \dfrac{h}{2} \right) \\[0.4em] 0 & \left( PV > SP + \dfrac{h}{2} \right) \\[0.4em] \text{hold the previous state} & \left( \text{otherwise} \right) \end{cases} \]

Drop below the band: turn on. Rise above it: turn off. Inside the band: do nothing. That’s the whole algorithm — two comparisons and not a single multiplication. This simplicity is on–off control’s greatest strength.

The rule driving this figure

  • Well below the target → switch the voltage (SoftMV) fully on
  • Well above the target → switch it off

Try this

1Watch the upper chart: blue (PV) keeps crossing back and forth over gray (SP), forever
2Narrow “Hysteresis” down to about 0.2 V. Switching gets faster and the wobble gets busy and nervous
3Now widen it to 1.0 V. Fewer switch events — but a bigger swing
4Drag the SP slider and watch the whole band follow the target

What to look for

Blue never sticks to gray — it shuttles back and forth inside the band (called hunting, or limit cycling). The yellow MV below is a square wave slamming between zero and full power. Narrow the band and the wobble shrinks, but switching gets frequent — and on real hardware, frequent switching eats relays and heaters alive. You are forced to sacrifice either ripple or switching life. That trade-off is the limit of on–off control.

Loading simulator…

Status

3.00 V Once it settles, move me!
0.60 V Width of the dead band.
Narrow = busy switching; wide = big swing.

SP/PV

MV

Powered by CircuitJS1 (Paul Falstad / Iain Sharp et al., GPL)

3. Push in Proportion to the Error (Fig. 2: P Control)

We want the wobble gone. So we pick up our first real tool: instead of choosing between full power and nothing, push with a strength proportional to how far off we are. This is proportional control — the “P” in PID.

\[ MV = K_p\, e = K_p\,(SP-PV) \]

Far from the target, push hard; closing in, ease off. It’s exactly what your hand does on a shower tap. The proportional gain \(K_p\) is the sensitivity — “how many volts of push per volt of error.”

But P alone has a built-in flaw. Our device sags the moment you stop pushing, so holding the target takes a sustained effort. Yet \(MV = K_p e\) says that when the error hits zero, the push also drops to zero. A controller that can only push while there is an error has no choice but to settle a little short of the target and balance there. That leftover gap is called steady-state error (offset).

For this particular device, which settles at \(PV = MV\), you can actually compute where it balances. Solving \(PV = K_p (SP-PV)\):

\[ PV = \frac{K_p}{1 + K_p}\, SP, \qquad e_{\infty} = \frac{SP}{1 + K_p} \]

With \(SP = 3\,\mathrm{V}\) and \(K_p = 5\), that predicts \(PV = 2.5\,\mathrm{V}\) — about 0.5 V short. Check it against the figure below; it really lands there. Raising \(K_p\) shrinks the offset (the denominator grows), but the response turns twitchy, and the first hints of overshoot and oscillation creep in.

The rule driving this figure

  • The farther from the target, the harder the voltage (SoftMV) pushes up or down (Kp)

Try this

1Leave Kp = 5 and confirm blue (PV) parks slightly below gray (SP) — around 2.5 V for SP = 3 V
2Drop Kp to 1. The gap grows dramatically (the math says half of SP: 1.5 V)
3Push Kp up to 8. The gap shrinks, but step the SP and you’ll see it start to overshoot
4Step SP up and down and compare blue’s tracking with the yellow MV trace below

What to look for

The hunting is gone. But blue stops just short of gray, every time. Play with Kp and check the gap against the formula \(e_{\infty} = SP/(1+K_p)\). Also notice the yellow MV: instead of a slamming square wave, it now glides smoothly in proportion to the error — the other big difference from Fig. 1.

Loading simulator…

Status

3.00 V Once it settles, move me!
5 How eagerly it chases the target.
Too strong = overshoot and wobble.

SP/PV

MV

Powered by CircuitJS1 (Paul Falstad / Iain Sharp et al., GPL)

4. Erase the Leftover Error over Time (Fig. 3: PI Control)

P control’s weakness was “no error, no push.” The fix is almost cheeky: keep a running total of the error over time, and push on that as well. That is integral action (I), and adding it to P gives us PI control.

\[ MV = K_p\, e + K_i \int e\, dt \]

The second term is the trick. As long as any error e remains, the integral \(\int e\, dt\) keeps growing — which means the push keeps ratcheting up as long as the target hasn’t been reached. Under this rule, no operating point other than e = 0 can be an equilibrium. That is precisely why the steady-state error that P control left behind is wiped out — not approximately, but in principle.

Look at the settled state and something delightful is going on: the error is zero, so the P term contributes nothing. What holds PV up is the integral term alone, carrying the entire sustained push on the memory of past errors. The integrator is the controller’s memory.

There is a price. Because the integral drags history along, it is still “charged up” at the moment you arrive at the target — so the response tends to overshoot first and come back down. Push \(K_i\) too high and it sways back and forth before settling.

The rule driving this figure

  • The farther from the target, the harder the voltage pushes (Kp)
  • Whatever error remains gets accumulated over time and squeezed out (Ki)

Try this

1With Kp = 5, Ki = 50, confirm blue (PV) now sits dead on gray (SP) — the big difference from Fig. 2
2Set Ki to 0. You are back to Fig. 2’s “always a little short”
3Raise Ki past 100 and step the SP. Watch it overshoot and swing before settling
4Once settled, look at the lower chart: zero error, yet yellow (MV) holds a steady level — that’s the integral term working alone

What to look for

Blue now locks onto gray. That is the power of integral action. But watch right after an SP step: blue overshoots the target once before coming back. “Guaranteed to erase the error” and “never overshoots” pull in opposite directions — and balancing Kp against Ki is your first taste of what engineers call tuning.

Loading simulator…

Status

3.00 V Once it settles, move me!
5 How eagerly it chases the target.
Too strong = overshoot and wobble.
50 How fast leftover error is erased.
Too strong = more overshoot and sway.

SP/PV

MV

Powered by CircuitJS1 (Paul Falstad / Iain Sharp et al., GPL)

5. Brake Before You Overshoot (Fig. 4: PID Control)

PI can lock onto the target. The remaining complaint is the overshoot. While you are closing in fast, PI keeps pushing as long as any error remains — it keeps its foot on the accelerator right up to the doorstep. A human driver would never do that: approaching a stop, you brake before you get there. Derivative action (D) is that anticipatory braking, written as math.

\[ MV = K_p\, e + K_i \int e\, dt + K_d \frac{de}{dt} \]

And with that, the equation from the introduction is complete — this is PID. The third term watches \(de/dt\), the speed at which the error is changing. When you are rushing toward the target, e is shrinking fast, so \(de/dt\) is strongly negative — the D term pulls back on the push (brakes). And when a disturbance suddenly knocks you off target, D reacts to how fast the error is growing and starts pushing back before anyone else.

The division of labor in one line each:

  • P (the present) — pushes in proportion to the current error. The workhorse.
  • I (the past) — remembers accumulated error and carries the final sustained push. Kills steady-state error.
  • D (the future) — reads the trend and brakes before the overshoot happens.

The rule driving this figure

  • The farther from the target, the harder the voltage pushes (Kp)
  • Leftover error accumulates over time and gets squeezed out (Ki)
  • The faster the error is changing, the more the push is trimmed to prevent overshoot (Kd)

Try this

1With Kp = 4, Ki = 50, Kd = 0.02, make a big SP step and note how high blue peaks past the target
2Set Kd to 0 and repeat. The overshoot grows — the brakes are gone
3Crank Kd to 0.05. Yellow (MV) turns jittery — on real hardware, sensor noise would make it thrash
4Watch the lower chart at the instant of an SP step: that sharp yellow spike is D doing its job

What to look for

With a moderate Kd, blue stops punching through gray. Look for the moment the yellow trace eases off early, just before arrival — that’s the brake being applied. But don’t overdo it: D reacts to change, which means it reacts to noise too. In the field, engineers often keep D small or skip it entirely and run PI — and after a minute of playing with this figure, you’ll feel exactly why.

Loading simulator…

Status

3.00 V Once it settles, move me!
4 How eagerly it chases the target.
Too strong = overshoot and wobble.
50 How fast leftover error is erased.
Too strong = more overshoot and sway.
0.02 Braking against overshoot.
Too strong = twitchy, noise-sensitive.

SP/PV

MV

Powered by CircuitJS1 (Paul Falstad / Iain Sharp et al., GPL)

6. Holding Steady Against Disturbances (Fig. 5)

So far we’ve watched the controller chase a changed target. But where feedback control really earns its keep is when the world interferes without asking: someone opens a window and the room chills, the road tilts uphill, a gust shoves the drone sideways. Any unplanned push that knocks PV off target is called a disturbance.

Here is the elegant part: PID needs no extra machinery to handle disturbances. The equation is the very same one from Fig. 4.

\[ MV = K_p\, e + K_i \int e\, dt + K_d \frac{de}{dt} \]

The controller has no idea why the error appeared. It reacts to the bare fact that an error exists — whether you moved the target or the world shoved the process. This indifference to cause is exactly what makes feedback control so robust.

The rule driving this figure (same PID as Fig. 4)

  • P, I, and D all working exactly as before
  • The “Disturbance pulse” button injects a voltage into the circuit from the side, forcibly knocking PV off target

Try this

1With Kp = 6, Ki = 60, Kd = 0.02, wait for blue (PV) to settle onto gray (SP)
2Hit “Disturbance pulse”. Red (Dist) spikes in the lower chart and blue gets shoved upward
3Watch blue find its way back to gray on its own — and watch yellow (MV) dig in to make it happen
4Set Kd to 0 and pulse again. Compare the shape of the recovery (first reaction, sway)

What to look for

Right after the pulse hits: D reacts first to the sudden change, P shoves back, and I mops up whatever error is left — the whole division of labor plays out inside a single recovery. When you open a window in an air-conditioned room and the temperature drifts back a few minutes later, this exact sequence is what’s happening behind the wall.

Loading simulator…

Status

3.00 V Once it settles, move me!
6 How eagerly it chases the target.
Too strong = overshoot and wobble.
60 How fast leftover error is erased.
Too strong = more overshoot and sway.
0.02 Braking against overshoot.
Too strong = twitchy, noise-sensitive.

SP/PV

MV/Dist

Powered by CircuitJS1 (Paul Falstad / Iain Sharp et al., GPL)

7. PID Is Hiding All Around You

The “P + I + D” stack we just built is not some exotic factory technology. It is close to invisible precisely because it is everywhere:

  • Air conditioners and water heaters — settling snugly at the set temperature and recovering when a door opens. Inverter-driven units typically run PID-family temperature loops.
  • Cruise control — throttle position is the MV, road speed is the PV, and the hill is the disturbance.
  • Drones — attitude angles corrected by PID hundreds of times per second. A drone leveling itself after a gust is Fig. 5, verbatim.
  • 3D printer hotends — holding roughly 200 °C to within a degree. Open the firmware settings and you’ll find Kp, Ki, and Kd listed by name.
  • Rice cookers and ovens — the fancier the model, the finer the temperature-profile tracking.
  • PLCs and process controllers — the standard building block for temperature, pressure, and flow loops in industry. The “auto-tune” button? It picks Kp, Ki, and Kd for you.

Meanwhile, the space heater and the electric kettle still run plain on–off control (Fig. 1) — and rightly so. If wandering inside a band costs nothing, simplicity wins. Add only as many terms as the required precision demands: the path we walked in this article — ON/OFF → P → PI → PID — is also, step for step, how a practicing engineer decides how much controller a job actually needs.

8. What to Watch for on Real Hardware

Three issues look tame in the figures but show up immediately on real hardware. As it happens, the control code running this very page quietly implements a counter-measure for each one.

  • Saturation — real actuators have hard limits (a heater cannot exceed 100%). While MV is pinned at a limit, the neat linear equations stop applying.
  • Integral windup — if the integrator keeps accumulating while the output is saturated, the stored-up push explodes into a huge overshoot when the output comes free. The standard cure: stop integrating while saturated (this page’s code cancels the integration step whenever the output clips).
  • Derivative vs. noise — D amplifies whatever changes fast, and nothing changes faster than sensor noise. Real controllers add a low-pass filter to D, keep it small, or drop it and run PI.

One more piece of demystification. Inside a microcontroller or PLC, the integral is just a running sum and the derivative is just “this sample minus the last one.” The JavaScript driving this page computes exactly:

\[ MV_n = K_p\, e_n + K_i \sum_{k} e_k\, \Delta t + K_d\, \frac{e_n-e_{n-1}}{\Delta t} \]

The textbook form (integrals and derivatives) and the code form (sums and differences) are the same idea in different clothes. Once it clicks that the intimidating formula compiles down to additions and subtractions, PID stops being theory and becomes a tool.

Summary

  • Control means deciding a command (MV) that brings the actual value (PV) to the target (SP) and holds it there.
  • On–off control (Fig. 1) is simple and rugged — but forever shuttles inside its hysteresis band.
  • P control (Fig. 2) kills the hunting, but “no error, no push” leaves a steady-state offset (for this device, \(e_{\infty}=SP/(1+K_p)\)).
  • Adding I gives PI (Fig. 3): accumulated error supplies the sustained push, erasing the offset in principle — at the price of overshoot.
  • Adding D gives PID (Fig. 4): anticipatory braking against overshoot, at the price of noise sensitivity.
  • The finished PID handles setpoint changes and disturbances (Fig. 5) with one and the same equation.
  • From air conditioners to drones, PID is a standard part of everyday machines — and where on–off is enough, on–off is still what’s used.
FigureControllerTerm addedWhat you see
Fig. 1On–offHunting (shuttling inside the band)
Fig. 2PProportionalNo more hunting, but a leftover offset
Fig. 3PI+ IntegralOffset erased; overshoot creeps in
Fig. 4PID+ DerivativeBraking ahead of the overshoot
Fig. 5PID + disturbanceSame equation, automatic recovery

FAQ

Q1. Is this circuit an actual temperature controller?

A. No — it’s a stand-in. The resistor–capacitor pair reproduces the “responds with a lag” character shared by heaters, motors, and many other real processes (a first-order lag), fast enough and safely enough to run in your browser. With τ ≈ 4.7 ms, a full response fits inside the chart’s 0.05-second window.

Q2. How do you choose Kp, Ki, and Kd?

A. That process is called tuning. Classic recipes exist (the Ziegler–Nichols method being the most famous), and industrial controllers and drone firmware ship with auto-tuning that picks the gains for you. Tuning by hand, the time-honored order is: shape the response with P alone, add I to erase the offset, then add a pinch of D only if you need it — which is precisely the order of this article’s chapters.

Q3. Why is the control computed in JavaScript instead of inside the circuit?

A. Partly because CircuitJS1 has no ready-made PID block, and partly to keep the sliders, charts, and circuit synchronized on one page. The page’s script reads PV out of the simulation, computes the PID law, and writes the result back into the voltage source SoftMV — the same read-sensor → compute → write-output loop you would run on a microcontroller.

Q4. Is this the same PID as in a PLC or a process controller?

A. The skeleton is identical, but production implementations add refinements: derivative-on-PV, derivative filtering, anti-windup schemes, bumpless transfer, and more. Treat this article as a learning model of the skeleton.

Q5. I’ve heard practitioners often skip D. Is that true?

A. “Often, yes” is the honest answer. On noisy processes and slow temperature loops, PI is frequently all you need, and D’s benefit comes bundled with noise amplification. The jitter you saw in the yellow trace when you cranked Kd in Fig. 4 is that risk in miniature.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *