Problem with PID Library

Hello,
I got a pretty simple sketch using the PID Library but have the problem, that on serial Monitor the output value goes up to 255 almost immediatly, even if my Setpoint is 40.

+Using Arduino Uno

Code:

#include <PID_v1.h>

double Setpoint, Input, Output;

PID myPID(&Input, &Output, &Setpoint,2,5,1, DIRECT);

void setup()
{
  Input = 10;
  Setpoint = 40;
  myPID.SetMode(AUTOMATIC);
      Serial.begin(9600);
}

void loop()
{
  myPID.Compute();
  Serial.println(Output);
}

That's not that strange is it?

Input and output have no relation whatsoever in you're code. Input is 10 and you want 40 but the output isn't pushing that 10 closer to 40 so it just tries harder. :smiley:

It's like disconnecting the engine in your car (clutch engaged / in neutral) an trying to go from 10km/h to 40km/h. You think you do that by pushing the throttle so you push it a little. But your still going slow so you push it harder and harder and harder. Difference with a PID and you is you might suspect something is wrong, a PID will just reach it's limits.

Ok, I understand, but how do I build up this relation?

PID is generally used to control some physical hardware. What are you trying to do with it?

wildbill:
PID is generally used to control some physical hardware. What are you trying to do with it?

Right, the output of the PID drives the input of a physical system (the Plant). This produces a change in the Plant’s output – otherwise, why would you be trying to control it with a PID? You measure this output and supply it as the Input of the PID (feedback). The PID then compares this input to the Set Point producing the Error Signal. The Error Signal is filtered by the PID’s control function to become the PID’s Output. The cycle then starts over again.