HomeArticlesControl Engineering

PID Control: Proportional, Integral, Derivative Explained

Three terms, three failure modes fixed — how u = Kp·e + Ki·∫e + Kd·ė keeps a drone level and a thermostat honest.

mysimulator teamUpdated July 2026≈ 9 min read▶ Open the simulation

Feedback control in one sentence

Every closed-loop controller does the same job: measure the process variable (PV), compare it to a setpoint (SP), and turn the resulting error e(t) = SP − PV into a control signal that drives an actuator toward zero error. A thermostat set to 22°C in a room at 18°C sees e = +4°C, switches the heater on, watches the error shrink, and backs off as it approaches zero. The PID controller — Proportional-Integral-Derivative — is simply the most battle-tested way to turn that error into an output, estimated to run in roughly 90% of industrial control loops and in every consumer quadcopter drone.

live demo · closed-loop step response● LIVE

The equation, and what each term corrects

The controller output is a weighted sum of the present error, its accumulated history, and its rate of change:

u(t) = Kp·e(t) + Ki·∫e(τ)dτ + Kd·(de/dt)

  u(t) = controller output          Kp = proportional gain
  e(t) = setpoint − measured_value  Ki = integral gain
                                     Kd = derivative gain

Proportional (P) reacts to the error as it stands right now — bigger error, bigger correction. Push Kp too low and the response is sluggish; push it too high and the loop overshoots and rings. Used alone, P control always leaves a residual steady-state offset: a heater has to sit at some nonzero output just to counter ongoing heat loss, and the only way a pure-P law can hold a nonzero output is to keep a small permanent error alive.

Integral (I) sums the error over time, so even a tiny persistent offset keeps growing the correction until it's driven to exactly zero — this is what erases the P-only offset entirely. The cost is windup: if the actuator saturates (heater pinned at 100%) the integral keeps accumulating error the plant can't act on yet, and once the process variable finally catches up, that oversized integral overshoots badly before it unwinds.

Derivative (D) looks at how fast the error is changing and applies a brake before the setpoint is even reached — if the error is falling quickly, D pulls the output back down pre-emptively, cutting overshoot and settling time. Its weakness is that differentiation amplifies noise: a jittery sensor produces a huge instantaneous slope, so D is usually computed on the measured process variable rather than the error (avoiding a "derivative kick" on setpoint changes) and passed through a low-pass filter.

A minimal digital implementation

Discretised at a fixed timestep dt, with anti-windup clamping and derivative-on-measurement, a PID loop is barely twenty lines of JavaScript:

update(setpoint, measurement) {
  const error = setpoint - measurement;
  const P = this.kp * error;

  this.integral += error * this.dt;         // accumulate
  const I = this.ki * this.integral;

  const D = this.kd * (this.prevError - error) / this.dt;
  this.prevError = error;

  const raw = P + I + D;
  const output = clamp(raw, this.outMin, this.outMax);
  if (output !== raw) this.integral -= error * this.dt;  // anti-windup
  return output;
}

Tuning: Ziegler-Nichols and the manual method

The classic empirical recipe, published by Ziegler and Nichols in 1942, sets Ki = Kd = 0 and raises Kp alone until the loop sustains a constant-amplitude oscillation — the ultimate gain Ku at the ultimate period Tu. From those two numbers:

Kp = 0.6 · Ku
Ki = 2 · Kp / Tu
Kd = Kp · Tu / 8

This tends to be aggressive, so most engineers use it as a starting point rather than a final answer. The manual alternative is just as common: raise Kp alone until the response is fast with acceptable overshoot (roughly 10–20%), add Ki slowly until the steady-state error disappears without excessive ringing, then add a small Kd only if overshoot still needs trimming. Many industrial loops — furnaces, 3D-printer hot ends, fermenters — run PI only, because noisy sensors make the derivative term more trouble than it's worth; drones and CNC servo loops, running at 500–2000 Hz with clean IMU or encoder feedback, use all three terms.

Frequently asked questions

Why does proportional-only control always leave a steady-state error?

A P-only controller's output is u = Kp·e, so the moment the error reaches zero the output also drops to zero — but many processes (a heater fighting heat loss, a motor fighting friction) need a nonzero sustained output just to hold position. The only way a P controller can supply that output is to keep a small permanent error alive, since u must stay above zero. Raising Kp shrinks this offset but never eliminates it, and pushes the loop closer to oscillation.

What is integral windup and why is it dangerous?

The integral term keeps accumulating error even after the actuator has saturated (a heater already at 100%, a motor already at full throttle) because the physical output can't increase any further even though the mathematical error is still being summed. When the process finally catches up to the setpoint, that oversized accumulated integral keeps forcing extra output, driving a large overshoot before it unwinds. Anti-windup clamps the integral term (or back-calculates it) whenever the output saturates, so it stops growing once the actuator can't act on it anyway.

Why does the derivative term amplify sensor noise, and how is it filtered in practice?

Derivative action is Kd·(de/dt), and differentiation amplifies high-frequency content — a sensor jittering by a fraction of a degree between samples produces a huge instantaneous slope once divided by a small dt. In practice engineers differentiate the measured process variable rather than the error (removing the "derivative kick" that a setpoint step would otherwise cause) and pass it through a low-pass filter, or simply set Kd = 0 on noisy industrial sensors and accept a slightly slower settling time.

Try it live

Every gain and clamp above runs live in PID Controller. Drag Kp, Ki and Kd, inject a setpoint step or a noisy disturbance, and watch overshoot, oscillation and settling time respond in real time.

▶ Open PID Controller simulation

What did you find?

Add reproduction steps (optional)