Fads to Obsessions and Beyond...




Free domain for life, exceptional technical support, website transfer

MAX31855 Thermocouple Driver

Demonstrate interfacing Arduino Nano with the MAX31855 Thermocouple Driver to read temperatures from K-type thermocouples. Code also demonstrates multiple connected MAX31855's to enable reading more than one thermocouple. Output to serial monitor/PC and LCD.

The MAX31855K Thermocouple Driver is a 14-bit resolution, SPI-compatible, serial interface thermocouple board that makes reading a wide range of temperatures, using a K-type thermocouple typically -200 °C to 1000 °C, relatively simple. A thermocouple works by taking two wires made of dissimilar metal alloy, connecting them at the two ends, and making a temperature gradient between one end and the other (a ‘hot’ end and a ‘cold’ one). Once this is achieved, a voltage potential is formed due to the Seebeck Effect and current flows. The MAX31855 amplifies, digitises and converts this signal and outputs the temperature as a binary data stream via a SPI interface. Details about the necessary circuit connections and coding in regards interfacing to an Arduino Nano are given below.

The Arduino Nano is used as this microcontroller is advantageous in terms of small physical size and low cost per GPIO/onboard peripheral available. Particularly good for 'small' DIY projects controlling a single sensor and or output for example, such as temperature monitoring for kilns, furnaces, ovens and other such 'high' temperature applications.

First some background about thermocouples (specifically related to use with the MAX31855) and then some specifics about the MAX31855.

Details on how to setup the Arduino IDE and environment to programme Arduino Nano microcontrollers are given in the Arduino Nano introduction.

Thermocouples

As mentioned, thermocouples operate due to two wires of different metal compositions connected at the two ends, with the two ends being placed in differing temperature environments, which generates a voltage potential and current flow (Seebeck Effect). This means that thermocouples are classified by type of metals used, with the most common being type K made from chromel and alumel. These two alloys produce a potential of approximately 41.276 µV/°C. The MAX31855 uses this known potential difference to calculate the temperature. Therefore, it is important that the MAX31855 variant used is the "K" version, to match the type of thermocouple used, otherwise the reported temperature will be incorrect.

Further, thermocouples can be either 'grounded' or 'ungrounded' in construction. When a thermocouple is ungrounded, the junction is detached from the sensor hull and electrically isolated. The detached junction results in slower response times compared to grounded probes. The electrically isolated junction prevents the signal from being interrupted by electrical noise. Thus the accuracy of the temperature measurement is much higher. A grounded thermocouple is a thermocouple where the junction is welded directly to the inside of the hull at the tip of the sensor which results an effective heat transfer thus faster response times. However, grounded thermocouples are prone to induce noise from ground loops which results in a less accurate reading.

The MAX31855 only works with ungrounded thermocouple probes.

MAX31855 Thermocouple Driver

The datasheet (see Bill of Materials Section) gives the full list of the necessary details and specifications.

In brief, the MAX31855 is a thermocouple-to-digital converter with a built-in 14-bit analog-to-digital converter (ADC). The device also contains cold-junction compensation sensing and correction, a digital controller, with an SPI-compatible interface. The device is designed to work in conjunction with an external microcontroller. The MAX31855 is available in several versions, each optimized and trimmed for a specific thermocouple type (K, J, N, T, S, R, or E.). The thermocouple type is indicated in the suffix of the part number (e.g., MAX31855K).

For a K-type thermocouple, the voltage changes by about 41.276 µV/°C, the MAX31855 assumes a linear relationship between temperature and voltage. Because all thermocouples exhibit some level of nonlinearity, you may need to apply appropriate correction to the device’s output data.

The MAX31855 resolves temperatures to 0.25°C, allows readings as high as +1800°C and as low as -270°C (dependant upon thermocouple in use), and exhibits thermocouple accuracy of ±2°C for temperatures ranging from -200°C to +700°C for K-type thermocouples.

Arduino Code Library

The MAX31855 provides the temperature output in the form or a signed 14-bit, SPI-compatible, read-only format. This means the necessary microcontroller code is relatively simple, basically just being the SPI connection to capture the output data, which is 32bits. Then from this 32 bits, strip the 14-bit thermocouple temperature data, the 12-bit internal temperature, and 4-bits of error code.

