Temperature Controller of Heating Element

Hello,

I am new to Arduino and circuitry and am looking to implement feedback control system for a simple two wire heating element. I am using a MAX31855 thermocouple temperature sensor for the temperature feedback using a thermocouple. I had no problem with this.

My issue is in implementing the control system to regulate the current that the heating element sees. I assume that the signal output analogWrite from the PID code will need to be used in a transistor to regulate the current flow to the heating element from the power supply. The circuit I setup is as follows:

  1. Positive wire from 13.8 V (25 A) power supply to NPN transistor collector
  2. Output from Arduino pin 6 to transistor base
  3. Transistor emitter to heating element wire 1
  4. Heating element wire 2 to ground (of power supply, not Arduino)

The questions I have are:
Is this the correct circuit setup for PID control through arduino to regulate flow through heating coil (or headed in the right direction)?
Do I need to connect the ground of the circuit from the temperature sensor to the ground of the power supply/control circuit?
Should I be using something other than a transistor to regulate the power supply?

Here is the code for my system:

#include <PID_v1.h>
#include "Adafruit_MAX31855.h"

//Define Sensor
int thermoDO = 3;
int thermoCS = 4;
int thermoCLK = 5;

Adafruit_MAX31855 thermocouple(thermoCLK, thermoCS, thermoDO);

//PID Control
//Define Variables we'll be connecting to
double Setpoint, Input, Output;

//Define the aggressive and conservative Tuning Parameters
double aggKp=4, aggKi=0.2, aggKd=1;
double consKp=1, consKi=0.05, consKd=0.25;

//Specify the links and initial tuning parameters
PID myPID(&Input, &Output, &Setpoint, consKp, consKi, consKd, DIRECT);

void setup()
{
  Serial.begin(9600);
  
  Serial.println("MAX31855 Thermocouple Temperature Sensor");
  //wait for MAX chip to stabilize
  delay(500);
  
  //initialize the variables we're linked to
  Setpoint = 200; //In degrees Celsius

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

void loop()
{
  
  //print current temp
  Serial.print("Internal Temp = ");
  Serial.println(thermocouple.readInternal());
  
  double c = thermocouple.readCelsius();
  if (isnan(c)) {
    Serial.println("Something wrong with the thermocouple!");
  }
  
  else {
    Serial.print("C = ");
    Serial.println(c);
  }
  
  Input = c;
  
  double gap = abs(Setpoint-Input); //distance away from setpoint
  if(gap<10)
  {  //we're close to setpoint, use conservative tuning parameters
    myPID.SetTunings(consKp, consKi, consKd);
  }
  else
  {
     //we're far from setpoint, use aggressive tuning parameters
     myPID.SetTunings(aggKp, aggKi, aggKd);
  }
  
  myPID.Compute();
  analogWrite(6,Output);
  
  delay(1000); 
}

I have the input for the PID control in degrees Celsius because I want my setpoint to be in degrees Celsius as well, but I am unsure if this will create problems with the analogWrite output signal the arduino is sending (I think it should be between 0-255).

Any help will be greatly appreciated!

Thanks
Nick

Is this the correct circuit setup for PID control through arduino to regulate flow through heating coil (or headed in the right direction)?

No if you are going to use a transistor you need a resistor in the base.
How much current does the heater take? It is likely that you need a FET rather than a transistor because the transistor will get too hot.
Anyway the heater goes in the collector with the emitter directly to ground.

Do I need to connect the ground of the circuit from the temperature sensor to the ground of the power supply/control circuit?

Only if you want the thing to actually work.

I think it should be between 0-255)

Yes it should.

rader945:
Hello,

I am new to Arduino and circuitry and am looking to implement feedback control system for a simple two wire heating element. I am using a MAX31855 thermocouple temperature sensor for the temperature feedback using a thermocouple. I had no problem with this.

My issue is in implementing the control system to regulate the current that the heating element sees. I assume that the signal output analogWrite from the PID code will need to be used in a transistor to regulate the current flow to the heating element from the power supply. The circuit I setup is as follows:

  1. Positive wire from 13.8 V (25 A) power supply to NPN transistor collector
  2. Output from Arduino pin 6 to transistor base
  3. Transistor emitter to heating element wire 1
  4. Heating element wire 2 to ground (of power supply, not Arduino)

