Skip to content
Velloreth
Engineering & Robotics 12 min read

PID Controllers Explained Intuitively

What the three terms of a PID controller actually do, how each one changes the response, how to tune them with Ziegler-Nichols, and the failures you will meet first.

By

A PID controller is a loop, not a formula. Something is measured, compared against a target, and the difference drives an actuator that pushes the measurement toward the target. The formula people memorize is just the rule for turning that difference into a command — and the three terms in it each exist to fix a specific failure of the term before it.

Once you can look at a response curve and say which term is misbehaving, tuning stops being guesswork.

The loop, concretely

Take a motor you want spinning at 1000 rpm. You measure the actual speed, subtract it from the setpoint, and get the error. The controller turns error into a command — usually a voltage or a PWM duty cycle — and the motor responds.

setpoint ──►(+)──► PID ──► actuator ──► plant ──► measurement
              ▲                                    │
              └────────────── feedback ◄───────────┘

The error is e(t) = setpoint − measurement. Everything else is a decision about how to convert e(t) into an output:

TermReadsQuestion it answers
Proportional (Kp)present errorHow far off am I right now?
Integral (Ki)accumulated errorHave I been off for a while?
Derivative (Kd)rate of change of errorAm I approaching too fast?

In the ideal (parallel) form:

u(t) = Kp * e(t) + Ki * ∫e(t)dt + Kd * de(t)/dt

Many textbooks use the series form with integral time Ti and derivative time Td instead of Ki and Kd:

u(t) = Kp * ( e(t) + (1/Ti) * ∫e(t)dt + Td * de(t)/dt )

The two are the same controller with different parameterization: Ki = Kp/Ti and Kd = Kp*Td. Watch which convention your library uses — mixing them up is the most common cause of a “tuning that makes no sense.”

Proportional: the present

Double the error, double the push. P control is immediate and intuitive, and it does most of the work.

It has one structural flaw: it needs error to produce output. If the load requires 30% duty cycle to hold the motor at 1000 rpm, the controller will settle at whatever error makes Kp × error = 30%. That residual is the steady-state offset. You can shrink it by raising Kp, but only by raising it, and gain costs stability — higher Kp means more overshoot and, past a point, sustained oscillation.

Raising Kp cannot eliminate the offset. Something has to produce output when the error is zero, and that is the integral term’s job.

Integral: the past

The integral accumulates error over time. Even a small persistent error grows the term until the output moves far enough to drive the error to zero. That is why PI or PID control achieves zero steady-state offset where P alone cannot.

The cost is history. The integral carries every past error forward, which shows up in two ways:

Overshoot. As the measurement approaches the setpoint, the integral is already large from the earlier error, so it keeps pushing past the target. The error reverses, the integral has to drain, and the system swings back. A little of this is normal; a lot means Ki is too high.

Windup. If the actuator saturates — heater at 100%, valve fully open — the measurement cannot catch the setpoint, so the integral keeps growing the whole time. When the error finally shrinks, the controller is sitting on a huge stored integral and unwinds slowly, driving a large overshoot on the way back.

Anti-windup, in order of preference:

  1. Clamp the integral so Ki * integral can never push the output beyond the actuator range.
  2. Conditional integration — freeze the accumulator entirely while the output is saturated.
  3. Back-calculation — when saturated, drive the integrator toward the value that would make the output exactly the saturation limit.

For a first implementation, clamping is enough:

float pid_update(PID *c, float error, float dt) {
    c->integral += error * dt;

    float out = c->kp * error + c->ki * c->integral;
    float sat = out > c->out_max ? c->out_max
              : out < c->out_min ? c->out_min : out;

    if (sat != out) {
        out = sat;
        c->integral = (out - c->kp * error) / c->ki;  /* back-calculation */
    }
    return out;
}

Derivative: the future

The derivative term looks at how fast the error is changing and applies braking. Approaching the setpoint quickly produces a large negative derivative contribution that slows the approach, which reduces overshoot and lets you run a higher Kp than you otherwise could.

