Motor control with PID and PWM

Working on adding encoders to my project and could use some resources/help on understanding how to code pulse width modulation (PWM) with Proportional Integral Derivative (PID) to control brushed DC motors. Any help would be wonderful. 


ISRs with arduino is what you need

Dear: Wilsorob

Just to let you know if you are to use encoders and to get a decent reading from them you are going to need some ISRs. Preferable you need one for each encoders but that may vary depending on the encoders. Look here for using encoders with arduino.

Also in case you are wondering what an ISR is it is an interrupt service routine. Basically it is a very fast loop with not a lot of memory. You can not write a lot of code in an ISR fewer the better so good luck!!!

From: Noah

Simple explanation of PID.


Robb, for a simple introduction to PID, I don’t think you can do better than Mark Harrison’s video HERE, with part 2 HERE.


This was super helpful.

This was super helpful. Thank you for linking these videos. 

You can have a look at my code

I just explained parts of my robot’s Arduino motor control code in another comment. I’ve also included links to some of my measurements how differently my motors reacted to the same PWM pulse (which made PID necessary) and how different PID parameters affected the results. 

Hope this helps