PID control explained

A zero preparation starting point

Mattia Maldini
13 min readDec 17, 2018

PID control is a mathematical approach to a broad range of output control scenarios. Whenever a system needs to tune an output based on some input value, PID techniques offer a neat starting point to implement a solution.

There are countless thousand pages books out there delineating the perfect way to use and manage PID control in your process. Like in most things however, the core concept can be useful even with a much lower effort, and I do believe online resources on the topic are somewhat lacking for beginners. So here we are.

The problem

Our system has an input value taken in by sensors every x time units (minutes, seconds, milliseconds; in abstract it doesn’t matter). Depending on said value a proper output response has to be calculated in order to reach a desired state. To throw in some examples, we could be talking about:

  • A thermostat. The input value is the current temperature and the output is the “power” of heating system.
  • A robotic arm. The input value is its position and the output is the voltage and direction to apply to its actuators.
  • A valve controlling water flow. The input is the current flow and the output is the speed and direction of the motor attached to the valve, allowing more or less liquid to pass through.
  • A cart trying to arrive to a destination point. The input is the distance between here and the goal, and the output is the speed and the direction with which to proceed.
  • A quadcopter trying to balance itself. The input is the angle it’s currently leaning on and the output is the power to apply to each rotor.

From a purely theoretical standpoint the problem can be defined by variable representing the current state of the system (temperature, flow, position,…). The input read every period is the process variable (or PV); the goal of our control system is to reach and maintain a certain value for this variable, called the SetPoint (or SP). At any given moment t it’s useful to consider the current error, given by the difference between the SetPoint and the process variable, e(t) = SP-PV.



Mattia Maldini

Computer Science Master from Alma Mater Studiorum, Bologna; interested in a wide range of topics, from functional programming to embedded systems.