Back to Arduino Step By Step Course

Lesson 47: Using MAX6675 K-Type Thermocouple with Relay as Thermostat

If you don't like to see ads while video is being played you can purchase this course for $200 from Udemy or purchase YouTube premium Here

Please download required files for this code

Part 4: Temperature Sensors

In this lesson we learn how to use MAX6675 with relay as thermostat to keep temperature stead for industrial application. For echmical, melting or other applications. We can set range of temperature and Arduino will keep it at that level by controlling heater or cooler. Please watch the video for full details.


 /*
 * Robojax Arduino Step By Step Course
 * Part 4: Temperature Sensors
 * Lesson 47: Using Max6675 as Thermostat with relay
 * 
 * This is Arduino code to measure MAX6675 Thermocoupler K-Type sensor
 * and control realy as Heater or cooler

   Please watch video instruction here https://youtu.be/yJYXfaU9J34
   Introduction to MAX6675 video is https://youtu.be/A55QNx6kCoo
 This code is available at http://robojax.com/course1/?vid=lecture47

 
Course worth of $200 with over 150 lectures Free On  YouTube Watch it here http://robojax.com/L/?id=338
Get the code for the course: http://robojax.com/L/?id=339  

 * Written by Ahmad Shamshiri on May 20, 2020 at in Ajax, Ontario, Canada
 * in Ajax, Ontario, Canada. www.robojax.com
 * 
 * Library from : // www.ladyada.net/learn/sensors/thermocouple
 * 

or make donation using PayPal http://robojax.com/L/?id=64

 *  * This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.* 
 * This code has been download from Robojax.com
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.


*/


#include "max6675.h"
//Robojax.com heater/cooler with MAX6675 Thermocoupler
int GNDpin = 2;
int VCCpin =3;
int thermoCLK = 4;
int thermoCS = 5;
int thermoDO = 6;
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);


const int relayPin =8;
const int relayON = LOW;// do not change
const int relayOFF = HIGH; //do not chage 
int relayState = relayOFF;//initial state of relay

const int TEMPERATURE_UNIT =1;//1=Celsius, 2=Fahrenheit, 3=Keliven
const float START_TEMPERATURE = 80.0;//unit above
const float STOP_TEMPERATURE = 100.0;//unit above
const int CONTROL_TYPE = 1;// 1= heater, 2=cooler
float temperature;

void setup() {
  //Robojax.com heater/cooler with MAX6675 Thermocoupler
  //free course YouTube Watch it here http://robojax.com/L/?id=338
  Serial.begin(9600);
  Serial.println("MAX6675 test with relay");
  // use Arduino pins 
  pinMode(relayPin, OUTPUT);//pin for relay
  digitalWrite(relayPin, relayState);
  
  pinMode(VCCpin, OUTPUT);
  digitalWrite(VCCpin, HIGH);

  pinMode(GNDpin, OUTPUT);
  digitalWrite(GNDpin, LOW);

  // wait for MAX chip to stabilize
  delay(500);
//Robojax.com heater/cooler with MAX6675 Thermocoupler  
}

void loop() {
  //free course YouTube Watch it here http://robojax.com/L/?id=338  
  //Robojax.com heater/cooler with MAX6675 Thermocoupler
   readTemperature();
   printTemperature();
   loadControl(); 
   if(temperature >=89.5)
   {
    ///
   }
   delay(1000);
//Robojax.com heater/cooler with MAX6675 Thermocoupler   
}//loop



/*
 * loadControl()
 * @brief controls the load based 
 * @param state can be either : relayON or relayOFF

 * @return returns none
 * Written by Ahmad Shamshiri for robojax.com
 * on May 20, 2020 at 15:23 in Ajax, Ontario, Canada
 */