There are a number of code libraries (1), with the offering by Rob Tillaart being recommended (3). However, since the required code is short, the following examples in the Testing/Experimental Results Section use 'custom' functions, so it can be readily apparent what the code is doing.


The Arduino Nano board has a surface mount microcontroller with headers for all pins. Additionally, the board provides a 5V regulator for external DC power input and PCB copper traces that enable insertion into standard USB connector which can then be used for DC power source. There is an onboard LED to indicate power-on and an additional LED/resistor connected to pin1 for user control.

For convenience for this simple test, the USB power supply is used.

ISP programming is used as detailed in the Arduino Nano introduction.

MAX31855

The most important initial point is that the MAX31855 is a 3.3V device and the appropriate power source will be necessary. Further, when using the Arduino Nano (or similar) the SPI output pins from the Nano are 5V which will damage the MAX31855 input pins. Therefore, the appropriate voltage conversion (just simple voltage divider resistors will suffice, as shown on the Schematics) will be necessary. This is assuming the MAX31855 breakout board is an "ebay special". Some more "reputable" versions possibly have input voltage conversion on board.

The Schematics Section gives the wiring diagram for connection of the CLK (clock), SO (data out), and CS (chip select) lines to the Nano.

From the data sheet, "because of the small signal levels involved, thermocouple temperature measurement is susceptible to power supply coupled noise. The effects of power-supply noise can be minimized by placing a 0.1 µF ceramic bypass capacitor close to the VCC pin of the device and to GND."

The datasheet also "recommends" to add a 10nF ceramic surface-mount differential capacitor, placed across the T+ and T- pins, in order to filter noise on the thermocouple lines. It is reported online/Youtube Channels that the MAX31855 breakout board "ebay specials" do in fact not actually work if this 10nF capacitor is not placed across the T+ and T- pins. However, I have not observed this to be the case, at least with the particular versions of the MAX31855 I sourced from ebay.

Thermocouple Wires

As previously discussed, thermocouples are made by welding together two wires, the MAX31855 reads the voltage difference between the two. One is the negative (for K-type its made of Alumel) and the other positive (for K-type its made of Chromel). Generally the wires are color coded, and almost all of the time you'll find the Alumel is red and the Chromel is yellow. If the thermocouple temperature goes down instead of up when heated, try swapping the red and yellow wires.


Note: Image loading can be slow depending on server load.

  • MAX31855 SchematicMAX31855 Schematic

    Silver Membership registration gives access to full resolution schematic diagrams.

    Arduino Nano with single MAX31855 Schematic

    Arduino Nano with single MAX31855 Schematic

  • Multiple MAX31855 SchematicMultiple MAX31855 Schematic

    Silver Membership registration gives access to full resolution schematic diagrams.

    Arduino Nano with multiple MAX31855 Schematic

    Arduino Nano with multiple MAX31855 Schematic

This project did not require a PCB.

The construction was done using prototyping board. See the photographs and schematic diagram sections.

Qty Schematic Part-Reference Value Notes
Resistors
2R1,R42K21/4W, 10% 
4R2,R33K81/4W, 10% 
Integrated Circuits
1U1Arduino/Nanomicrocontroller datasheet
1Z1MAX3185514-bit Thermocouple Driver datasheet
Miscellaeous
3J1wiresDupont pin jumper wires
Description Downloads
Bill of Materials Text File Download

Before connecting the Arduino Nano to the USB port, check for any shorts (direct positive voltage to ground connection) as this could damage both the Nano board and the USB/PC.

The SPI interface provided by the MAX31855 and the digital output of the temperature sensed by the thermocouple probe means temperature measurements with the MAX31855 is relatively straight forward. The following Code Snippet 1 demonstrates using a single MAX31855 to retrieve temperature from a connected thermocouple. Output is directed via the USB/serial port to a connected PC.

Nano Interfaced with single MAX31855

Since for a K-type thermocouple, the voltage changes by about 41.276 µV/°C, and the MAX31855 assumes a linear relationship between temperature and voltage, there is no need for 'calibration' as such of the MAX31855 (assuming the thermocouple itself is not damaged/worn-out).

