Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float kp = 3; //Mine was 8
- float ki = 0.6; //Mine was 0.2
- float kd = 0.2; //Mine was 3100
- time = millis();
- temp_error = setpoint - tempC;
- PID_p = kp * temp_error;
- float temp_diference = temp_error - temp_previous_error;
- //Serial.println("---------------");
- //Serial.print("Temp: ");
- //Serial.println(tempC);
- //Serial.print("error: ");
- //Serial.println(temp_error);
- //Serial.print("PID_p: ");
- //Serial.println(PID_p);
- PID_d = kd * ((temp_error - temp_previous_error) / period);
- //Serial.print("PID_d: ");
- //Serial.println(PID_d);
- if (temp_error < limit) // && temp_error <= limit)
- {
- PID_i = 0;
- //Serial.print("inside error");
- }
- else
- {
- PID_i = PID_i + (ki * temp_error);
- //Serial.print("outside error");
- }
- //Serial.print("PID_i: ");
- //Serial.println(PID_i);
- PID_total = PID_p + PID_i + PID_d;
- //Serial.print("PID_total: ");
- //Serial.println(PID_total);
- //PID_total = map(PID_total, -150, 150, 0, 150);
- if (PID_total >= 3) {
- //Serial.println("Heating");
- row1 = String(String(tempC) + "C HEAT");
- heater(true);
- plot = 1;
- } else {
- //Serial.println("Waiting");
- row1 = String(String(tempC) + "C WAIT");
- heater(false);
- plot = 0;
- }
- Serial.print(tempC);
- Serial.print(" ");
- Serial.print(setpoint);
- Serial.print(" ");
- Serial.print(plot);
- Serial.print(" ");
- Serial.print(setpoint + limit);
- Serial.print(" ");
- Serial.println(setpoint - limit);
- temp_previous_error = temp_error;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement