MAX6675: thermocouple temperatures up to 1024 C
A K-type thermocouple measures hundreds of degrees, far past any DS18B20, but its output is a few tens of microvolts per degree and needs cold-junction compensation. The MAX6675 does both jobs on one chip and hands back the temperature as a 12-bit number in quarter degrees, from 0 to 1024 C. The MAX6675 library reads it over three pins: clock, chip select and data out.
Built in on Mokxi: #include <max6675.h> and it builds, with nothing to install. Free, and no account needed.
What MAX6675 library does
The constructor takes the pins in the order SCLK, CS, MISO, the same order the library鈥檚 example calls thermoCLK, thermoCS and thermoDO. Any three digital pins work, because the library clocks the bits out in software rather than using the SPI hardware.
The chip needs about 220 ms to finish a conversion, and reading faster just returns the previous value. When the thermocouple is unplugged or broken, the chip sets an open-probe bit and readCelsius() returns NAN, so test for it.
| Library Manager name | MAX6675 library |
|---|---|
| Author | Adafruit |
| Include | #include <max6675.h> |
| Boards | every board Mokxi compiles for |
| In the simulator | Simulated: it runs against the part the way it does on the bench. |
| Parts it drives | Thermocouple converter, MAX6675 |
Install it
It builds on every board Mokxi compiles for.
In Mokxi it is built in: #include <max6675.h> and the sketch compiles, with no download, no zip and no Library Manager.
On a real board, install "MAX6675 library" by Adafruit from the Arduino IDE鈥檚 Library Manager (Sketch, Include Library, Manage Libraries), or add MAX6675 library to lib_deps in PlatformIO. Mokxi follows the calls of release 1.1.2, so a sketch written here builds there too.
ESP32-C3 路 Arduino Uno 路 Arduino Nano 路 Arduino Mega 2560 路 Arduino Leonardo 路 SparkFun Pro Micro 路 Arduino Micro 路 ESP32-C6 路 ATtiny85 路 Raspberry Pi Pico 路 Raspberry Pi Pico W 路 Seeed XIAO SAMD21 路 STM32 路 STM32 Nucleo-F411RE 路 STM32 Blue Pill 路 micro:bit V2 路 Arduino Uno R4 路 ESP32 DevKit 路 ESP32-S3-DevKitC-1 路 ESP8266 NodeMCU 路 Arduino Pro Mini 3.3 V 路 Seeed XIAO ESP32-C3 路 ESP32-C3 SuperMini 路 Seeed XIAO ESP32-C6 路 ESP32-DevKitC V4 路 LOLIN32 Lite 路 Wemos D1 R32 路 Cheap Yellow Display 路 TTGO T-Display 路 Seeed XIAO ESP32-S3 路 Arduino Nano ESP32 路 Arduino Nano RP2040 Connect 路 Seeed XIAO RP2040 路 Waveshare RP2040-Zero 路 Arduino Uno R4 WiFi
The calls you will use
In the order a sketch meets them.
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO)
Creates the sensor on three digital pins: clock, chip select, data out.
thermocouple.readCelsius()
The probe temperature in degrees Celsius, in 0.25 degree steps, or NAN when the probe is open.
float c = thermocouple.readCelsius();
if (isnan(c)) Serial.println("Thermocouple not connected");
else Serial.println(c);
delay(250);thermocouple.readFahrenheit()
The same in Fahrenheit. Old sketches spell it readFarenheit(), which still works.
delay(250)
Not a library call, but every MAX6675 loop needs it or a millis() timer: the chip converts about four times a second.
Example: Thermocouple
On the Arduino Uno R3. It runs in the browser exactly as printed.
// Thermocouple: a K-type thermocouple on a MAX6675 board, read twice a
// second with Adafruit's max6675 library.
//
// MAX6675 SCK -> 6, CS -> 5, SO -> 4, VCC -> 5 V, GND -> GND
//
// A thermocouple is two different metals joined at the tip. The junction
// makes a few microvolts per degree, far too little for the Uno's ADC, so
// the MAX6675 measures it, corrects for the temperature of its own terminals
// and sends the result as a 16-bit word: pull CS low and clock out sixteen
// bits. The temperature is bits 14 to 3, a quarter degree a count.
//
// The chip converts while CS is high and a conversion takes up to 0.22 s.
// Reading faster than that returns the same number again, which is why
// every MAX6675 sketch waits between reads.
//
// Things to try. Drag the slider on the board and watch the reading follow.
// Then open the board's properties and untick probe: the open thermocouple
// reads as NAN, and the sketch says so.
#include <max6675.h>
const int SCK_PIN = 6;
const int CS_PIN = 5;
const int SO_PIN = 4;
MAX6675 thermocouple(SCK_PIN, CS_PIN, SO_PIN);
void setup() {
Serial.begin(9600);
Serial.println("MAX6675 ready");
// Give the chip time to finish its first conversion.
delay(500);
}
// Hundredths printed as a whole number and two decimals, which keeps the
// float printing code out of the sketch.
void printHundredths(long h) {
if (h < 0) {
Serial.print('-');
h = -h;
}
Serial.print(h / 100);
Serial.print('.');
if (h % 100 < 10) Serial.print('0');
Serial.print(h % 100);
}
void loop() {
float celsius = thermocouple.readCelsius();
if (isnan(celsius)) {
Serial.println("No thermocouple");
} else {
Serial.print("C = ");
printHundredths((long)(celsius * 100));
Serial.print(" F = ");
printHundredths((long)(celsius * 180) + 3200);
Serial.println();
}
delay(500);
}Open it in the editor, wired and ready to run 路 Thermocouple: the project page
Common errors and how to fix them
readCelsius() returns NAN
The open-probe bit is set: the thermocouple is not making contact. Tighten the screw terminals, and check the probe is not broken. If the probe is fine, check the CS pin is the one in the constructor.
The temperature falls when the probe is heated
The thermocouple leads are on the wrong terminals. On a K-type, the yellow (or red, by older color codes) lead goes to plus; swap the two wires.
The reading never changes
You are reading faster than the chip converts, or CLK and DO are swapped. Wait at least 250 ms between reads and check the pin order SCLK, CS, MISO in the constructor.
Try MAX6675 library without installing anything
Open the example, change the sketch, and keep your version in a free account.