Using PID Library to control temperature with SSR

Hi,
I have used QuickPID libraries example for PID control for SSR and i want to configure it. I want to set a temperature and i want to heat the element until it reaches to desired temperature. But i want to make sure that it won't turn on for 1-2 sec then turn off for a while or turn off 1-2 sec then turn on for a while.

This is the code i wrote to check if the NTC sensor has reached the set temperature.

if(pot_val_desired<t2){
    if (!relayStatus && Output > (msNow - windowStartTime)) {
      if (msNow > nextSwitchTime) {
        nextSwitchTime = msNow + debounce;
        relayStatus = true;
        digitalWrite(ssrPin, HIGH);
      }
    } else if (relayStatus && Output < (msNow - windowStartTime)) {
      if (msNow > nextSwitchTime) {
        nextSwitchTime = msNow + debounce;
        relayStatus = false;
        digitalWrite(ssrPin, LOW);
      }
    }
  }
  else{
    digitalWrite(ssrPin,LOW);    
  }  

what is SSR

do you really need PID?

sounds like you just need some hysteresis, set an upper and lower threshold or turning off and turning on, maybe +/- 1 deg

Solid State Relay

Do you mean that you would like the PID "time-proportioning" output control action to be disabled while the system is warming up to set temperature? If so, this could create significant overshoot. In the example, the PID tuning parameters and "SetSampleTimeUs" determine how your system will respond. The "windowSize" determines the output control period where this is actually a slow software PWM frequency. In the example, this is set to 5000ms (5-sec).

Note that its normal for a tuned PID system to begin regulating the output prior to the input temperature reaching the setpoint.

Could you provide your full code and provide more details on your system and its requirements?

Most folks here use the Arduino PID Library. It's quite sophisticated and well-documented.

See:

Forgot to mention that QuickPID is actually an updated fork of the Arduino PID Library. However, if you only need coarse temperature control, you may not need to use PID at all and the suggestion as in @gcjr post#2 could work well.

If you need very precise temperature control, then I could help with an enhanced version of the output control function. Take a look here, where there's minimal overshoot and better than 0.25 degree regulation when using an SSR (zero-cross type).

Set your window to 999 milliseconds and set the min and max output for the PID to 1 and 998. That way the state will always switch once per second and will NEVER go 1-2 seconds ON or 1-2 seconds OFF.

Normally a two-point control with hysteresis is sufficient.

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