Everything around you is secretly using PID

Blog  — Sun 16 Feb 2025

In a world full of IT, there is an underrated hero. A piece of code most people don’t even know exists, yet it appears virtually everywhere in IT.

To name a few examples:

  • Cruise control in your car
  • Drones in war zones
  • Central heating
  • Rockets in space exploration
  • Ventilators in hospitals
  • Autofocus and image stabilization in cameras

And I could go on. The world is full of them. But what are we talking about? Well, it's the PID.

A PID, which stands for Proportional Integral Derivative, is essentially a mathematical formula. Well, we call it an algorithm. An algorithm that continuously looks at the difference between where you are and where you want to be. And that difference is called “the error.” The PID then determines how strongly to adjust, based on three principles. More on those three principles later.

In the software world, this algorithm is wrapped into a function. And at regular intervals, you ask it the same question: we are ‘here’, and we want to go ‘there’. How do we do that? The behavior seems almost magical. You keep feeding the PID two pieces of information:

  1. Where are we now
  2. Where do we want to go

And the PID gives back one thing: a control signal to get there.

Very concretely: suppose you have a digital thermostat. You tell the PID it’s currently 16 degrees, and you want it to be 21 degrees. The PID returns a number. You pass that number to the heating system. Suppose the system can be off or on, but also anywhere in between. Then you might have a range from 0 to 100%. The PID value could initially be 100%, because the difference is still large. But as the temperature rises, you keep feeding the current temperature back to the PID. And it adjusts its control signal accordingly.

As the boiler runs at 100%, the temperature rises. And the PID receives the new temperature every second. This way, it can continuously adjust its response as we approach the target point. Just before it hits 21 degrees, the PID says: okay, we only need to heat at 5% now. If you were to plot the PID’s control signal on paper, you’d see a nice, smooth curve. No abrupt jumps, but a gradual, elegant movement toward the goal.

That goal is called the setpoint. In this example, that’s 21 degrees. The input we give the PID is the current temperature. But how does the PID determine what to do exactly? That’s where the three letters come in: P, I, and D. I mentioned them briefly. They stand for Proportional, Integral, and Derivative. And together they determine how the PID controls the system. From where we are now to where we want to be.

Each has its own role:

  • P (Proportional): reacts directly to the error. The larger the difference, the stronger the reaction. So suppose you choose a P-value of 0.25. With an error of 5 degrees, the PID then outputs 0.25 × 5 = 1.25, which translates to 125% (which you of course cap at 100% in your software). That’s what we call a clamp.
  • I (Integral): looks at the accumulated error over time. So if the system remains slightly off for a while, the I helps eliminate that error. A kind of memory.
  • D (Derivative): looks at how quickly the error is changing. So if the temperature is rising rapidly toward 21, the D says: “Whoa! You're going too fast. Start slowing down already.”

With just the P, you can already get quite far. But the system might overshoot its target. For example, reaching 23 degrees instead of 21. That’s called overshoot. The I helps correct that over time, while the D helps prevent overshoot by braking early.

And all of that with one clever algorithm. The PID. Invisible, yet essential everywhere. Anyway, this blog has already gotten a bit long. Maybe more next time. Like PID tuning. Or what can go wrong. Because believe me, there's enough magic *and* frustration in that too, worth writing about.