PID Control for Heating a Mold with Cartridge Heaters and a SSR

Hello,

I am working on a project using cartridge heaters to heat an aluminium mold to 90 C where it will stay for two minutes and then turn off. To do this I plan on wiring the heaters to an SSR which can be activated by an Arduino UNO. To control the temperature increase I am using the Arduino PID Library where my input will be given by a thermocouple. I am familiar with how PID controllers work but this is my first time using one in actual application.

My first question is regarding tuning parameters, How do I initially find these values? I have seen in many projects people using the Autotune Library but everything I’ve read about this says you should reach your set point before you use this to get good results, but what tuning parameters do you use to initially reach that set point. Is it worth using autotune if you will always have the same set point?

Secondly, because everything I read about projects like this tells me I need a heatsink for my relay does anyone have suggestions for choosing a heatsink. The SSR is rated for 40A 230Vac, so I imagine I want a big one, the electronic shop I use has a huge selection and classifies their heatsinks by Rth (K/W) so what Rth should my heatsink have.

Finally, I have attached my code and schematic of the system if anyone sees any red flags in the coding or in the design of the circuit please let me know, I really don’t want to get electrocuted or burn the building down…

Thanks,
Chris

/* Heat Cartdridge Control:
 *  The Purpose of this program is to have cartridge heaters heat a mold to 90d Celsius
 *  hold there for 2 minutes and then turn off. To do this I will use the Max6675 K type
 *  thermocouple and its acompanying library along with the PID library
 *  
 *  Still in progress: Finding PID tuning parameters and autotune library
 */


// inlude libraries
#include <max6675.h>
#include <PID_v1.h>
//#include <PID_AutoTune_v0.h>

#define RelayPin 6

//Define PID Variables we'll be connecting to
double Setpoint;
double Input;
double Output;
double Kp;
double Ki;
double Kd;

//Specify the links and initial tuning parameters
PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);

// 10 second Time Proportional Output window
int maxDutyCycle = 1000;
int count = 0;  

// ThermoCouple
int thermo_gnd_pin = 45;
int thermo_vcc_pin = 47;
int thermo_so_pin  = 49;
int thermo_cs_pin  = 51;
int thermo_sck_pin = 53;
  
MAX6675 thermocouple(thermo_sck_pin, thermo_cs_pin, thermo_so_pin);
  
void setup() {
  Serial.begin(9600);
 
 
  //initialize the variables we're linked to
  Setpoint = 90;
 
  //tell our PID to give us an output as a duty cycle out of 1 second
  
  myPID.SetOutputLimits(0, maxDutyCycle);

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

  //Assign pins for thermocouple
  pinMode(thermo_vcc_pin, OUTPUT); 
  pinMode(thermo_gnd_pin, OUTPUT); 
  digitalWrite(thermo_vcc_pin, HIGH);
  digitalWrite(thermo_gnd_pin, LOW);
}

void loop() {
  
  digitalWrite(RelayPin,LOW); // Make sure relay is off to start
 
  while (count < 120) {
  
    Serial.print("Temp: ");
    Serial.println(thermocouple.readCelsius());
    Input = thermocouple.readCelsius();
    myPID.Compute();

    int now = millis();


    while (Output < now) digitalWrite(RelayPin,HIGH); // Turn relay on for the portion of a second given by PID Controller
   
   digitalWrite(RelayPin,LOW);

 if (thermocouple.readCelsius() > 85) count++;
 
 delay(1000-Output);
  }
 Serial.print("Heating Complete");
  

}

new doc 2017-09-12 13.37.58.pdf (273 KB)

Heat_Cartridge_Control.ino (1.97 KB)

Hi,
Welcome to the forum.

OPs diagram.


Tom... :slight_smile:

Hi,
What is your external supply for your cartridge heaters?
What are the specifications of the heaters?

Your SSR has to be in series with the heaters and your power supply.

Thanks.. Tom... :slight_smile:

Hi,
Your heater side of the SSR should be wired like this.

Tom... :slight_smile:

TomGeorge:
Hi,
Your heater side of the SSR should be wired like this.

Tom... :slight_smile:

Thanks Tom, The cartridge heaters are rated for 230V and provide 1500W - http://www.heizpatronen.info/eng/shop_product.php?r=36040

Usually, PID is used where you can vary something, to achieve a desired result, such as varying the duty cycle of a PWM pin, to get a heater to draw just enough current to maintain the desired temperature.

Using PID when all you can do is bang the heater(s) on or off is less usual.

I'm struggling to understand exactly what you will use the output value for.

PaulS:
Usually, PID is used where you can vary something, to achieve a desired result, such as varying the duty cycle of a PWM pin, to get a heater to draw just enough current to maintain the desired temperature.

Using PID when all you can do is bang the heater(s) on or off is less usual.

I'm struggling to understand exactly what you will use the output value for.

I restricted the output value between 0 and 1000, this way the value can be the amount of milliseconds the heaters will be on for in each second. basically making a small PWM.

The reason I use PID is to avoid overshooting the temp...

Depending on how many hours your project will operate, you may be able to use the enclosure for your controller as the SSR heat sink. It is metal, isn't it?

Paul

PID is useful for controlling a system where you want to be able to vary the set point and/or have external influences changing conditions. The PID doesn't 'know' anything about the system it's controlling. In your case it may be simpler to heat until you reach 80 degrees and then find out by experimentation what degree of fake pwm will get you to 90 with minimal overshoot and similarly what is needed to hold you there for two minutes.

wildbill:
PID is useful for controlling a system where you want to be able to vary the set point and/or have external influences changing conditions. The PID doesn't 'know' anything about the system it's controlling. In your case it may be simpler to heat until you reach 80 degrees and then find out by experimentation what degree of fake pwm will get you to 90 with minimal overshoot and similarly what is needed to hold you there for two minutes.

This is exactly what I did last winter for my drying oven. Initial heating took 15 minutes. Overshoot, of course. If initial heating, stop heating a few minuets to allow for residual heat. Then waited for cool down below set point and turned SSR back on. Experimented for a couple of days to get timing to allow a temp of +- 4 degrees or less.

Wrote one function for initial heating and one for subsequent controlled heating.

Paul

PID tuning: Everything you need to know was published in 1942. Google Ziegler-Nichols. Their method worked then, still works today. IMO, autotune is just a crutch - a crutch that still needs to be refined for best performance.

To calculate a minimum size heat sink for your SSR, you'll need the thermal resistance of the device. If it's an eBay special without a datasheet, use the Crydom guide below for those numbers (from a similar rating) and go as large as is practical.

http://www.crydom.com/en/products/panel-mount/perfect-fit/

Using digital outputs to power the MAX6675 is unnecessary. This is not battery powered device, wire it to +5 and gnd and be done with it.

Every pass through the "loop()" subroutine, the millis() function updates the "now" variable which results in the heater output turning on an never turning off. You'll need a separate start time value that is an "unsigned long", not an "int" to do millis() function based calculations.

The use of the delay() function suspends the calls to the PID function and will result in output instability. Everything stops until the delay time expires. Have a look at the example program named "blink without delay" to see one approach for dealing with time based functions.

Finally, a curiosity question. After heating the mold at 90C for two minutes, is it just left to cool in ambient air? Water cooling? How much time passes until the next heat cycle?