# PID control of DC motor

**URL:** <https://forum.arduino.cc/t/pid-control-of-dc-motor/1338806>\
**Category:** Motors, Mechanics, Power and CNC\
**Created:** [January 4, 2025, 4:35am UTC](https://forum.arduino.cc/t/pid-control-of-dc-motor/1338806 "2025-01-04T04:35:49Z")\
**Posts on this page:** 1\
**Showing post:** 16

<div class="post-metadata">

**Author:** ![DaveX](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/davex/32/751443_2.png) [@DaveX](https://forum.arduino.cc/u/DaveX)\
**Post date:** [January 6, 2025, 1:43am UTC](https://forum.arduino.cc/t/pid-control-of-dc-motor/1338806/16 "2025-01-06T01:43:25Z")

</div>

> [@jaguilar84](#):
>
> In _any_ process where the driven variable is not zero at the setpoint (e.g. a motor seeking a given speed) the P term will be zero when you've reached the steady state. In fact, if you're in a steady state where the error is low, the I term is the _only_ term that will have any value (because derr is zero or close to it, as is err).

Yes. If you are operating at the setpoint with zero error at steady state, only the integral term can possibly contribute to the output. PID systems with bumpless initialization/transfer use that fact to initialize the integral term such that `integratedError = Output/Ki`. The arduino PID library author explains his implementation of bumpless transfer here:

[http://brettbeauregard.com/blog/2011/04/improving-the-beginners-pid-initialization/](http://brettbeauregard.com/blog/2011/04/improving-the-beginners-pid-initialization/)

If there is any error or process disturbances, the tuning of the terms and their interactions is important. If you aren't completely rigorous about tuning, many implementations often depend heavily on the P term and set the setpoint a little higher than the actual desired setpoint, and rely on `output = Kp*error` to do the work. Cruise controls on cars often do this--you can't set the CC to an explicit "65mph", you just get controls to bump the unseen setpoint up or down to visually make the actual speed as desired, and accept some slop around it as the load changes when you go uphill or downhill. Relying on the P term instead of the I term trades off some of some level of error for more robustness.

I've got some Wokwi simulations of PID systems in this thread:

> [@PID with simulated heater or motor](https://forum.arduino.cc/t/pid-with-simulated-heater-or-motor/1093539/16):
>
> Here are the plain Arduino PID example code demos implemented in Wokwi: I think the simulation where you are the process/plant and use a slide potentiometer to communicate your ProcessVariable to the PID are the most hands-on in understanding those PID examples: [[image]https://wokwi.com/projects/412997833205485569](https://wokwi.com/projects/412997833205485569) and [[image] https://wokwi.com/projects/410423413759806465](https://wokwi.com/projects/410423413759806465)

---

_[View the full topic](https://forum.arduino.cc/t/pid-control-of-dc-motor/1338806)._
