I am making a system which regulates the temperature of a plate. using the PID library I programed the system as followed:

 * PID Basic Example
 * Reading analog input 0 to control analog PWM output 5

#include <PID_v1.h>
#include "math.h" 

int val, output2; 
//Define Variables we'll be connecting to
double Setpoint, Input, Output;
//Specify the links and initial tuning parameters
PID myPID( &Input, &Output, &Setpoint,0,20,20, DIRECT);

void setup()
  //initialize the variables we're linked to
  Setpoint = 37; //temperature a reguler 

  //turn the PID on
  pinMode(9, OUTPUT);
  myPID.SetOutputLimits(-100, 100);
  while (!Serial); 

void loop()
  // phase haute
  val = analogRead(1);
  float mv = ( val/1024.0)*5000; 
  Input = mv/10;
  {   output2 = map(Output, -100, 100, 0, 200); 
      Serial.print("output is :");
      // phase basse
  //Serial.print("input temperature is :");
  // Serial.println(Output);
  // Serial.println(Input);


As you can see in the code the output result is between 0 and 100. the temperature desired in the plate is 37 degre. and the actual temperature is 24 degre. consequently, the program supposes to set the value of the output to the max value to reach to 37 degre. But the problem is my output is setting to different values as you can see here: enter image description here

what can be the problem here ? thank you in advance

  • Could you add the value of Input to the serial print? – Gerben Nov 9 '15 at 19:11

As Gerben said in a comment, you should add the value of Input to the serial print, to facilitate problem diagnosis. As your question stands, one can only speculate about what the problem might be. My speculation is that the system is unable to cope with parameters (Kp, Ki, Kd) = (0, 20, 20), ie, that it's unstable and unresponsive without proportional control.

| improve this answer | |
  • you are right jwpat7. after changing the value of Ki. the output works very well, and the value of it is setting to the max which is 200. – zakaria Nov 10 '15 at 10:09
  • @zakaria, I meant to call the first parameter Kp instead of Ki (and your 0 value for Kp was why I referred to "without proportional control") and have now corrected that in my answer. That is, the parameter order in the PID constructor is (&inputreading, &controloutput, &setpoint, Kp, Ki, Kd, direction). Glad it worked! – James Waldby - jwpat7 Nov 10 '15 at 13:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.