PID controller problems SOLUTION

Hello I need help, I have a pid control to control the temperature but when it reaches the temperature after 1 minutes it resets to zero help please.
I am using a controllino and a DHT21 sensor

the output is permanently reset
it only changes if i restart the program at that moment it starts calculating again

I have solved it in the end it was a current problem, I was feeding a relay module with the 5v output of controllino Thanks to all

Post your code.

ok it's ready

Start with Kp = 0
kp * error = Pterm
in other words, when error equals 0 output equals 0 so Proportional is not the best way to control the temperature as when you reach the temperature you add nothing to the environmental space you are controlling.

Start with "ti = 1.72". "ti" is additive When you have an error it adds a portion of the error to the output. Too much "ti" the temperature in the space will oscillate. too little it will take forever to reach setpoint. adjust this till your temperature overshoots just a little but has the ability to land on setpoint after a few oscillations. integral can wind up and could be a portion of your problem. I'm not sure if PID_v1.h has resolved this but you can try my version if you like it is 100% compatible with PID_v1.h
Arduino_PID_Library_v3
if you choose to use this additional features are available and can simplify your code.

Set "td = 0" as we will only need it to help land the on the setpoint after the other two are calibrated

now add some kp until setpoint lands quickly td take change in error and can slow or speed up the change to help lock down setpoint quickly

Z

2 Likes

The default myPID.SetSampleTime() is 100 ms for each iteration of myPID.Compute(), but you have a delay(500); at the end of loop(). Why is this delay there?

2 Likes

It does not have any specific function, do I have to delete it?

Of course, delete it, but there's 7 more blocking delays that affect the loop() rate:

line 125:  delay(1500);
line 175:  delay(2000);
line 193:  delay(100);
line 208:  delay(100);
line 212:  delay(100);
line 239:  delay(200);
line 248:  delay(500);

the delays of those lines are useful for the program
Is that the reason for the problem?

While the "delay" is running, your MCU cannot do anything else. That is bad.

What specifically do you mean here? What happens? What serial output do you see?

pid output is zero

What could I do ?

Refactor your program to use a finite state machine and the millis() function for timing purposes. You can find plenty of tutorials on that with the forum search of Google.

(Note: I am not sure if that is the cause of your problem, I haven't looked at your code in depth.)

No, they are not, especially for PID control.

For timed actions, get rid of all the delay statements and use millis() instead, as described in this tutorial.

1 Like

Which controllino model?
What are you controlling?
Could you post a schematic?

With the delays, It's surprising you have any usable control left. I guess your system must have a slow time constant, in which case some PID control is possible.

The delays may not be causing the 10 minute reset problem, but the delays are no help for smooth and precise PID control. There's many other possibilities like electrical, code, switching, EMI, watchdog timer?, lack of MOV's/Snubbers/Flyyback diodes, etc. There's also some warning on the controllino Mini sheet about the INT terminal, so answers to above would be helpful.

1 Like

I am using the controllino mini,
Through the pid control I control a niquelina through a circuit that will take care of the AC control.
And the response is slow, there is a temperature change approximately each 10 seconds.

I have also noticed that the output goes to zero when there is no temperature change.
Even so, do not reach the set point if it takes too long at an unchanged temperature.
the output is reset stays there until the program is restarted

The schematic fails to show most of the components used by the program, and how most of the circuit is powered.

What is the point of posting such an incomplete diagram?

No useful comments in the posted code, either.

In setup, the PID is set to AUTOMATIC, which automatically initializes the PID, but in the lectura() function, it's conditionally set to AUTOMATIC once more ... possibly after 10 minutes?

void lectura() {
  delay(1500);
  Temperatura = dht.readTemperature();
  humedad = dht.readHumidity();
  mq135 = analogRead(A2);
  CO2 = map(mq135, 0, 1023, 400, 10000);
  if (Temperatura < 0  || Temperatura > 100 || humedad < 0 || humedad > 100) {
    myPID.SetMode(AUTOMATIC);
    inicio();
  }
}

Is this intended as a temperature or humidity overlimit shutdown for the PID output?
(I think this is the output reset issue)

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.