Lesson 47: Using K-Type MAX6675 as thermostat with relay | Arduino Step By Step Course
This project guides you through building a temperature control system using an Arduino, a MAX6675 K-type thermocouple, and a relay. This system can maintain a desired temperature range, making it suitable for various applications. You can use this to build:
- A temperature-controlled incubator for delicate experiments or seedlings.
- An automated brewing system for maintaining consistent wort temperatures.
- A climate-controlled enclosure for reptiles or other temperature-sensitive animals.
- A simple heating or cooling system for a small space.
The system uses the MAX6675 to read temperatures from a K-type thermocouple, providing accurate temperature readings over a wide range (depending on the thermocouple type, up to 1000°C or more). The Arduino processes these readings and controls a relay to switch a heating or cooling element on or off, maintaining the temperature within a user-defined range. (in video at 00:32)
Hardware/Components
To build this project, you will need the following components:
- Arduino board (Uno, Nano, etc.)
- MAX6675 thermocouple amplifier
- K-type thermocouple
- Relay module
- AC bulb (or other load, such as a fan or heater)
- Jumper wires
- Breadboard (optional, but recommended)
Wiring Guide
The wiring is explained in detail in the video. (in video at 03:28) Refer to the video for a visual guide. The key connections include connecting the MAX6675 to the Arduino (pins 2-6), the relay module to the Arduino (pin 8 and power), and the relay module to the AC load. A critical aspect is correctly identifying the live and neutral wires of your AC load before connecting them to the relay. Incorrect wiring can lead to dangerous situations.