Three things go wrong with it in practice:

  • Noise. Derivative amplifies high-frequency content. A measurement noise of ±0.5 units sampled at 1 kHz produces spikes in de/dt, and the controller will jitter the actuator. Filter the measurement, or use a low-pass filter on the derivative term with a corner around 10–30 Hz for most mechanical loops.
  • Derivative on error vs on measurement. If the setpoint changes as a step, de/dt on the error becomes a huge spike that slams the actuator. Compute the derivative on the measurement instead — it produces the same damping during disturbances and no spike on setpoint changes.
  • Setpoint ramping. For position commands, ramp the setpoint rather than stepping it, so the controller is never asked to change velocity instantaneously.

If your process is slow — a tank level, a large thermal mass — the derivative term usually buys you nothing and only imports noise. PI is the right structure there.

What each term looks like on a response

Given a step change in setpoint, the shape tells you what to adjust:

ResponseLikely causeFirst move
Rises slowly, settles short of targetKp too low, no integralRaise Kp, or add Ki
Reaches target, holds a constant offsetP-only, or Ki too lowAdd or raise Ki
Overshoots once, settlesNormal, slightly aggressiveReduce Ki a little
Overshoots repeatedly, decays slowlyKp or Ki too highCut Ki first, then Kp
Sustained oscillationGain too high or delay too largeReduce gains 20–30% and retest
Jittery output, noisy actuatorDerivative on noisy signalFilter, or drop Kd
Overshoot only after big setpoint changesWindup or unfiltered derivativeFix anti-windup, ramp setpoint
Slow drift after disturbanceIntegral too weakRaise Ki

Tuning: Ziegler-Nichols and what it is really telling you

You need a repeatable procedure, not intuition. The classic one is Ziegler-Nichols, published in 1942, and there are two variants.

Closed-loop (ultimate gain) method

  1. Set Ki = 0 and Kd = 0 so the controller is pure P.
  2. Raise Kp from zero in small steps, waiting for the response to settle after each change, until the output oscillates with sustained, constant amplitude. If output limits are being hit, you have not found the real limit — reduce the experiment amplitude.
  3. Record that gain as Ku (ultimate gain) and the period of oscillation as Pu (ultimate period).
  4. Compute the settings:
ControllerKpTiTd
P0.5 * Ku——
PI0.45 * KuPu / 1.2—
PID0.6 * KuPu / 2Pu / 8

These are the classic rules; variants exist with different aggressiveness. The “no overshoot” row of the extended table uses Kp = 0.2 * Ku for PID, which is a reasonable fallback if the classic tune rings too much.

Note what the rules assume: a response with roughly quarter-amplitude decay, where each oscillation peak is about a quarter of the previous one. That is a deliberate choice favoring disturbance rejection over smoothness. It is often more oscillation than you want, and reducing Kp by 20–30% from the Ziegler-Nichols value is a normal next step, not a failure of the method.

Open-loop (reaction curve) method

If you can safely step the actuator and watch the process, this avoids pushing the loop to the edge of instability:

  1. Hold the process steady, then step the controller output by a known amount Δm.
  2. Record the response curve and measure L (dead time — the delay before the process reacts) and R (the slope of the steepest part of the response, in units of process variable per second).
ControllerKpTiTd
PΔm / (R * L)——
PI0.9 * Δm / (R * L)3.33 * L—
PID1.2 * Δm / (R * L)2 * L0.5 * L

The dead time L dominates everything. A process with large dead time — long pipes, conveyor delays, sensor lag — is fundamentally hard to control with PID, and the formulas will hand you a low gain as a warning. When L is comparable to or larger than the process time constant, consider feedforward, a predictor, or accepting a slower loop rather than cranking gain.

The practical sequence

Regardless of method:

  1. Start with Ki = 0, Kd = 0. Raise Kp until the response is fast enough but not ringing. Write down the value.
  2. Add Ki in small increments. Watch the offset disappear and watch for overshoot. Stop before overshoot becomes persistent.
  3. Add Kd last, with filtering, only if overshoot or settling time still needs work.
  4. Disturb the system deliberately — load the motor, open the door of the chamber — and confirm it recovers. Tuning for setpoint tracking and tuning for disturbance rejection are not the same test, and disturbance rejection is usually the one you care about.

A worked tuning pass

Numbers make the method concrete. Suppose a hot plate in open loop: you step the duty cycle output from 20% to 40% (Δm = 20 percentage points), and the thermocouple does nothing for 12 seconds, then climbs at a steepest slope of 0.05 °C/s.

So L = 12 s and R = 0.05 °C/s, giving R * L = 0.6 °C:

