Go Down

Topic: Arduino PID Library (Read 59 times) previous topic - next topic


I am so pleased to have found the PID Library that you created, br3ttb.

It could be the perfect solution to my current challenge.  I have a question regarding the output.

The analogy that you give regarding the cruise control is a nice one, and I understand the beauty of the PID's ability to limit the overshoot by "letting up on the gas."

My basic question is how do I interpret the "Output Value?"  What does it represent?  It seems to be a "Correction Value" specifically related to the "Input Value" and the "Setpoint."  

This may seem obvious, but so far (without using the PID) I have been splitting my sensor input, which is a value between 0-255 at my desired setpoint, roughly the mid-point, and using the values on one side of the setpoint to drive a motor in one direction and the values on the other side of the setpoint to drive the motor in the opposite direction.

Thus, my question...given the one value for Output how should i interpret this value

I imagine that I could split the value and feed it into two separate PID's if that is necessary.

Thanks for any help :D


Jan 14, 2009, 03:19 pm Last Edit: Jan 14, 2009, 03:32 pm by br3ttb Reason: 1
what I would suggest is to have your output range from negative to positive.  (-255 to 255 say)  your code would look something like this:
Code: [Select]
double Input, Output, Setpoint;
PID pid(&Input, &Output, &Setpoint, -3,4,1);

void setup()

  pid.SetIOLimits(0,1023,-255,255); //tell the PID to range the output from -255 to 255
  Output = 0; //start the output "motor stopped" and vary from there

  pid.SetMode(AUTO); //turn on the PID

void loop()
  //give the PID the opportunity to compute if needed
  Input = //whatever your input is

   if (Output>0)
   //spin the motor one way at speed = Output
   else if(Output<0)
   //spin the motor the other way at speed = -1* Output
   //motor stopped

hope that helps,  Brett


Thanks so much, Brett.

I will try this solution.


Mike Mc

Why is it so hard to find the PID Library in the playground? there seems to be no link to it at all or am i being dumb?  :-/


Modesty mostly.  and fear.  I didn't want to presume to add my library to the lexicon.  at least not until I made sure that there weren't glaring errors I had missed.  it's been about 2 months now, so I feel a little more comfortable adding it.  here you go:  http://www.arduino.cc/playground/Main/GeneralCodeLibrary

Go Up