Code Explanation
The Arduino code (shown in snippets below) utilizes the MAX6675 library to read temperature values from the thermocouple. The user-configurable parts of the code are:
relayPin: The Arduino pin connected to the relay module (default: 8). (in video at 07:35)relayONandrelayOFF: These constants define the logic levels to turn the relay on and off, respectively. These are usually LOW and HIGH, but might need to be adjusted depending on your relay module. (in video at 07:35)TEMPERATURE_UNIT: Sets the unit for temperature readings (1 for Celsius, 2 for Fahrenheit, 3 for Kelvin). (in video at 08:21)START_TEMPERATUREandSTOP_TEMPERATURE: These variables define the temperature range for the control system. The system will turn on the relay when the temperature falls belowSTART_TEMPERATUREand turn it off when the temperature reachesSTOP_TEMPERATURE(or vice-versa, depending on whether you're controlling a heater or cooler). (in video at 08:31)CONTROL_TYPE: A variable that determines whether the system acts as a heater (1) or cooler (2). (in video at 08:36)
The code includes functions like readTemperature(), printTemperature(), loadControl(), and relayControl() to handle temperature reading, display, and relay operation. These functions are clearly defined and explained in the video. (in video at 09:37, 10:00, 10:43, 11:30)
const int relayPin =8;
const int relayON = LOW;// do not change
const int relayOFF = HIGH; //do not change
int relayState = relayOFF;//initial state of relay
const int TEMPERATURE_UNIT =1;//1=Celsius, 2=Fahrenheit, 3=Kelvin
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
Live Project/Demonstration
The video demonstrates the functioning of the temperature control system for both heating and cooling scenarios. (in video at 13:15 and 15:28) The demonstration clearly shows how the system maintains the temperature within the set range by turning the relay on and off as needed.
Chapters
- [00:00] Introduction
- [00:55] Heater/Cooler Control Explanation
- [03:28] Wiring Diagram
- [06:26] Code Explanation
- [13:15] Heater Control Demonstration
- [15:28] Cooler Control Demonstration
- [17:29] Conclusion
/*
* Dies ist der Arduino-Code für den MAX6675 Thermoelement K-Typ mit Relais und Anzeige. Der Ausgangspin 10 ist mit dem Relais verbunden. Wenn die Temperatur den gewünschten Wert erreicht, schaltet Pin 10 das Relais EIN.
*
* Dieser Code wurde in unserem Video unter https://youtu.be/cD5oOu4N_AE erklärt.
*
* Geschrieben von Ahmad Nejrabi für Robojax Video
* Datum: 9. Dezember 2017 in Ajax, Ontario, Kanada
* Erlaubnis zur Weitergabe dieses Codes, sofern diese
* Notiz mit dem Code beibehalten wird.
* Haftungsausschluss: Dieser Code ist "WIE BESEHEN" und nur zu Bildungszwecken gedacht.
*
* /
*
* // Dieses Beispiel ist gemeinfrei. Viel Spaß!
* // www.ladyada.net/learn/sensors/thermocouple
*/
#include "max6675.h"
int thermoDO = 4;
int thermoCS = 5;
int thermoCLK = 6;
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
int vccPin = 3;
int gndPin = 2;
void setup() {
Serial.begin(9600);
// Verwende Arduino-Pins
pinMode(vccPin, OUTPUT); digitalWrite(vccPin, HIGH);
pinMode(gndPin, OUTPUT); digitalWrite(gndPin, LOW);
pinMode(10, OUTPUT); // Setze Pin 10 als Ausgang.
Serial.println("Robojax: MAX6675 test");
// Warte, bis der MAX-Chip stabil ist.
delay(500);
}
void loop() {
// Basisdurchlauf-Test, einfach die aktuelle Temperatur ausdrucken.
Serial.print("C = ");
Serial.println(thermocouple.readCelsius());
Serial.print("F = ");
Serial.println(thermocouple.readFahrenheit());
// Wenn die Temperatur über 80,0 °C steigt, schalte das Relais EIN.
if(thermocouple.readCelsius() > 80.00){
digitalWrite(10, LOW); // setze Pin 10 auf LOW
}else{
digitalWrite(10, HIGH); // setze Pin 10 auf HIGH
}
delay(1000);
}
++
/*
* Bibliothek von: // www.ladyada.net/learn/sensors/thermocouple
*
* Dies ist Arduino-Code zur Messung des MAX6675 Thermoelements K-Typ und zur Steuerung eines Relais als Heizgerät oder Kühler.
*
* Siehe Videoanleitung zu diesem Code: https://youtu.be/dVh77wT-4Ao
*
* Geschrieben von Ahmad Shamshiri am 20. Mai 2020 in Ajax, Ontario, Kanada www.robojax.com
*
* Holen Sie sich diesen Code und andere Arduino-Codes von Robojax.com. Lernen Sie Arduino Schritt für Schritt in einem strukturierten Kurs mit sämtlichem Material, Verdrahtungsdiagrammen und Bibliotheken, alles an einem Ort. Kaufen Sie meinen Kurs auf Udemy.com http://robojax.com/L/?id=62
*
* Wenn Sie dieses Tutorial hilfreich fanden, unterstützen Sie mich bitte, damit ich weiterhin Inhalte wie diesen erstellen kann. Sie können mich auf Patreon unterstützen http://robojax.com/L/?id=63
*
* oder eine Spende über PayPal tätigen http://robojax.com/L/?id=64
* Verwandte Videos:
* Einführung in MAX6675 K-Typ: https://youtu.be/VGqONmUinqA
* Verwendung des MAX6675 K-Typ-Thermoelements mit LED-Anzeige: https://youtu.be/cD5oOu4N_AE
* Verwendung des MAX6675 K-Typ-Thermoelements mit LCD1602-I2C: https://youtu.be/BlhpktgPdKs
* Verwendung von 2 oder mehr MAX6675 K-Typ-Thermoelementen: https://youtu.be/c90NszbNG8c
* Verwendung des MAX6675 K-Typ-Thermoelements als Steuergerät für Heizung oder Kühlung: [dieses Video]
* * Dieser Code ist "WIE BESEHEN" ohne Gewährleistung oder Haftung. Kostenlos zu verwenden, solange Sie diese Notiz unversehrt lassen. *
* Dieser Code wurde von Robojax.com heruntergeladen.
* Dieses Programm ist freie Software: Sie können es weiterverbreiten und/oder ändern
* unter den Bedingungen der GNU General Public License, wie sie von
* der Free Software Foundation veröffentlicht wurde, entweder in der Version 3 der Lizenz oder
* (nach Ihrer Wahl) in jeder späteren Version.
*
* Dieses Programm wird in der Hoffnung verteilt, dass es nützlich sein wird,
* aber OHNE JEDE GEWÄHRLEISTUNG; ohne sogar die stillschweigende Gewährleistung für
* VERMARKTBARKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK. Siehe die
* GNU General Public License für weitere Einzelheiten.
*
* Sie sollten eine Kopie der GNU General Public License
* zusammen mit diesem Programm erhalten haben. Wenn nicht, siehe <https://www.gnu.org/licenses/>.
*/
#include "max6675.h"
// Robojax.com Heiz-/Kühler mit MAX6675 Thermoelement
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; // nicht ändern
const int relayOFF = HIGH; // nicht ändern
int relayState = relayOFF; // Anfangszustand des Relais
const int TEMPERATURE_UNIT =1; // 1=Grad Celsius, 2=Grad Fahrenheit, 3=Kelvin
const float START_TEMPERATURE = 80.0; // Einheit darüber
const float STOP_TEMPERATURE = 100.0; // Einheit darüber
const int CONTROL_TYPE = 1; // 1= Heizung, 2= Kühler
float temperature;
void setup() {
// Robojax.com Heiz-/Kühler mit MAX6675 Thermoelement
Serial.begin(9600);
Serial.println("MAX6675 test with relay");
// verwende Arduino-Pins
pinMode(relayPin, OUTPUT); // Pin für Relais
digitalWrite(relayPin, relayState);
pinMode(VCCpin, OUTPUT);
digitalWrite(VCCpin, HIGH);
pinMode(GNDpin, OUTPUT);
digitalWrite(GNDpin, LOW);
// Warten Sie, bis der MAX-Chip stabil ist.
delay(500);
// Robojax.com Heiz-/Kühler mit MAX6675 Thermoelement
}
void loop() {
// Robojax.com Heiz-/Kühler mit MAX6675 Thermoelement
readTemperature();
printTemperature();
loadControl();
if(temperature >=89.5)
{
// /
}
delay(1000);
// Robojax.com Heiz-/Kühler mit MAX6675 Thermoelement
} // Schleife
/*
* loadControl()
* @brief steuert die Last basierend auf
* @param state kann entweder : relayON oder relayOFF sein
* @return gibt nichts zurück
* Geschrieben von Ahmad Shamshiri für robojax.com
* am 20. Mai 2020 um 15:23 in Ajax, Ontario, Kanada
*/
void loadControl()
{
// Robojax.com Heiz-/Kühler mit MAX6675 Thermoelement
// Serial.print("Start: ");
// Serial.print(START_TEMPERATUR);
// Serial.print(" Stopp: ");
// Serial.println(STOP_TEMPERATUR);
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 Heiz-/Kühler mit MAX6675 Thermoelement
} // loadControl()
/*
* relayControl(int Zustand))
* @brief schaltet das Relais EIN oder AUS
* @param Zustand ist "relayON" oder "relayOFF", definiert am Anfang des Codes
* @return gibt nichts zurück
* Geschrieben von Ahmad Shamshiri für robojax.com
* am 20. Mai 2020 um 15:23 in Ajax, Ontario, Kanada
*/
void relayControl(int state)
{
// Robojax.com Heiz-/Kühler mit MAX6675 Thermoelement
if(state ==relayON)
{
digitalWrite(relayPin, relayON);
Serial.println("Relay ON");
}else{
digitalWrite(relayPin, relayOFF);
Serial.println("Relay OFF");
}
// Robojax.com Heiz-/Kühler mit MAX6675 Thermoelement
} // relaySteuerung()
/*
* readTemperature()
* @brief liest die Temperatur basierend auf der TEMPERATUR_EINHEIT
* @param durchschnittliche Temperatur
* @return gibt einen der oben genannten Werte zurück
* Geschrieben von Ahmad Shamshiri für robojax.com
* am 20. Mai 2020 um 15:23 in Ajax, Ontario, Kanada
*/
void readTemperature()
{
// Robojax.com Heiz-/Kühler mit MAX6675 Thermoelement
if(TEMPERATURE_UNIT ==2)
{
temperature = thermocouple.readFahrenheit(); // in Fahrenheit umrechnen
}else if(TEMPERATURE_UNIT ==3)
{
temperature = thermocouple.readCelsius() + 273.15; // in Kelvin umrechnen
}else{
temperature = thermocouple.readCelsius(); // return Celsius
}
// Robojax.com Heiz-/Kühler mit MAX6675 Thermoelement
} // readTemperature()
/*
* printTemperatur()
* @brief druckt die Temperatur auf dem seriellen Monitor aus
* @param charact Typ
* @param "Typ" ist Zeichen
* C = Celsius
* K = Kelvin
* F = Fahrenheit
* @return keine
* Geschrieben von Ahmad Shamshiri für robojax.com
* am 08. Mai 2020 um 02:45 in Ajax, Ontario, Kanada
*/
void printTemperature()
{
// Robojax.com Heiz-/Kühler mit MAX6675 Thermoelement
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 Heiz-/Kühler mit MAX6675 Thermoelement
} // printTemperatur()
/*
* @brief druckt das Grad-Symbol im seriellen Monitor
* @param keine
* @return gibt nichts zurück
* Geschrieben von Ahmad Shamshiri am 13. Juli 2019
* für Robojax Tutorial Robojax.com
*/
void printDegree()
{
Serial.print("\\xC2");
Serial.print("\\xB0");
}
Dinge, die Sie vielleicht brauchen
-
eBay
-
AliExpressKaufe 1 Kanal 5V KY-019 Relais von AliExpress.s.click.aliexpress.com
-
BanggoodMAX6675 K-Typ bei Banggood kaufenbanggood.com
Ressourcen & Referenzen
-
ExternMAX6675 Datenblatt (PDF)datasheets.maximintegrated.com
Dateien📁
Keine Dateien verfügbar.