void loadControl()
{
    //free course YouTube Watch it here http://robojax.com/L/?id=338
//Robojax.com heater/cooler with MAX6675 Thermocoupler  
     // Serial.print("Start: ");
     // Serial.print(START_TEMPERATURE);
     // Serial.print(" Stop: ");
      //Serial.println(STOP_TEMPERATURE);      
  if(CONTROL_TYPE ==1)
  {
    if(START_TEMPERATURE >= temperature && STOP_TEMPERATURE >=temperature)
    {
      relayControl(relayON);
    }
    if(STOP_TEMPERATURE <=temperature)
    {
      relayControl(relayOFF);
    }
  }else{
    if(START_TEMPERATURE >= temperature && STOP_TEMPERATURE >=temperature)
    {
      relayControl(relayOFF);
    }
    if(STOP_TEMPERATURE <=temperature)
    {
      relayControl(relayON);
    }
  }
    
//Robojax.com heater/cooler with MAX6675 Thermocoupler
}//loadControl()


/*
 * relayControl(int state))
 * @brief turns the relay ON or OFF
 * @param state is "relayON" or "relayOFF" defined at the top of code
 * @return returns none
 * Written by Ahmad Shamshiri for robojax.com
 * on May 20, 2020 at 15:23 in Ajax, Ontario, Canada
 */
void relayControl(int state)
{
    //free course YouTube Watch it here http://robojax.com/L/?id=338
  //Robojax.com heater/cooler with MAX6675 Thermocoupler
  if(state ==relayON)
  {
    digitalWrite(relayPin, relayON);
    Serial.println("Relay ON");   
  }else{
   digitalWrite(relayPin, relayOFF);    
    Serial.println("Relay OFF");   
  }
  //Robojax.com heater/cooler with MAX6675 Thermocoupler  
  //free course YouTube Watch it here http://robojax.com/L/?id=338
}//relayControl()


/*
 *  readTemperature()
 * @brief reads the temperature based on the TEMPERATURE_UNIT
 * @param average temperature

 * @return returns one of the values above
 * Written by Ahmad Shamshiri for robojax.com
 * on May 20, 2020 at 15:23 in Ajax, Ontario, Canada
 */
void readTemperature()
{
    //free course YouTube Watch it here http://robojax.com/L/?id=338
 //Robojax.com heater/cooler with MAX6675 Thermocoupler 

  if(TEMPERATURE_UNIT ==2)
   {
   temperature = thermocouple.readFahrenheit();//convert to Fahrenheit 
   }else if(TEMPERATURE_UNIT ==3)
   {
    temperature = thermocouple.readCelsius() + 273.15;//convert to Kelvin
   }else{
    temperature = thermocouple.readCelsius();// return Celsius
   }    
 //Robojax.com heater/cooler with MAX6675 Thermocoupler 
}// readTemperature()

/*
 * printTemperature()
 * @brief prints  temperature on serial monitor
 * @param charact type
 * @param "type" is character
 *     C = Celsius
 *     K = Keliven
 *     F = Fahrenheit
 * @return none
 * Written by Ahmad Shamshiri for robojax.com
 * on May 08, 2020 at 02:45 in Ajax, Ontario, Canada
 */
void printTemperature()
{
    //free course YouTube Watch it here http://robojax.com/L/?id=338
//Robojax.com heater/cooler with MAX6675 Thermocoupler
   Serial.print(temperature);
    printDegree();    
  if(TEMPERATURE_UNIT ==2)
   {
     Serial.print("F");
    }else if(TEMPERATURE_UNIT ==3)
   {
     Serial.print("K");
   }else{
     Serial.print("C");
   }    
  Serial.println();
//Robojax.com heater/cooler with MAX6675 Thermocoupler  
}//printTemperature()

/*
 * @brief prints degree symbol on serial monitor
 * @param none
 * @return returns nothing
 * Written by Ahmad Shamshiri on July 13, 2019
 * for Robojax Tutorial Robojax.com
 */
void printDegree()
{
    //free course YouTube Watch it here http://robojax.com/L/?id=338
    Serial.print("\xC2"); 
    Serial.print("\xB0");  
}

   

The least I expect from you is to thumb up the video and subscribe to my channel. I appriciate that. .I have spent months making these lectures and writing code. You don't lose anything by subscribging to my channel. Your subscription is stamp of approval to my videos and more people can find them and in it turn it helps me. Thank you

If you found this tutorial helpful, please support me so I can continue creating content like this. support me via PayPal

**** AFFILIATE PROGRAM **** We are a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for us to earn fees by linking to Amazon.com and affiliated sites.