In this tutorial you will learn how to use RTD sensors with the MAX31865 and Arduino. RTD sensors are highly accurate, robust temperature sensors and the MAX31865 is a resistance-to-digital
converter that makes it easy to connect RTD sensors with a microcontroller such as an Arduino.
In the following sections you will learn about different types of RTD sensors, how they work and how to connect them to a MAX31865 board. We will also look at the function of the MAX31865, and how read temperature data using the Adafruit_MAX31865 library.
Let’s get started with the required parts.
Required Parts
I used an Arduino Uno for this project but any other Arduino board, or an ESP8266/ESP32 board will also work. Note that I selected the common Pt100 Sensor and the corresponding MAX31865 board. If you prefer a Pt1000 you should buy a matching board, otherwise you will have to change the reference resistor on the MAX31865 board. You can find more details in the later sections.
MAX31865
RTD Pt100 Sensor
Arduino Uno
Dupont Wire Set
USB Cable for Arduino UNO
Makerguides.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to products on Amazon.com. As an Amazon Associate we earn from qualifying purchases.
RTD Sensor
RTD stands for “Resistance Temperature Detector”. An RTD sensor is essentially a temperature sensitive resistor that changes resistance when the temperature changes.
RTD sensors have high accuracy, stability, and repeatability. They provide a largely linear output over a wide temperature range and are normally housed in a protective cable, which makes them very robust. However, they are more expensive than thermocouples and thermistors, and they have slower response times.
The most common RTDs are wire wound, platinum RTDs. They consist of a platinum wire that is wound around a ceramic core. The length of this platinum wire is chosen to achieve a specified resistance at 0°C. This is called the R0 resistance. For the Pt100 Sensor the R0 resistance is 100 Ω and for the Pt1000 the resistance is 1000Ω, for instance. And Pt refers to the fact that the sensor is made from platinum.
Temperature response of RTDs
RTDs are very accurate but not completely linear in their temperature response. The following diagram shows the change in resistance of a Pt100 sensor depending on temperature compared to a completely linear response.
Callendar Van Dusen equation
You can see there is a deviation from the ideal line at higher temperatures. This deviation or curvature can be described by the so called “Callendar Van Dusen” equation:
For accurate temperature readings at higher temperatures you would have to implement this equation. Luckily the Adafruit_MAX31865 library has this compensation already built in, and we don’t have to worry about it.
Finally, there are many other RTD types, that use different materials with different resistance values, but in this tutorial we are focusing on the common Pt100 RTD. For more information on other types of RTDs have a look at this article: RTDs – the key to accurate industrial temperature measurements.
Wiring configurations of RTDs
RTDs come in 2-wire, 3-wire, or 4-wire configurations, with the 3-wire configuration being the most common one.
Two wires are used to connect to the internal temperature sensitive resistor element of the RTD. However, the wires themselves have resistance as well. To be able to measure their resistance and to compensate for it, one or two additional wires are connected in the 3- and 4-wire RTDs as shown above.
Two-wire RTDs are typically chosen for applications where accuracy is not critical and the wires are short. They are easy to use but are less accurate since there is no compensation for the resistance of the wires possible.
Three-wire RTDs are the most common configuration that compensates for the resistance added by the wires, allowing for better accuracy and longer wires. With this configuration, the controller makes two measurements. The first measures the total resistance of the sensor and the connecting wires. The second the resistance of the compensation loop. By subtracting the compensation loop resistance from the total resistance, a net resistance can be calculated.
Four-wire RTDs essentially add a second compensation loop for even better compensation of wire resistance and higher accuracy. This configuration is used for precision measurements in laboratories and other applications where top accuracy is needed.
In this tutorial we are specifically going to use the 3-wire Pt100 RTD and its specifications are listed in the next section.
Technical Specification of the Pt100 RTD
The Pt100 is a 3-wire RTD with a nominal resistance of 100Ω at 0°C. The resistive wire is made of Platinum and the housing of the probe and the cable wrapping are made of stainless steel. Sensor and cable are water tight. The sensor has a temperature range from -50 to 200℃ with an accuracy of ±0.15 °C.
Test your Pt100 RTD
You can test the correct function of your Pt100 RTD with a multimeter. First identify the two wires that have a very low resistance of around 2Ω. The exact value will depend on the length of the wires. Typically these two wires have the same color coding – blue in my case – but that is not always so.
Then measure the resistance between one of the blue wires and the red wire. At room temperature it should be around 110Ω. If you then place the sensor into an ice bath (0°C) the resistance should drop to 100Ω. For the Pt1000 that resistance at 0°C would be 1000Ω.
In the next section we are going to connect the Pt100 RTD to the MAX31865 Board.
MAX31865 Board
The MAX31865 is a precision analog front-end IC for platinum RTD temperature sensors. It works by measuring the resistance of the RTD sensor and converting it into a digital value using a built-in analog-to-digital converter (ADC). Below the block diagram of the internals of the MAX31865 IC.
You can see the inputs for the RTD on the left (RTDIN+, RTDIN-, FORCE), the 15-bit ADC in the center and the SPI interface (SCLK, SDO, SDO, CS) on the right. The RTD sensor itself will be connected to the RTDIN+, RTDIN- inputs, while the FORCE pins are used to measure the wire resistance. The following table describes the all the pins and their functions.
The MAX31865 can handle PT100 or PT1000 sensors in 2-wire, 3-wire, or 4-wire configurations. Due to the 15-bit ADC it is very accurate with a resolution of 0.03125°C and a fast conversion time of 21ms. Furthermore, it has a built-in fault reporting function for errors such as Open RTD Element, RTD Shorted,
Out-of-Range Voltage, or Short Across RTD Element. For more information have a look at the datasheet.
Breakout board for MAX31865
Typically you don’t use the MAX31865 IC directly but in the shape of a breakout board. There are different versions but I am going to focus on the one listed in the Required Parts. The picture below shows the top and bottom of the MAX31865 breakout board.
You can see the inputs for the SPI interface and the RTD sensor marked. The board runs on 5V or 3.3V and therefore works nicely with Arduino or ESP32 microcontrollers.
You have to watch out when buying a MAX31865 breakout board. It should match your RTD sensor. The MAX31865 breakout boards differ in the Rref resistor that is pre-soldered on the board. If you have a Pt100 RTD you want a board with a Rref = 430Ω (labelled as 4300). But for a Pt1000 the Rref should be 4300Ω (lablled as 4301):
Though, you can replace the Rref resistor if you need to, because otherwise the boards are identical.
Connecting the RTD Sensor to the MAX31865
When connecting the RTD Sensor to the MAX31865 it is easy to make mistakes and you will get fault message from MAX31865 if you do it wrong. Please read the following sections carefully!
We start with the description of the wiring and board setup for the 3-wire RTD, since this is the most common configuration.
3 Wire RTD
Before you connect the RTD wires to the board you have to prepare the board for the 3-wire configuration. Specifically, you need to do the following three steps:
- Solder together the two pads labelled “2/3 Wire“
- Solder together the two right-most pads of the section labelled “24 3“
- Cut the thin trace between the two left-most pads of the section labelled “24 3“
The picture below shows the relevant locations on the breakout board (marked yellow)
Cutting trace
Note that the trace to cut is very thin and difficult to see. You will need a small, sharp knife to cut it. Watch out not to cut any other trace accidentally. The following picture shows a close-up of the trace that needs to be cut.
For some boards this small trace is even covered by color and almost invisible. After cutting the trace verify with a multimeter that there is no connection between the left and right pad anymore. I even took a microscope picture (after soldering) to make sure that I got a nice cut between the pads.
Below is another close up of the board that shows how the three sections with pads should look like after soldering and cutting.
Connecting the 3 wires
Finally we need to connect the three wires of the Pt100 RTD. You will notice that the end contacts it comes with are actually do not fit in the terminals. You will need to use pliers and fold them to make them small enough to fit. The picture below shows the contacts before and after.
Now you can insert them into the terminals. The two wires with the same color (low resistance loop) go into the right terminal (the terminal close to the “2 Wire” pad). And the wire with the other color goes into the left terminal. See picture below.
Which port of the left terminal block you are using for the red wire doesn’t matter. The solder blob on the “2/3 Wire” pad shortcuts those two ports.
If you look at the datasheet for the MAX31865, you will see that we are making the following connections between the MAX31865 and the 3-wire RTD:
4 Wire RTD
For the 4-wire configuration you don’t have to do anything. Just leave the board as it is, without soldering any pads or cutting any traces.
With a four wire RTD the wires with same color typically go into the same terminal (left or right). The order of the wires within the terminal doesn’t matter.
To be sure, use a multimeter and confirm that the wires that go into the same terminal have low resistance (2Ω).
2 Wire RTD
For the 2-wire configuration you have to solder the “2/3 Wire” pad and the “2 Wire” pad but you must not cut the thin trace of the “24 3” pad section.
Connecting the 2-wire RTD is very simple. Each of the two cables has to to go into a different terminal block (left or right). The order of the cables does not matter.
Connecting the MAX31865 to Arduino
Once you have prepared the MAX31865 board and connected the RTD sensor we are ready to connect the MAX31865 to the Arduino. The wiring diagram below shows the connections. Note that the RDY output of the MAX31865 board is not used.
The following table also lists the connection you need to make between the Arduino and the MAX31865 board.
Arduino | MAX31865 |
---|---|
10 | CS |
11 | SDI |
12 | SDO |
13 | CLK |
– | RDY |
5V | VIN |
GND | GND |
Reading RTD temperature data from the MAX31865
After everything is connected we can write some code. If you haven’t already installed the Adafruit_MAX31865 library, now is the time to do it. Go to Tools > Manage Libraries ...
and open the LIBRARY MANAGER. Search for “Adafruit_MAX31865” and press install. Once done, it should look like this.
Code Example
With that out of the way, below is a minimal example of how to read temperature data from the MAX31865. Have a quick look at the code first and then we discuss the details.
#include "Adafruit_MAX31865.h" Adafruit_MAX31865 thermo = Adafruit_MAX31865(10, 11, 12, 13); #define RREF 430.0 #define RNOMINAL 100.0 void setup() { Serial.begin(9600); thermo.begin(MAX31865_3WIRE); // 2WIRE, 3WIRE, 4WIRE } void loop() { uint8_t fault = thermo.readFault(); if (fault) { Serial.print("Fault 0x"); Serial.println(fault, HEX); thermo.clearFault(); } else { float temp = thermo.temperature(RNOMINAL, RREF); Serial.print("Temp:"); Serial.println(temp); } delay(1000); }
The code starts by including the Adafruit_MAX31865
library and creating the thermometer object thermo
. When creating the object we have to provide the Arduino pins used to communicate with the MAX31865 via SPI. In our case these are CS=10, DI=11, DO=12, CLK=13
.
#include "Adafruit_MAX31865.h" Adafruit_MAX31865 thermo = Adafruit_MAX31865(10, 11, 12, 13);
Next we define the constants for the RTD sensor. In the case of the Pt100 RTD we have reference resistance of 430Ω and a nominal resistance a 0 degrees of 100Ω.
#define RREF 430.0 #define RNOMINAL 100.0
If you use a Pt1000 RTD or different RTD you would use RREF=4300.0
and RNOMINAL=1000.0
.
In the setup function, we initiate the serial communication and also the communication with the MAX31865. Note that we are specifying a 3-wire RTD (MAX31865_3WIR
E). Change this parameter if you have a 2-wire (MAX31865_2WIRE
) or a 4-wire (MAX31865_4WIRE
) RTD connected.
void setup() { Serial.begin(9600); thermo.begin(MAX31865_3WIRE); }
Finally, in the loop function we first check for faulty readings. If we receive a fault message, we print “Fault” to the Serial Monitor and clear the fault. Otherwise we read the temperature from the MAX31865 and print it.
void loop() { if (thermo.readFault()) { Serial.println("Fault!"); thermo.clearFault(); } else { float temp = thermo.temperature(RNOMINAL, RREF); Serial.print("Temp:"); Serial.println(temp); } delay(1000); }
And that’s it. Now you can measure temperature using an RTD sensor and the MAX31865!
Serial plotter and monitor output
On your Serial Monitor you should now see printed out every second the ambient temperature in grad Celsius.
And you can the follow the change in temperature by opening the Serial Plotter. Warm up the sensor a bit by holding it in your hand, or cool it down by blowing on it.
Debugging
As you have seen, connecting the RTD wires and preparing the MAX31865 board correctly can be a bit tricky and if anything is wrong, you will not be able get any useful temperature readings. Luckily the MAX31865 is able to detect and report certain faults, which can be helpful in debugging.
The Adafruit_MAX31865 library comes with an example program that prints out the fault codes returned from the MAX31865. Below is a slightly modified version of that example code for the 3-wire Pt100 RTD.
#include "Adafruit_MAX31865.h" Adafruit_MAX31865 thermo = Adafruit_MAX31865(10, 11, 12, 13); #define RREF 430.0 #define RNOMINAL 100.0 void setup() { Serial.begin(9600); thermo.begin(MAX31865_3WIRE); } void loop() { uint16_t rtd = thermo.readRTD(); float ratio = rtd / 32768.0; Serial.print("RTD value: "); Serial.println(rtd); Serial.print("Ratio = "); Serial.println(ratio, 8); Serial.print("Resistance = "); Serial.println(RREF * ratio, 8); Serial.print("Temperature = "); Serial.println(thermo.temperature(RNOMINAL, RREF)); uint8_t fault = thermo.readFault(); if (fault) { Serial.print("Fault 0x"); Serial.println(fault, HEX); if (fault & MAX31865_FAULT_HIGHTHRESH) { Serial.println("RTD High Threshold"); } if (fault & MAX31865_FAULT_LOWTHRESH) { Serial.println("RTD Low Threshold"); } if (fault & MAX31865_FAULT_REFINLOW) { Serial.println("REFIN- > 0.85 x Bias"); } if (fault & MAX31865_FAULT_REFINHIGH) { Serial.println("REFIN- < 0.85 x Bias - FORCE- open"); } if (fault & MAX31865_FAULT_RTDINLOW) { Serial.println("RTDIN- < 0.85 x Bias - FORCE- open"); } if (fault & MAX31865_FAULT_OVUV) { Serial.println("Under/Over voltage"); } thermo.clearFault(); } Serial.println(); delay(3000); }
If you run this code, and everything is correctly wired and configured you should see something like the following text on your Serial Monitor.
RTD value: 8300 Ratio = 0.25329589 Resistance = 108.91723632 Temperature = 22.89
Specifically, we see that the RTD returned a non-zero reading (8300) that could be converted into a reasonable resistance value (108.9Ω) for a Pt100 sensor. And we get a correct reading of the current temperature in grad Celsius (22.89).
RTD incorrectly connected
If I pull the red cable out of the terminal and therefore disrupt the connection of the Pt100 with the MAX31865, I get the following error message:
RTD value: 32767 Ratio = 0.99996948 Resistance = 429.98687744 Temperature = 988.79 Fault 0xA8 RTD High Threshold REFIN- > 0.85 x Bias RTDIN- < 0.85 x Bias - FORCE- open
MAX31865 board incorrectly configured
On the other hand, if you see an error message similar to this, with an RTD value of zero and an negative temperature, it usually indicates that the pads are not correctly soldered or that the trace was not cut.
RTD value: 0 Ratio = 0.00000000 Resistance = 0.00000000 Temperature = -242.02 Fault 0x68 RTD Low Threshold REFIN- > 0.85 x Bias RTDIN- < 0.85 x Bias - FORCE- open
RTD Thresholds exceeded
Finally, the Adafruit_MAX31865 library has a function setThresholds(lower,upper)
that allows you to set thresholds on the minimal and maximal RTD values. If those limits are exceeded the MAX31865 will report a fault like this (despite everything wired correctly).
RTD value: 8292 Ratio = 0.25305175 Resistance = 108.81225585 Temperature = 22.62 Fault 0x80 RTD High Threshold
For more detailed information on the fault conditions the MAX31865 can detect, have a look at the Datasheet of the MAX31865.
Conclusions
RTD Sensors are accurate and robust temperature sensors that come in different wire configuration 2-, 3, 4-wire). These different wire configurations require specific changes to the MAX31865 board, which makes a successful connection of RTD, MAX31865 and Arduino a bit tricky.
If your MAX31865 reports zero resistance, large negative temperatures or other faults, it is usually due to a misconfigured board or connection.
I hope this tutorial helps you to avoid the common pitfalls with RTDs and the MAX31865 board. If you have any questions feel free to leave them in the comment section.
If you are interested in other temperature sensors have a look at the following tutorial:
- DHT11/DHT22 Sensor with Arduino Tutorial (2 Examples)
- Interfacing Arduino To An NTC Sensor
- DS18B20 Temperature Sensor Arduino Tutorial (4 Examples)
- LM35 Temperature Sensor Arduino Tutorial (3 Examples)
- TMP36 Temperature Sensor Arduino Tutorial (2 Examples)
- AM2320 I2C Temperature and Humidity Sensor Arduino …
And now, have fun with your temperature measurements ; )
Links
Here some links I found useful when writing this tutorial.
- Understanding RTDs
- What Is RTD Sensor And How Does It Work?
- Getting Started with High Precision Temperature Sensing using a MAX31865 and PT1000
- RTDs – the key to accurate industrial temperature measurements
- Adafruit MAX31865 RTD PT100 or PT1000 Amplifier
- Adafruit_MAX31865 libary
- MAX31865 Datasheet
I am Puneeth. I love tinkering with open-source projects, Arduino, ESP32, Pi and more. I have worked with many different Arduino boards and currently I am exploring, Arduino powered LoRa, Power line communication and IoT.
Hossein mohammad saeedi
Monday 6th of May 2024
hello I reload your sample for pt100 with MAX31865 and Arduino but don't working (with 3 wire) please help me thanks
Tufan Paul
Wednesday 29th of May 2024
By the the way I am using pt 1000-s rtd sensor. it showing terminal resistance between rtd+ & rtd- is 1134ohm at room temperature. referential temperature of my MAX31865 module is 431 ohm. https://robu.in/product/pt1000-s-waterproof-1m-30mm-stainless-steel-pole-probe-temperature-sensor/ https://robu.in/product/max31865-rtd-platinum-resistance-temperature-detector-module-pt100-pt1000/
Tufan Paul
Wednesday 29th of May 2024
Thanks for sharing. but i already go through this content, as there is no reference image given I am confused. i connected 2 wire RTD sensor to RTD+ & RTD- terminal leave F+ & F - Terminal as it is. but on the opposite side I have soldered the junction (v shape) between 2 wire copper plate & 2/3 wire copper plate both & leave 2/4/3 wire copper plate as it is. can you please guide me with the connection?
Tufan Paul
Tuesday 28th of May 2024
I made the circuit to test the temperature reading from a 2 wire circuit & use MAX31865 module, Arduino Uno with the given code here. but after compiling & uploading it to arduino I am getting error as 0* 80 RTD at high threshold RTD out of range temperature -242.20 degree celsius all time & some unrecognized characters etc. can you help me with the same?
Tufan Paul
Monday 27th of May 2024
@Stefan Maetschke, i am using 2 wire rtd & getting RTD at high threshold. please let me know asap if any way is there to figure out the same.
Stefan Maetschke
Monday 6th of May 2024
Do you see any error messages or what is not working?