In this guide, you’ll learn how to read temperature using a K-Type Thermocouple with the MAX6675 amplifier with the ESP32 board. A K-type thermocouple is a type of temperature sensor with a wide measurement range like â200 to 1260ÂșC (â326 to 2300ÂșF).
This tutorial covers how to interface the k-type thermocouple with your ESP32 board, install the required library and use a simple sketch to display the sensor readings in the Serial Monitor.
Table of Contents
In this tutorial, we’ll cover the following topics:
- Introducing K-Type Thermocouple
- MAX 6675 Amplifier
- Interfacing K-Type Thermocouple with MAX 6675 Amplifier
- Installing MAX 6675 Arduino Library
- Code – Get Temperature from K-Type Thermocouple with MAX 6675 Amplifier
What is a K-Type Thermocouple?
A thermocouple is a device that consists of two different electrical conductors that form an electrical junctionâthermal junction. The change in temperature at the junction creates a slightly but measurable voltage at the reference junction that can be used to calculate the temperature.
A thermocouple can be made of different metals. The metals used will affect the voltage range, cost, and sensitivity. There are standardized metal combinations that result in different thermocouple types: B, E, J, N, K, R, T, and S.
Our tutorial is about the k-type thermocouple. A k-type thermocouple is made out of chrome and alumel conductors and has a general temperature range of â200 to 1260ÂșC (â328 to 2300ÂșF).
MAX6675 Amplifier
To get the temperature from the thermocouple we need a thermocouple amplifier. The temperature output from the thermocouple amplifier depends on the voltage read on the reference junction. The voltage at the reference junction depends on the temperature difference between the reference junction and the thermal junction. So, we need to know the temperature at the reference junction.
The MAX6675 thermocouple comes with a temperature sensor to measure temperature at the reference junction (cold-compensation reference) and amplifies the tiny voltage at the reference junction so that we can read it using our microcontrollers. The MAX6675 amplifier communicates with a microcontroller using SPI communication protocol and the data is output in a 12-bit resolution.
Usually, you can get a pack with a k-type thermocouple and the MAX6675 amplifier. Here’s a list of the MAX6675 most relevant features. For a more detailed description, please consult the MAX6675 datasheet.
- Direct digital conversion of type -K thermocouple output
- Cold-junction compensaiton
- Simple SPI-compatible serial interface
- Operating voltage range: 3.0 to 5.5V
- Operating temperature range: â20 to 85ÂșC
- Resolves temperatures to 0.25ÂșC, allows readings as high as 1024ÂșC (1875ÂșF).
Interfacing K-Type Thermocouple with MAX6675 Amplifier
As mentioned previously, the MAX 6675 communicates with a microcontroller using SPI communication protocol.
MAX6675 | Microcontroller |
SO | MISO |
CS | CS |
SCK | CLK |
VCC | VCC (3.3V or 5V) |
GND | GND |
Get Temperature from K-Type Thermocouple with MAX6675 Amplifier
In this section, you’ll learn how to get temperature from your k-type thermocouple. We’ll show you a simple example that reads the temperature and displays it on the Arduino IDE Serial Monitor.
Parts Required
To complete this tutorial, you need the following parts:
- K-type thermocouple with MAX6675 amplifier
- ESP32 (read Best ESP32 development boards)
- Jumper wires (female-to-female)
You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!
Schematic – ESP32 with K-type thermocouple and MAX6675 Amplifier
Wire the MAX6675 Amplifier to the ESP32 as shown in the following schematic diagram.
You can also follow the next table.
MAX6675 | ESP32 |
GND | GND |
VCC | 3.3V |
SCK | GPIO 5 |
CS | GPIO 23 |
SO | GPIO 19 |
Installing MAX6675 Arduino Library
There are different libraries to get temperature from a K-type thermocouple using the MAX6675 amplifier. We’ll use the max6675 library from Adafruit.
Follow the next steps to install the library in your Arduino IDE:
Open your Arduino IDE and go to Sketch > Include Library > Manage Libraries. The Library Manager should open.
Search for âmax6675 â in the search box and install the library from Adafruit.
Code – Get Temperature from K-Type Thermocouple with MAX 6675 Amplifier
Getting temperature from the K-Type thermocouple with the ESP32 is very simple. The library provides an example that gets temperature and displays the results on the Arduino IDE Serial monitor.
The code was adapted from the example provided by the library to make it compatible with the ESP32.
// this example is public domain. enjoy! https://learn.adafruit.com/thermocouple/
#include "max6675.h"
int thermoDO = 19;
int thermoCS = 23;
int thermoCLK = 5;
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
void setup() {
Serial.begin(9600);
Serial.println("MAX6675 test");
// wait for MAX chip to stabilize
delay(500);
}
void loop() {
// basic readout test, just print the current temp
Serial.print("C = ");
Serial.println(thermocouple.readCelsius());
Serial.print("F = ");
Serial.println(thermocouple.readFahrenheit());
// For the MAX6675 to update, you must delay AT LEAST 250ms between reads!
delay(1000);
}
How the Code Works
First, include the max6675.h library.
#include "max6675.h"
Define the pins that are interfacing with the MAX6675 thermocouple amplifier.
int thermoDO = 19;
int thermoCS = 23;
int thermoCLK = 5;
Create a MAX6675 object called thermocouple on the pins we’ve defined previously.
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
In the setup(), initialize the Serial Monitor at a baud rate of 9600.
Serial.begin(9600);
In the loop(), we read the temperature and display it on the Serial Monitor. The library provides a method to read the temperature in Celsius and a method to read the temperature in Fahrenheit degrees.
- thermocouple.readCelsius(): returns temperature in Celsius degrees.
- thermocouple.readFahrenheit(): returns temperature in Fahrenheit degrees.
The following lines read the temperature and display it on the Serial Monitor.
Serial.print("C = ");
Serial.println(thermocouple.readCelsius());
Serial.print("F = ");
Serial.println(thermocouple.readFahrenheit());
As you can see, it’s very simple to get temperature readings using the K-type thermocouple with the MAX6675 amplifier.
Demonstration
Upload the code to your ESP32 board. Don’t forget the select the board you’re using in Tools > Board and select the COM port your board is connected to in Tools > Port.
After uploading the code to the ESP32, open the Serial Monitor at a baud rate of 9600. Press the ESP32 on-board RST button.
New temperature readings are displayed on the Serial Monitor every second.
Wrapping Up
In this tutorial, you learned how to read temperature using the k-type thermocouple with the MAX6675 amplifier. Thermocouples have a wide temperature measurement range and allow you to read very high temperaturesâas high as 1024ÂșC (1875ÂșF) when using k-type thermocouple with MAX6675.
We have tutorials for other popular sensors with the ESP32 board that you may like:
- ESP32 with DS18B20: Temperature Sensor
- ESP32 with BME680: Gas, Pressure, Humidity, and Temperature Sensor
- ESP32 with BME280: Temperature, Humidity, and Pressure Sensor
- ESP32 DHT11/DHT22: Temperature, and Humidity Sensor
- ESP32 with BMP388: Altimeter Sensor
- ESP32 HC-SR04: Ultrasonic Distance Sensor
- ESP32 PIR: Motion Sensor
- ESP32 BMP180: Pressure Sensor
- ESP32 with BH1750 Ambient Light Sensor
Learn more about the ESP32 with our resources:
MAX6675s are desperately inaccurate. Use a MAX31855K and you’ll get way better results. The interface is the same (SPI) and the code to drive them is nearly identical.
Push four bytes to the device, receive four back with
(float) ((rd_buf[0] << 8) + rd_buf[1]) / 16,
(float) ((rd_buf[2] << 8) + rd_buf[3]) / 256);
Hi.
Thanks for the suggestion.
We used the MAX6675 because it came as a package with the type-k thermocouple.
We’ll take a look at the one you suggested.
Regards,
Sara
Nice article(s), as usual.
I love thermocouples, especially K-type. I’ve used them is projects from woodstove thermometer, cookstove thermometer (pyrometer), waterheater controller, to just plain temperature sensor.
Did you know that ESP32 has support for K-type thermocouples without and external amplifier? Have a look at this: https://github.com/krzychb/esp32-lna
(Apparently, only some revisions have this feature and it’s not being carried forward into new designs. Some TTGO boards [e.g. T-Display] have support for this.)
And, certain AVR chips have this ability too: http://www.technoblogy.com/show?2G9S
Also, as you may know, MAX6675, although still available, is obsolete. It’s replacement, MAX31855 is very similar, more competent, but just a little harder to use (3v3 only, for one thing). I wrote an Arduino library that’s agnostic about which chip it’s reading and just gives the right answer. https://github.com/polypagan/MAXthermo
Hi Daniel.
Thanks for sharing that info. I didn’t know about that feature of the ESP32.
Yes, we need to order a MAX31855. Everybody is mentioning that đ
Regards,
Sara
Hi thanks for a great tutorial.
I’ve got this set up working well but I’m really struggling with adding mqtt to the code to allow more remote monitoring .
Can anyone point me in the right direction as to how to go about it .
Regards
Paul
Hi.
I answered your question here: https://rntlab.com/question/k-type-thermo-couple-with-mqtt/
Regards,
Sara
Hello – Have you played around with the ESP32-C3? This code did not work (I am sure I have something wrong with the pins I tried to use).
I bought a couple inexpensive ESP32-C3 boards that have a small OLED, a Neopixel and a Qwiic connector. But the SPI pins seem hard to figure out. This is the board — https://github.com/01Space/ESP32-C3-0.42LCD/
Thanks.
Hi.
What pins are you using?
I think you can use any pins as long as you define them on the following line:
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
What is exactly the error that you get?
Regards,
Sara
I tried to assign CS to pin 5, used the pin labeled SCK (pin 10) for CLK and then used the one labeled MOSI (pin 7) for the DO (assuming it is out from the 6675 and in on the ESP). No errors – it compiled and uploaded, but nothing at all on the serial monitor. Maybe a bad 6675 (cheap ebay one). I bought a Qwiic thermocouple interface on SparkFun (MCP9600 based) and plan to try that on the board’s Qwiic interface – they have an example using another sensor on the Git. Thanks for your fast response.
Can you help me please? I have to do it with 3 max6675 and one of them connected with a relay. I can run it with 1 max6675 but what should i do with other two
Hi.
You’ll need to create multiple instances for the sensors. For example:
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
MAX6675 thermocouple_2(thermoCLK_2, thermoCS_2, thermoDO_2), in which the arguments are other pins for that sensor.
etc…
Then, you just need to refer to each sensor by thermocouple, thermocouple_2 and so on.
Regards,
Sara
Thank you RUI and SARA.
As I read about 6675 and 31855 sensors, I find some info that says I need Pull-up resistors on the data lines. Is this so?
I am using two Max31855 with an S2 dev board, working in PlatformIO. I created a proto board containing the two max 31855’s an OLED and three buttons to operate a Reflow oven.
Hi.
I’m not sure. I’m our case, we didn’t need to do that. Probably because the resistord already come with our module.
If you’re creating one from scratch you probably need those, but I’m not really familiar with that subject.
Regards,
Sara