1

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>
#include "Adafruit_MAX31855.h"

int thermoDO = 3;
int thermoCS = 4;
int thermoCLK = 5;
Adafruit_MAX31855 thermocouple(thermoCLK, thermoCS, thermoDO);

#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
  Input = thermocouple.readCelsius();
  Setpoint = 20;

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

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

void loop()
{
  Input = thermocouple.readCelsius();
  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:

MAX31855

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? – frarugi87 Dec 13 '17 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. – Hasan Dec 13 '17 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? – frarugi87 Dec 13 '17 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. – Hasan Dec 14 '17 at 13:58
  • No, I think that reposting the previous question is useless; in any case so it was just a loose connection? – frarugi87 Dec 14 '17 at 14:15
5

PID algorithms basically change the output to approach the setpoint. Now in your case you have a setpoint of 20 and an input of 24.5. Thus the algorithm thinks it needs to turn the output off so it can "cool down". This would work for a heater.

However since your output is a cooler you need to specify "REVERSE" rather than "DIRECT". This tells the PID module that the output needs to be higher if the input is higher than the setpoint.

| improve this answer | |

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.