The questions I have are:
Is this the correct circuit setup for PID control through arduino to regulate flow through heating coil (or headed in the right direction)?
Do I need to connect the ground of the circuit from the temperature sensor to the ground of the power supply/control circuit?
Should I be using something other than a transistor to regulate the power supply?

Here is the code for my system:

#include <PID_v1.h>

#include "Adafruit_MAX31855.h"

//Define Sensor
int thermoDO = 3;
int thermoCS = 4;
int thermoCLK = 5;

Adafruit_MAX31855 thermocouple(thermoCLK, thermoCS, thermoDO);

//PID Control
//Define Variables we'll be connecting to
double Setpoint, Input, Output;

//Define the aggressive and conservative Tuning Parameters
double aggKp=4, aggKi=0.2, aggKd=1;
double consKp=1, consKi=0.05, consKd=0.25;

//Specify the links and initial tuning parameters
PID myPID(&Input, &Output, &Setpoint, consKp, consKi, consKd, DIRECT);

void setup()
{
 Serial.begin(9600);
 
 Serial.println("MAX31855 Thermocouple Temperature Sensor");
 //wait for MAX chip to stabilize
 delay(500);
 
 //initialize the variables we're linked to
 Setpoint = 200; //In degrees Celsius

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

void loop()
{
 
 //print current temp
 Serial.print("Internal Temp = ");
 Serial.println(thermocouple.readInternal());
 
 double c = thermocouple.readCelsius();
 if (isnan(c)) {
   Serial.println("Something wrong with the thermocouple!");
 }
 
 else {
   Serial.print("C = ");
   Serial.println(c);
 }
 
 Input = c;
 
 double gap = abs(Setpoint-Input); //distance away from setpoint
 if(gap<10)
 {  //we're close to setpoint, use conservative tuning parameters
   myPID.SetTunings(consKp, consKi, consKd);
 }
 else
 {
    //we're far from setpoint, use aggressive tuning parameters
    myPID.SetTunings(aggKp, aggKi, aggKd);
 }
 
 myPID.Compute();
 analogWrite(6,Output);
 
 delay(1000);
}




I have the input for the PID control in degrees Celsius because I want my setpoint to be in degrees Celsius as well, but I am unsure if this will create problems with the analogWrite output signal the arduino is sending (I think it should be between 0-255).

Any help will be greatly appreciated!

Thanks
Nick

OK - how much current to the heating element and what voltages ?

What precision of control do you want ? i.e. what are you trying to build here ?

Look up on the Internet Sous-vide arduino to get an idea of what you can do.

I would suggest if we are talking mains voltages here that you look at a SSR of suitable Amperage and Voltage that incorporates Zero Cross circuits in it.

This will more than handle what you need to do.

Then you would wire

  1. PWM output from Arduino to SSR control line
  2. Current (hot) into SSR
  3. Switched current out to element from SSR
  4. Other side of element to Ground.

Craig

I would suggest if we are talking mains voltages here that you look at a SSR

But he describes the circuit as the heater being connected to a 13.8V 25A supply so we are not talking about mains.

Either way, Mike the SSR would provide isolation and minimize if not eliminate the 13.8V from ever getting onto an Arduino pin and is pretty easy to connect for a newbie.

Grumpy_Mike:

I would suggest if we are talking mains voltages here that you look at a SSR

But he describes the circuit as the heater being connected to a 13.8V 25A supply so we are not talking about mains.

Sorry Mike - you are right - i skim read the start of the post.

I still think (dependant on what he is trying to achieve) that the SSR is a valid way to approach it - it will be slightly more expensive for a DC-DC SSR but not absurdly so. It is nice and simple for a NOOB rather than trying to get a MOSFET up and running - mind you there is a good cheap option from Freetronics which is a NPN MOSFET packaged on a board (obviously for low side rather than high side switching)

Craig