Arduino library · Sensors

Adafruit MAX31855: a K-type thermocouple from -200 to 1350 °C

Yes. You can use the Adafruit MAX31855 library online in Mokxi with nothing to install, and the sketch runs in your browser against the simulated part (Thermocouple converter, MAX31855). The example below, "A K-type thermocouple on a MAX31855, on any three pins", runs on the Arduino Uno R3.

Built in on Mokxi: #include <Adafruit_MAX31855.h> and it builds, with nothing to install. Free, and no account needed.

What Adafruit MAX31855 does

A thermocouple makes a few microvolts per degree, far too little for an analog pin, so a converter chip does the work. The MAX31855 is Maxim’s newer one for K-type probes: it reads from -200 to 1350 °C in quarter-degree steps, compensates for the temperature of its own terminals, and sends the result as a 32-bit word over a read-only SPI link. Adafruit_MAX31855 reads that word and hands you degrees.

Next to the MAX6675 the difference is range and diagnosis. The MAX6675 stops at 0 °C at the bottom and 1024 °C at the top and reports only an open probe. The MAX31855 also reads below freezing, gives you the chip’s own temperature with readInternal(), and tells three faults apart: probe open, shorted to ground, or shorted to VCC. On any fault readCelsius() returns NAN, which is why the example checks isnan().

The library works on hardware SPI or any three pins in software, and the example uses software SPI with CLK on pin 2, CS on pin 3 and DO on pin 4. The thermocouple part in Mokxi has a temperature and an ambient you can set, so you can watch both readings and try a fault without a hot plate.

Library Manager nameAdafruit MAX31855
AuthorAdafruit
Include#include <Adafruit_MAX31855.h>
Boardsevery board Mokxi compiles for but ATtiny85
In the simulatorSimulated: it runs against the part the way it does on the bench.
Parts it drivesThermocouple converter, MAX31855

Install it

It builds on every board Mokxi compiles for but ATtiny85.

In Mokxi it is built in: #include <Adafruit_MAX31855.h> and the sketch compiles, with no download, no zip and no Library Manager.

On a real board, install "Adafruit MAX31855" by Adafruit from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add Adafruit MAX31855 to lib_deps in PlatformIO. Mokxi follows the calls of release 1.4.2, so a sketch written here builds there too.

The calls you will use

In the order a sketch meets them.

Adafruit_MAX31855 thermocouple(MAXCLK, MAXCS, MAXDO)

The chip on three pins of your choosing, in software SPI. Passing only the CS pin uses the hardware SPI bus.

thermocouple.begin()

Sets the pins up and returns true. Call it once, after a short delay so the chip has finished its first conversion.

thermocouple.readCelsius()

The probe’s temperature in °C as a double, or NAN when a fault is set.

double c = thermocouple.readCelsius();
if (isnan(c)) Serial.println("fault");
else Serial.println(c);

thermocouple.readInternal()

The chip’s own temperature, which is the cold junction it compensates for. Handy as a room thermometer.

thermocouple.readFahrenheit()

The probe temperature in °F, also NAN on a fault.

thermocouple.readError()

The fault bits: MAX31855_FAULT_OPEN, MAX31855_FAULT_SHORT_GND and MAX31855_FAULT_SHORT_VCC, or 0 when all is well.

thermocouple.setFaultChecks(MAX31855_FAULT_OPEN)

Chooses which faults make readCelsius() return NAN. Leave out the short checks if your probe is grounded on purpose.

Example: A K-type thermocouple on a MAX31855, on any three pins

On the Arduino Uno R3. It runs in the browser exactly as printed.

sketch.ino · Arduino Uno R3
#include <SPI.h>
#include "Adafruit_MAX31855.h"

#define MAXDO   4
#define MAXCS   3
#define MAXCLK  2

Adafruit_MAX31855 thermocouple(MAXCLK, MAXCS, MAXDO);

void setup() {
  Serial.begin(9600);
  Serial.println("MAX31855 test");
  delay(500);
  if (!thermocouple.begin()) {
    Serial.println("ERROR.");
    while (1) delay(10);
  }
}

void loop() {
  Serial.print("Internal Temp = ");
  Serial.println(thermocouple.readInternal());
  double c = thermocouple.readCelsius();
  if (isnan(c)) {
    Serial.println("Thermocouple fault(s) detected!");
  } else {
    Serial.print("C = ");
    Serial.println(c);
  }
  delay(500);
}

Wiring

  • Arduino Uno R3 2 to Thermocouple converter, MAX31855 CLK
  • Arduino Uno R3 3 to Thermocouple converter, MAX31855 CS
  • Arduino Uno R3 4 to Thermocouple converter, MAX31855 DO
  • Arduino Uno R3 5V to Thermocouple converter, MAX31855 VCC
  • Arduino Uno R3 GND to Thermocouple converter, MAX31855 GND

Open it in the editor, wired and ready to run

Common errors and how to fix them

Thermocouple fault(s) detected! on every reading

The probe is not connected, or is shorted to the case. Check both wires in the screw terminal, then call readError(): 1 is open, 2 a short to ground and 4 a short to VCC.

The temperature falls when the probe is heated

The thermocouple wires are swapped. On a K-type the red lead is usually negative; swap the two wires at the terminal block.

Readings jump by tens of degrees near a motor or relay

The tiny thermocouple voltage picks up noise. Keep the probe leads away from power wires, add a 10 nF capacitor across the inputs, and average a few readings.

Questions and answers

Can I use the MAX31855 with a J-type or T-type probe?

Only with the chip made for that type. The MAX31855K is for K-type; other letters (J, N, T, E, R, S) are separate chips that the same library reads.

Projects that use Adafruit MAX31855

Built-in projects that include it. Each page has the full sketch and opens in the editor, already wired.

Try Adafruit MAX31855 without installing anything

Open the example, change the sketch, and keep your version in a free account.