While this will be sufficient for common applications such as kiln or furnance temperature monitoring, for applications requiring more precise temperature measurement, there are polynomial equations defined by the International Temperature Scale of 1990 (ITS-90) standard that correlate the temperature and voltage output. These polynomial equations, and the back calculated thermocouple output voltage, could be utilised by the user/Arduino code to provide an alternative method for calculating the output temperature, rather than relying upon the MAX31855 linear approximation across the temperature range.

Code Snippet 1: Nano Interfaced with single MAX31855


 #include  //SPI communication

 uint32_t rawData = 0; //raw value coming from the thermocouple (long because the 32 bits)
 uint32_t rawTC = 0;   //raw data of the thermocouple
 uint32_t rawInternal = 0; //raw data of the internal temperature sensor
 float TCCelsius = 0;      //Celsius degrees of the thermocouple
 float intCelsius = 0;     //Celsius degrees of the internal thermometer

 const byte CS_pin = 10;   //chip select pin

 String outputString;

 void setup() {
   pinMode(CS_pin, OUTPUT);    // define chip select as an output
   digitalWrite(CS_pin, HIGH); //pull chip select low
   SPI.begin();                //start SPI

   Serial.begin(9600);
   while (!Serial) {
     ; // wait for serial port to connect. Needed for native USB port only
   }
   Serial.println("Start\n");

 }

 void loop() {
   readThermocouple(); //read the thermocouple
   outputString = String(intCelsius,2) + ", " + String(TCCelsius,2) + "\n";
   Serial.println(outputString); //internal thermometer value
   delay(2000); //typical conversion time is 70-100 ms, choose delay accordingly
 }

 void readThermocouple() {
   //bits
   //D31-D18: 14-bit thermocouple temperature data
   //D17: Reserved
   //D16: Fault bit
   //D15-D4: 12-bit internal temperature data
   //D3: reserved
   //D2: SCV, D1: SCG, D0: OC

   // Set everything to zero to avoid confusion
   rawData = 0;
   rawInternal = 0;

   digitalWrite(CS_pin, LOW); // Force CS low and apply a clock signal at SCK to read the results at SO
   SPI.beginTransaction(SPISettings(14000000, MSBFIRST, SPI_MODE0)); //standard Arduino SPI

   // put together a 24-bit number:
   rawData = SPI.transfer(0);  //MSB comes in, first 8 bit is updated // '|=' compound bitwise OR operator
   rawData <<= 8;              //MSB gets shifted LEFT by 8 bits
   rawData |= SPI.transfer(0); //16 comes in
   rawData <<= 8;              //Shifting
   rawData |= SPI.transfer(0); //24 comes in
   rawData <<= 8;              //Shifting
   rawData |= SPI.transfer(0); //32 - LSB

   SPI.endTransaction();       //close down SPI transaction
   digitalWrite(CS_pin, HIGH); //finished command sequence, so we switch it back to HIGH

   // create the 12-bit internal temperature number
   rawInternal = rawData >> 4; //shifts out the D0-D3
   rawInternal = rawInternal & 4095; //4095 = B00000000000000000000111111111111
   // Calculate the temperature in Celsius
   intCelsius = rawInternal * 0.0625; //datasheet page 4
   // create the 14-bit (signed) thermocouple number
   rawTC = rawData >> 18; //shifts out the D0-D17
   // taking care of the sign
   if(rawTC >> 13 == 1) //of the 14th bit is 1
   {
     rawTC = rawTC - 16384; //conversion of negative numbers
   }
   // Calculating the temperature in Celsius
   TCCelsius = rawTC * 0.25; //datasheet page 4
 }

   				

Interfacing multiple MAX31855's

Since the MAX31855 supports the SPI interface, there can be multiple connected MAX31855/thermocouples depending upon provision of seperate CS (chip select) lines to the Nano for each connected MAX31855. The following code demonstrates utilising two MAX31855/thermocouples. Utilising port expansion chips such as the PCF8574, to handle peripherals such as LCD's and keypads for example, the Arduino Nano could provide necessary I/O pins to connect many MAX31855/thermocouples if desired.

Code Snippet 2: Interfacing multiple MAX31855's


#include 

const byte max31855_num                   = 2;         // number of max6675s
const int  max31855_cs_pins[max31855_num] = { 10, 9 }; // max6675 chip select pin

const byte max31855_fault_bit_oc  = 0B00000001; // open connection
const byte max31855_fault_bit_scg = 0B00000010; // short circuit to GND
const byte max31855_fault_bit_scv = 0B00000100; // short circuit to VCC
const byte max31855_fault_bit_any = 0B00001000; // any of the above

