I Built a Thing to Explain PID

While I focus on neural network control, its still often useful to use PID control for low-level controls. When talking about this to people outside of control theory, I wanted a thing that lets me actually demo a PID controller. And since its an easy concept, its fun to teach/learn this stuff even if its not in your wheelhouse at all 🙂

Device Overview


Above you can see the device, unpowered. The pointer (pictured pointing straight up) is connected to a standard DC Motor, which is equipped with a quadrature encoder. (I’ll list all parts and code below).

There is also a OLED screen to show the PID values, the error and a few other things, described more below.

There are also three knobs to control the PID values.

Thats it!

Device in Action


Above you can see that when all knobs are set to zero, the pointer just falls over when pushed. Once I set the P value to 5, it starts to recover.

Screen Overview


Above you can see a closeup of the screen powered on. (Please excuse the glare!).

  • PID Values
  • Error – used for ‘P’
  • Prev Error – used for ‘D’
  • Acc Error -accumulated of error, used for ‘I’
  • Command – Final value sent to motor driver


Electronics Overview


Above you can see the insides. The left is the bottom, and the right is the top. I’ll make the parts list below links so you can purchase, or find out more specs if you are interested.

On the base (left photo) there are only three components:

On the top (right photo), there are a bit more fellows:


here is the code. There is not too much to say about it as it was straightforward.

Retrospective: The Parts I’d Improve

  • There is a bit of wiggle (backlash) given the gear-train on the DC motor. This means that the pointer can change angles without the encoders pickup on that change, which results in a bit of confusion for the learner. If I were to build this again, I’d put the encoder downstream the gear-train, so that every motion would be picked up, and the PID controller would work to get the pointer to a more specific place
  • The knobs turn potentiometers. Even though I’ve stepped down the possible range of values from 0-10, there is still a possible flicker between numbers if the knob is in just the right place. Better would have been to use a rotary encoder.

Retrospective: The Parts I’m Happy About

I’ve explained PID controllers to a hand-full of people using this device now, and I really find it useful. Each time, the person learning asks questions like, “won’t it work if we just use high P and nothing else?” or “Why do we need the D component?” and using this device I can let them experiment and learn for themselves. Once the lesson is over, they walk away really having internalized whats going on. I consider this project a success 🙂