# How to set PID parameter Kp, Ki and Kd?

Right now, I'm working with Peltier module using PID algorithm. I search out on the Internet about this and so I found that there are three parameters Kp, Ki and Kd. And everyone uses the different value for that. So, they actually calibrate that value but I don't understand how?

I just use default value like Kp = 2, Ki = 5 and Kd = 1.

And here I take Input as Temperature. My normal temperature is around 25. And now I set my setpoint 20. So, according to the PID algorithm temperature must be reduced to around 20. But still, no change in temperature and my PWM is still 0.

Below is my code:

``````#include <PID_v1.h>

int thermoDO = 3;
int thermoCS = 4;
int thermoCLK = 5;

#define PIN_OUTPUT 6

//Define Variables we'll be connecting to
double Setpoint, Input, Output;

//Specify the links and initial tuning parameters
double Kp = 2, Ki = 5, Kd = 1;
PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);

int IN1 = 8;
int IN2 = 9;

void setup()
{
Serial.begin(9600);

//initialize the variables we're linked to
Setpoint = 20;

//turn the PID on
myPID.SetMode(AUTOMATIC);

pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
}

void loop()
{
myPID.Compute();
analogWrite(PIN_OUTPUT, Output);

digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);

Serial.print("Setpoint: ");
Serial.print(Setpoint);
Serial.print("\t");
Serial.print("Input: ");
Serial.print(Input);
Serial.print("\t");
Serial.print("Output: ");
Serial.print(Output);
Serial.print("\t");
Serial.print("Kp: ");
Serial.print(myPID.GetKp());
Serial.print("\t");
Serial.print("Ki: ");
Serial.print(myPID.GetKi());
Serial.print("\t");
Serial.print("Kd: ");
Serial.print(myPID.GetKd());
Serial.print("\n");
}
``````

And my output is like:

``````Setpoint: 20.00 Input: 24.50    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.50    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.50    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.50    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.50    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.50    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.50    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.50    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
``````

Now here I use MAX31855 module for measuring the temperature which takes as Input here.

MAX31855 Module:

I think that may be my Kp, Ki and Kd are not perfect for my system. So, maybe this cause problem means not the proper value of Kp, Ki, and Kd. Can anyone give some suggestion how to set this value of Kp, Ki, and Kd? Or there is something else which caused the problem for that. Suggest me.

And here I'm using DC motor driver(20A) for driving the Peltier Module.

• Sorry Hasan, I cannot find your other post where I added a comment, which was about this problem but with more noisy measures. Did you cancel it? Commented Dec 13, 2017 at 11:30
• @frarugi87 Yes, I deleted that post because I thought that post was not cleared as I want. But now my problem is solved. And thank you for your answer. Commented Dec 13, 2017 at 11:44
• Well, it was a different question than this, so I think you should've posted an answer on that topic. How did you solve the problem you had? Was it due to noisy measurements? Or wrong setup? Commented Dec 13, 2017 at 12:48
• @frarugi87 Ok, If you think so then I will definitely post it. Actually, both questions' motto is same. And as you see that noisy measurement is only due to some loose connections. After I tried out again and I got the proper fine result. Commented Dec 14, 2017 at 13:58
• No, I think that reposting the previous question is useless; in any case so it was just a loose connection? Commented Dec 14, 2017 at 14:15