Arduino library · Sensors

Adafruit MAX31865: precise temperature from a PT100 or PT1000

Yes. You can use the Adafruit MAX31865 library online in Mokxi with nothing to install, and the sketch runs in your browser against the simulated part (RTD converter, MAX31865). The example below, "A PT100 on a MAX31865, its ratio, resistance and temperature", runs on the Arduino Uno R3.

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

What Adafruit MAX31865 does

An RTD is a platinum wire whose resistance rises with temperature: a PT100 is 100 ohms at 0 °C and about 138.5 ohms at 100 °C. It is slower and narrower in range than a thermocouple but far more accurate and stable, which is why lab baths, coffee roasters and brewing rigs use one. The MAX31865 drives a small current through the RTD, compares it with a reference resistor on the board, and returns the ratio as a 15-bit number over SPI.

The library turns that ratio into a temperature. readRTD() gives the raw ratio, where 32768 would equal the reference resistor; temperature() takes the RTD’s nominal resistance and the reference (100 and 430 on the PT100 board in the example; PT1000 boards usually fit a 4300 ohm reference) and solves the Callendar-Van Dusen equation for °C. readFault() reports an open or shorted probe, and the voltage checks that the chip makes on its inputs.

Two, three and four-wire probes are wired with the solder jumpers on the board and named in begin(). The example uses software SPI with CS on pin 5, DI on pin 4, DO on pin 3 and CLK on pin 2, and a probe at 100 °C, so you can see the raw count, the resistance worked out from it and the temperature. Mokxi stores the wire count but the reading is the same for each.

Library Manager nameAdafruit MAX31865
AuthorAdafruit
Include#include <Adafruit_MAX31865.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 drivesRTD converter, MAX31865

Install it

It builds on every board Mokxi compiles for but ATtiny85.

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

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

What to know in the simulator: The wire count is written but does not change the reading.

The calls you will use

In the order a sketch meets them.

Adafruit_MAX31865 thermo = Adafruit_MAX31865(10, 11, 12, 13)

Software SPI on CS, DI, DO and CLK. Adafruit_MAX31865(10) alone uses the hardware SPI bus with CS on pin 10.

thermo.begin(MAX31865_3WIRE)

Starts the chip for a 2, 3 or 4-wire probe: MAX31865_2WIRE, MAX31865_3WIRE or MAX31865_4WIRE. Match the board’s jumpers.

thermo.readRTD()

The raw 15-bit ratio of the RTD to the reference resistor. Resistance is RREF × value / 32768.

thermo.temperature(RNOMINAL, RREF)

Temperature in °C from a fresh reading: 100.0 and 430.0 for a PT100 board, 1000.0 and 4300.0 for a PT1000.

Serial.println(thermo.temperature(100.0, 430.0), 1);

thermo.readFault()

The fault byte, 0 when all is well. Test it against MAX31865_FAULT_HIGHTHRESH, MAX31865_FAULT_RTDINLOW and the rest.

thermo.clearFault()

Clears the fault bits so the next reading starts clean. Call it after reporting a fault.

thermo.enable50Hz(true)

Tunes the chip’s filter to reject 50 Hz mains hum instead of the default 60 Hz.

Example: A PT100 on a MAX31865, its ratio, resistance and temperature

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

sketch.ino · Arduino Uno R3
#include <Adafruit_MAX31865.h>

// CS, DI, DO, CLK
Adafruit_MAX31865 thermo = Adafruit_MAX31865(5, 4, 3, 2);

#define RREF      430.0
#define RNOMINAL  100.0

void setup() {
  Serial.begin(115200);
  Serial.println("Adafruit MAX31865 PT100 Sensor Test!");
  thermo.begin(MAX31865_3WIRE);
}

void loop() {
  uint16_t rtd = thermo.readRTD();
  Serial.print("RTD value: ");
  Serial.println(rtd);
  float ratio = rtd;
  ratio /= 32768;
  Serial.print("Resistance = ");
  Serial.println(RREF * ratio, 2);
  Serial.print("Temperature = ");
  Serial.println(thermo.temperature(RNOMINAL, RREF), 1);
  uint8_t fault = thermo.readFault();
  if (fault) {
    Serial.print("Fault 0x");
    Serial.println(fault, HEX);
    thermo.clearFault();
  }
  delay(500);
}

Wiring

  • Arduino Uno R3 2 to RTD converter, MAX31865 CLK
  • Arduino Uno R3 3 to RTD converter, MAX31865 SDO
  • Arduino Uno R3 4 to RTD converter, MAX31865 SDI
  • Arduino Uno R3 5 to RTD converter, MAX31865 CS
  • Arduino Uno R3 5V to RTD converter, MAX31865 VIN
  • Arduino Uno R3 GND to RTD converter, MAX31865 GND

Open it in the editor, wired and ready to run

Common errors and how to fix them

Temperature reads about -242 °C and readFault() is set

The ratio is 0, meaning an open probe or no SPI answer. Check the probe in the terminal block, then the four SPI wires and the order of the pins in the constructor: CS, DI, DO, CLK.

The temperature is off by a few degrees with a 3-wire probe

The board’s jumpers are still set for 2 or 4 wires, so lead resistance is counted. Cut and solder the jumpers for 3 wires and pass MAX31865_3WIRE to begin().

A PT1000 reads around -200 °C or wildly high

The sketch uses the PT100 constants. A PT1000 board has a 4300 ohm reference, so call temperature(1000.0, 4300.0) and set RREF to 4300 for the resistance sum.

Questions and answers

RTD or thermocouple: which should I pick?

An RTD for accuracy to a fraction of a degree below about 400 °C. A thermocouple with a MAX31855 for kilns, forges and anything hotter.

Projects that use Adafruit MAX31865

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

Try Adafruit MAX31865 without installing anything

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