ControllerCalculationResult
P20 / 0.6Kp = 33.3 %/°C
PI0.9 * 33.3, Ti = 3.33 * 12Kp = 30, Ti = 40 s (Ki = 0.75)
PID1.2 * 33.3, Ti = 2 * 12, Td = 0.5 * 12Kp = 40, Ti = 24 s, Td = 6 s

Deploy the PI values first, run one setpoint step from 60 °C to 80 °C, and look. If it overshoots by several degrees and rings, halve Ki before touching Kp. If it creeps to target and sits 2 °C low, the integral is doing its job too slowly — raise it in 50% increments and retest.

Now compare with the closed-loop route on the same plant: raise Kp until it sustains oscillation, find Ku = 4.0 and Pu = 30 s. The classic rules give Kp = 2.4, Ti = 15 s, Td = 3.75 s. Both methods landed on gains in the same neighborhood, which is the point — they are two ways of measuring the same process dynamics, and agreement between them is a good sign before you commit.

Implementation details that decide whether it works

Sample time matters. dt must be real and measured, not assumed. A controller running on a fixed timer still drifts if tasks block; use a monotonic clock and clamp dt after a stall so a delayed update does not inject a giant integral step.

Derivative filtering:

float alpha = dt / (dt + rc);          /* rc = 1/(2*pi*fc) */
d_meas = alpha * ((meas - prev_meas) / dt) + (1 - alpha) * d_meas;
output = kp * error + ki * integral - kd * d_meas;   /* minus: derivative on measurement */

Saturation is part of the design. Explicitly clamp the output to what the actuator can do, and make sure the integral cannot outlive that clamp.

Gain scheduling. If the process changes character across its range — a valve with very different authority at low flow, a battery-powered actuator weakening as the cell drains — one set of gains cannot be optimal everywhere. Schedule Kp/Ki as a function of operating point rather than pretending the plant is linear.

Feedforward beats feedback for known disturbances. If you know the load will change by a measurable amount, add the expected correction directly to the output and let PID mop up the residual. Feedback then only has to handle what the model missed.

When PID is the wrong tool

PID assumes a plant that reacts predictably: more input, more output, roughly linear, with modest delay. It struggles when:

  • Dead time dominates. Without an explicit delay model, the controller is always reacting to old information.
  • The process is strongly nonlinear. One set of gains cannot serve both ends of the range without scheduling.
  • You are controlling several coupled variables at once. A quadcopter attitude, a distillation column, a multivariable thermal chamber — these need coordinated control, where individual PID loops fight each other.
  • You lack a clean measurement. A controller is only as good as its sensor; noisy or biased feedback makes derivative action unusable and integral action accumulate nonsense.

For those, the toolbox extends to cascade loops (an inner current loop under an outer speed loop), state estimators, model predictive control, and simple feedforward. PID remains the workhorse underneath most of them — the inner loop usually is one.

The place to start is not the formula but the response curve. Get the loop into automatic with a modest gain, change the setpoint once, and look at what comes back. The shape of that curve tells you which of the three terms to touch next, and after a few iterations you are not tuning a formula — you are reasoning about a physical system that has inertia, delay, and limits.

Frequently asked questions

What does each letter in PID stand for?
Proportional, Integral, Derivative. Proportional produces output proportional to the current error, integral produces output proportional to the accumulated error over time, and derivative produces output proportional to how fast the error is changing. The controller output is the sum of the three terms.
Why does my system oscillate after I increase the gain?
Excess proportional gain makes the controller overreact, and each overshoot triggers a larger correction — the loop has run out of phase margin. Reduce Kp until oscillation stops, then reintroduce integral action slowly. If oscillation persists at low gain, the loop delay is probably too large relative to the process time constant, and no amount of tuning will fix that.
Do I always need all three terms?
No. Many temperature and motor loops run on PI alone because the derivative term adds noise sensitivity for little benefit on slow processes. Pure P is adequate where a small steady-state offset is acceptable, and D earns its place on fast, well-characterized systems such as servo position loops.
What is integral windup?
Windup happens when the actuator is saturated — a heater at 100%, a valve fully open — while error keeps accumulating in the integral term. When the error finally changes sign, the controller must first unwind all that stored integral before responding, which produces a large overshoot. Clamp the integral, or stop integrating while the output is saturated.