SPISettings max31855_spi(16000000,   // 16Mhz SPI clock
                      MSBFIRST,
                      SPI_MODE0);

void setup() {
int i;
for (i = 0; i < max31855_num; i++) {
   pinMode(max31855_cs_pins[i], OUTPUT);
   digitalWrite(max31855_cs_pins[i], HIGH);
}

SPI.begin();
Serial.begin(9600);
}

void loop() {
float thermocouple_temperature;
float internal_temperature;
byte  fault_bits;
int   i;

delay(1000);

for (i = 0; i < max31855_num; i++) {
   max31855Read(max31855_cs_pins[i],
                &thermocouple_temperature,
                &internal_temperature,
                &fault_bits               );
   Serial.print(i);
   Serial.print(" = ");
   Serial.print(thermocouple_temperature);
   Serial.print(", ");
   Serial.print(internal_temperature);
   Serial.print("\t");
}

Serial.println();
}

void max31855Read(int    max31855_cs_pin,
               float* thermocouple_temperature,
               float* internal_temperature,
               byte*  fault_bits)
{
unsigned int data_0;
unsigned int data_1;

digitalWrite(max31855_cs_pin, LOW);
SPI.beginTransaction(max31855_spi);

data_0 = SPI.transfer16(0);
data_1 = SPI.transfer16(0);

SPI.endTransaction();
digitalWrite(max31855_cs_pin, HIGH);

*fault_bits               =   data_1 & 0B0000000000000111
                          | ((data_0 & 0B0000000000000001) << 3);

*internal_temperature     = ((data_1 & 0B0111111111110000) >> 4) * 0.0625;
if (                          data_1 & 0B1000000000000000)
*internal_temperature     += -128;

*thermocouple_temperature = ((data_0 & 0B0111111111111100) >> 2) * 0.25;
if (                          data_0 & 0B1000000000000000)
*thermocouple_temperature += -2048;

if (*fault_bits) *thermocouple_temperature = NAN;
}
                

The circuit is the basic minimum required to enable the Arduino Nano microcontroller to operate after being programmed with a suitable .hex file. So this circuit was only laid out on a breadboard.

Before connecting the Arduino Nano to the USB port, check for any shorts (direct positive voltage to ground connection) as this could damage both the Arduino board and the USB/PC.

As discussed in the Background Section, the MAX31855 is a 3.3V device. Which means that the input pins to the MAX31855 will need appropriate voltage conversion (e.g., voltage divider resistors) if using output from 5V devices such as the Arduino Nano. This is probably the most common Gotch'ya.

Another common problem is to remember that the MAX31855 only works with ungrounded thermocouple probes.

From the data sheet, "because of the small signal levels involved, thermocouple temperature measurement is susceptible to power supply coupled noise. The effects of power-supply noise can be minimized by placing a 0.1 µF ceramic bypass capacitor close to the VCC pin of the device and to GND."

The datasheet also "recommends" to add a 10nF ceramic surface-mount differential capacitor, placed across the T+ and T- pins, in order to filter noise on the thermocouple lines. It is reported online/Youtube Channels that the MAX31855 breakout board "ebay specials" do in fact not actually work if this 10nF capacitor is not placed across the T+ and T- pins. However, I have not observed this to be the case, at least with the particular versions of the MAX31855 I sourced from ebay.

Finally, as previously discussed, thermocouples are made by welding together two wires, the MAX31855 reads the voltage difference between the two. One is the negative (for K-type its made of Alumel) and the other positive (for K-type its made of Chromel). Generally the wires are color coded, and almost all of the time you'll find the Alumel is red and the Chromel is yellow. If the thermocouple temperature goes down instead of up when heated, try swapping the red and yellow wires.


Note: Video loading can be slow depending on server load.

No video's for this topic.


Comments/Questions

No comments yet.

Add Comment/Question

Only Logged-In Members can add comments

"If we could sell our experiences for what they cost us, we'd all be millionaires".

Please donate any amount to help with hosting this web site.

If you subscribe (only $2/annum) you can view the site without advertisements and get emails abouts updates etc.

X

Sorry!

Only logged-in users with Silver Membership and above can download.


Silver Membership is only $2, so join now!