SHARE
TWEET

Untitled

a guest Oct 19th, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. float kp = 3; //Mine was 8
  2.           float ki = 0.6; //Mine was 0.2
  3.           float kd = 0.2; //Mine was 3100
  4.  
  5.           time = millis();
  6.           temp_error = setpoint - tempC;
  7.           PID_p = kp * temp_error;
  8.           float temp_diference = temp_error - temp_previous_error;
  9.           //Serial.println("---------------");
  10.           //Serial.print("Temp: ");
  11.           //Serial.println(tempC);
  12.           //Serial.print("error: ");
  13.           //Serial.println(temp_error);
  14.           //Serial.print("PID_p: ");
  15.           //Serial.println(PID_p);
  16.           PID_d = kd * ((temp_error - temp_previous_error) / period);
  17.           //Serial.print("PID_d: ");
  18.           //Serial.println(PID_d);
  19.  
  20.           if (temp_error < limit) // && temp_error <= limit)
  21.           {
  22.             PID_i = 0;
  23.             //Serial.print("inside error");
  24.           }
  25.           else
  26.           {
  27.             PID_i = PID_i + (ki * temp_error);
  28.             //Serial.print("outside error");
  29.           }
  30.           //Serial.print("PID_i: ");
  31.           //Serial.println(PID_i);
  32.  
  33.  
  34.           PID_total = PID_p + PID_i + PID_d;
  35.           //Serial.print("PID_total: ");
  36.           //Serial.println(PID_total);
  37.           //PID_total = map(PID_total, -150, 150, 0, 150);
  38.  
  39.  
  40.           if (PID_total >= 3) {
  41.             //Serial.println("Heating");
  42.             row1 = String(String(tempC) + "C HEAT");
  43.             heater(true);
  44.             plot = 1;
  45.  
  46.           } else {
  47.             //Serial.println("Waiting");
  48.             row1 = String(String(tempC) + "C WAIT");
  49.             heater(false);
  50.             plot = 0;
  51.           }
  52.           Serial.print(tempC);
  53.           Serial.print(" ");
  54.           Serial.print(setpoint);
  55.           Serial.print(" ");
  56.           Serial.print(plot);
  57.           Serial.print(" ");
  58.           Serial.print(setpoint + limit);
  59.           Serial.print(" ");
  60.           Serial.println(setpoint - limit);
  61.  
  62.  
  63.           temp_previous_error = temp_error;
  64. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top