# Bad readings with K Thermocouple+MAX31855+Arduino Mega

**URL:** <https://forum.arduino.cc/t/bad-readings-with-k-thermocouple-max31855-arduino-mega/152163>\
**Category:** Sensors\
**Created:** [March 22, 2013, 6:33pm UTC](https://forum.arduino.cc/t/bad-readings-with-k-thermocouple-max31855-arduino-mega/152163 "2013-03-22T18:33:30Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 22, 2013, 6:33pm UTC](https://forum.arduino.cc/t/bad-readings-with-k-thermocouple-max31855-arduino-mega/152163/1 "2013-03-22T18:33:30Z")

</div>

Hi all!!!, I´m trying to use a K type thermocouple with an arduino Mega...For this I get a MAX31855 microchip for analogic-digital conversion and using SPI (not the module, only the chip). I'm using an Arduino Mega 1280, but I only get bad measurements (I tried different libraries in arduino 1.01 and Arduino 0023)....This is an example what I get (I heat the probe with my hand, and when I get bad measurements I stopped)-I think that it is clear:

 ![](https://europe1.discourse-cdn.com/arduino/original/4X/c/9/e/c9edc25249d8afb8ca57d344e6f94313bde81382.jpeg)

And the connection diagram I'm using is:

 ![](https://europe1.discourse-cdn.com/arduino/original/4X/c/9/e/c9edc25249d8afb8ca57d344e6f94313bde81382.jpeg)

I think that the error is in my connections, not in code....But if anyone can help me, Ill be pleased-I´m about a month trying to solve this....Thank you for your interest. 🙂

---

<div class="post-metadata">

**Author:** ![CrossRoads](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/crossroads/32/214033_2.png) [@CrossRoads](https://forum.arduino.cc/u/CrossRoads)\
**Post date:** [March 22, 2013, 6:37pm UTC](https://forum.arduino.cc/t/bad-readings-with-k-thermocouple-max31855-arduino-mega/152163/2 "2013-03-22T18:37:10Z")

</div>

"I think that the error is in my connections, not in code"

It'd be easier to help if you posted both.

Datasheet

> **[Mixed-signal and digital signal processing ICs | Analog Devices](https://www.analog.com/en/index.html)**
>
> Analog Devices is a global leader in the design and manufacturing of analog, mixed signal, and DSP integrated circuits to help solve the toughest engineering challenges.

---

<div class="post-metadata">

**Author:** ![CrossRoads](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/crossroads/32/214033_2.png) [@CrossRoads](https://forum.arduino.cc/u/CrossRoads)\
**Post date:** [March 22, 2013, 6:45pm UTC](https://forum.arduino.cc/t/bad-readings-with-k-thermocouple-max31855-arduino-mega/152163/3 "2013-03-22T18:45:43Z")

</div>

"The Typical Application Circuit shows the device interfaced  
with a microcontroller. In this example, the device  
processes the reading from the thermocouple and  
transmits the data through a serial interface. Drive CS  
low and apply a clock signal at SCK to read the results  
at SO. Conversions are always being performed in the  
background. The fault and temperature data are only be  
updated when CS is high.  
Drive CS low to output the first bit on the SO pin. A  
complete serial-interface read of the cold-junction compensated  
thermocouple temperature requires 14 clock  
cycles. Thirty-two clock cycles are required to read both  
the thermocouple and reference junction temperatures  
(Table 2 and Table 3.) The first bit, D31, is the thermocouple  
temperature sign bit, and is presented to the SO  
pin within tDV of the falling edge of CS. Bits D[30:18]  
contain the converted temperature in the order of MSB  
to LSB, and are presented to the SO pin within tD0 of the  
falling edge of SCK. Bit D16 is normally low and goes  
high when the thermocouple input is open or shorted to  
GND or VCC. The reference junction temperature data  
begins with D15. CS can be taken high at any point while  
clocking out conversion data. If T+ and T- are unconnected,  
the thermocouple temperature sign bit (D31) is  
0, and the remainder of the thermocouple temperature  
value (D[30:18]) is 1."

All the examples would require 4 SPI transfers, after which you'd mask off for the 14 bits of interest.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 22, 2013, 6:49pm UTC](https://forum.arduino.cc/t/bad-readings-with-k-thermocouple-max31855-arduino-mega/152163/4 "2013-03-22T18:49:23Z")

</div>

Thank you CrossRoads for your fast answer....I tried different codes with the same problem. An example of one of this(the code used in the capture of the monitor I posted before), is:

> #include \<max31855.h\>
> 
> // \*\*\*\*\* PIN ASSIGNMENT \*\*\*\*\*  
> int thermocoupleSO = 50;  
> int thermocoupleCS = 53;  
> int thermocoupleCLK = 52;
> 
> double inputC;  
> double inputF;  
> double inCJC;  
> int inFault;
> 
> bool inOpen=0;  
> bool inShortGND=0;  
> bool inShortVCC=0;  
> bool inFaulted;
> 
> // Seconds timer  
> int timerSeconds;  
> unsigned long nextCheck;
> 
> // Specify MAX31855 thermocouple interface  
> MAX31855 thermocouple(thermocoupleCLK, thermocoupleCS, thermocoupleSO);
> 
> void **setup** ()  
> {
> 
> // Serial communication at 57600 bps  
> **Serial**.begin(57600);  
> }
> 
> void **loop** ()  
> {
> 
> inputC = thermocouple.readCelsius();  
> inputF = thermocouple.readFarenheit();  
> inCJC = thermocouple.readCJC();  
> inFault = thermocouple.readFaultCode();
> 
> // alternative method  
> // inFaulted = thermocouple.readMAX31855( &inputC, &inCJC, &inOpen, &inShortGND, &inShortVCC);
> 
> // Send temperature and time stamp to serial  
> **Serial**.print("Temperature: ");  
> **Serial**.print(inputC);  
> **Serial**.print("C, ");  
> **Serial**.print(inputF);  
> **Serial**.print("F. CJC: ");  
> **Serial**.print(inCJC);  
> **Serial**.print("C ");  
> if (inFault)  
> **Serial**.println("Faulted");  
> else  
> **Serial**.println(" No Fault");
> 
> delay(1000);
> 
> }

The connections are like I posted in the diagram, I don´t understand you well.....If it´s neccesary, I will make photographs of the circuit and the Arduino, and I'll post it here. Thank you for your help 🙂

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 22, 2013, 6:55pm UTC](https://forum.arduino.cc/t/bad-readings-with-k-thermocouple-max31855-arduino-mega/152163/5 "2013-03-22T18:55:43Z")

</div>

> CrossRoads:  
> "The Typical Application Circuit shows the device interfaced  
> with a microcontroller. In this example, the device  
> processes the reading from the thermocouple and  
> transmits the data through a serial interface. Drive CS  
> low and apply a clock signal at SCK to read the results  
> at SO. Conversions are always being performed in the  
> background. The fault and temperature data are only be  
> updated when CS is high.  
> Drive CS low to output the first bit on the SO pin. A  
> complete serial-interface read of the cold-junction compensated  
> thermocouple temperature requires 14 clock  
> cycles. Thirty-two clock cycles are required to read both  
> the thermocouple and reference junction temperatures  
> (Table 2 and Table 3.) The first bit, D31, is the thermocouple  
> temperature sign bit, and is presented to the SO  
> pin within tDV of the falling edge of CS. Bits D[30:18]  
> contain the converted temperature in the order of MSB  
> to LSB, and are presented to the SO pin within tD0 of the  
> falling edge of SCK. Bit D16 is normally low and goes  
> high when the thermocouple input is open or shorted to  
> GND or VCC. The reference junction temperature data  
> begins with D15. CS can be taken high at any point while  
> clocking out conversion data. If T+ and T- are unconnected,  
> the thermocouple temperature sign bit (D31) is  
> 0, and the remainder of the thermocouple temperature  
> value (D[30:18]) is 1."
> 
> All the examples would require 4 SPI transfers, after which you'd mask off for the 14 bits of interest.

Thank you for your help and interest CrossRoads, this is an interesting information about the running of this chip, but I don´t know how to apply this in my problem...Sorry for my ignorance, and thank you

---

<div class="post-metadata">

**Author:** ![CrossRoads](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/crossroads/32/214033_2.png) [@CrossRoads](https://forum.arduino.cc/u/CrossRoads)\
**Post date:** [March 22, 2013, 7:12pm UTC](https://forum.arduino.cc/t/bad-readings-with-k-thermocouple-max31855-arduino-mega/152163/6 "2013-03-22T19:12:49Z")

</div>

I am not familiar with the library max31855.h  
As such, I would simply do this:

digitalWrite(ssPin, LOW);  
byte3 = SPI.transfer(0);  
byte2 = SPI.transfer(0);  
byte1 = SPI.transfer(0);  
byte0 = SPI.transfer(0);  
digitalWrite(ssPin, HIGH);

dataResult = (byte3 \<\<24) + (byte2 \<\<16) +(byte1\<\<8 ) +byte0; // unsigned long

14bitTemp = dataResult \>\>18; // shift off the non-temperature bits

and do the math on the 14 bits that matter:

"For a K-type thermocouple, the voltage changes by about 41FV/NC, which approximates  
the thermocouple characteristic with the following linear equation:  
VOUT = (41.276FV/NC) x (TR - TAMB)  
where VOUT is the thermocouple output voltage (FV), TR is the temperature of the remote thermocouple junction  
(NC), and TAMB is the temperature of the device (NC)."

Or roughly (if I have the units correct):

float kTemp = (41.276/1000000)\*14bitTemp;

You can mask for the other bits & check for errors (opens, shorts).

Would be nice to get this chip working, would make a great alternative to

Thermocouple Amplifier AD595-AQ

typically used in oven controllers, as the MAX31855 is available for quite a few dollars less:

> **[MAX31855KASA+T | Digi-Key Electronics](https://www.digikey.com/en/products/detail/MAX31855KASA%2BT/MAX31855KASA%2BTCT-ND/2708805)**
>
> Order Analog Devices Inc./Maxim Integrated MAX31855KASA+T (MAX31855KASA+TTR-ND) at DigiKey. Check stock and pricing, view product specifications, and order online.

and AD595 is only from [Arrow.com](http://Arrow.com) that I have been able to find:  
[http://components.arrow.com/part/detail/52071S5444913N2771](http://components.arrow.com/part/detail/52071S5444913N2771)

or Sparkfun

> **[Thermocouple Amplifier AD595-AQ - COM-00306 - SparkFun Electronics](https://www.sparkfun.com/products/retired/306)**
>
> Analog Devices Thermocouple Type-K Amplifier. Attach a thermocouple, 5V power, and a decoupling capacitor and you've got 10mV/C output! Perfect for high te

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 24, 2013, 1:27pm UTC](https://forum.arduino.cc/t/bad-readings-with-k-thermocouple-max31855-arduino-mega/152163/7 "2013-03-24T13:27:26Z")

</div>

Thank you for your reply CrossRoads. I tried to do this, but without any result (I´m sure I did something wrong...).I´m sure too that the different codes I tried are correct because they examples from the different libraries for MAX31855. I'm thinking that the error could be for bad connections or bad using of level shifters (I´m using 2 voltage dividers- 1 for CS pin and other for SCK pin), to get 3v3 for the MAX31855. MISO pin is directly to Arduino Mega Digital 50.  
**There is a detail in the measurements** : At ambient temperature (about 14ºC it is measuring 2ºC and when I heat with my hand (view my first post), at more than 31,5ºC, it measurement is 0ºC. When I heat the probe with a lighter, the temperature increases more and more but It has a lot of bad measurements and others with 0ºC........Any suggestions for my circuit or pin configuration?

---

<div class="post-metadata">

**Author:** ![CrossRoads](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/crossroads/32/214033_2.png) [@CrossRoads](https://forum.arduino.cc/u/CrossRoads)\
**Post date:** [March 24, 2013, 7:14pm UTC](https://forum.arduino.cc/t/bad-readings-with-k-thermocouple-max31855-arduino-mega/152163/8 "2013-03-24T19:14:24Z")

</div>

Are you sure you have the right Kind of thermocouple for the chip you are using?  
The MAX31855 has 7 versions:  
MAX31855E,J,K,N,R,S,T, to go with the different kinds of probes.  
You have a MAX31855K ?

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 24, 2013, 9:42pm UTC](https://forum.arduino.cc/t/bad-readings-with-k-thermocouple-max31855-arduino-mega/152163/9 "2013-03-24T21:42:35Z")

</div>

Thank you for your reply...Yes I´m sure, I get the samples from MAXIM-IC and exactly is MAX31855KASA+, I´ve three of these, and everyone have the same problem. They are connected in a SOIC to DIP adapter connected in a protoboard, as you can see in the next photo:

(The capacitor that you can see between red and blue wire is 10nF for reducing noise-I didn´t draw it in the scheme)

The probe is from my multimeter (Velleman DVM 890), and I´m sure that it's a K probe too. I´m very confused :~

---

<div class="post-metadata">

**Author:** ![CrossRoads](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/crossroads/32/214033_2.png) [@CrossRoads](https://forum.arduino.cc/u/CrossRoads)\
**Post date:** [March 25, 2013, 2:44am UTC](https://forum.arduino.cc/t/bad-readings-with-k-thermocouple-max31855-arduino-mega/152163/10 "2013-03-25T02:44:35Z")

</div>

I don't know then. You seem to be connected to the right places.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 25, 2013, 6:22pm UTC](https://forum.arduino.cc/t/bad-readings-with-k-thermocouple-max31855-arduino-mega/152163/11 "2013-03-25T18:22:14Z")

</div>

Thank you for your help and replies CrossRoads.....Anyone has any suggestion??? Anyone used MAX31855??I can´t make it to run properlly....Could it be for the solder paste or using a protoboard---making a new couple of metals and giving me wrong results??? :~

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [February 15, 2014, 3:40pm UTC](https://forum.arduino.cc/t/bad-readings-with-k-thermocouple-max31855-arduino-mega/152163/12 "2014-02-15T15:40:27Z")

</div>

hello i recently started using max31855, and i wrote a code based on max31855.h library that seems to be working well, can not give sure because I was wrong when I ordered the samples and it was not for the right sensor. I still am waiting the right max31855.  
try the the code below and give me a feedback. It's likely that is not optimized, because I have not had much time to work on it .  
If you have any doubts says.

Sorry for my bad english.

```cpp
#define cs 10
#define sclk 13
#define miso 12

void setup() {
  //define pin modes
  pinMode(cs, OUTPUT);
  pinMode(sclk, OUTPUT); 
  pinMode(miso, INPUT);

  digitalWrite(cs, HIGH);

  Serial.begin(9600);
  
  Serial.println("MAX31855 test");

}

void loop() 
{
  int f = readInternal();
  Serial.print("Internal Temp = ");
  Serial.println(f);
  
  int c = readcelsius();
  
  if (isnan(c)) {
    Serial.println("Something wrong with thermocouple!");
  } 
  else 
  {
    Serial.print("C = "); 
    Serial.println(c);
    //Serial.print("spiread32() = "); 
    //Serial.println(spiread32());
  }
 
  delay(1000);
}

double readInternal() {
  unsigned int v;
  
  v = spiread32();
  
  // ignore bottom 4 bits - they're just thermocouple data
  v >>= 4;

  // pull the bottom 11 bits off
  float internal = v & 0x7FF;
  internal *= 0.0625; // LSB = 0.0625 degrees
  // check sign bit!
  if (v & 0x800) 
    internal *= -1;
  //Serial.print("\tInternal Temp: "); Serial.println(internal);
  return internal;
}

float readcelsius() {

  long v;
  
  v = spiread32();
  
  // get rid of internal temp data, and any fault bits
  v >>= 18;

  // pull the bottom 13 bits off
 short temp = v & 0x3FFF;

  // check sign bit
  if (v & 0x2000) 
    temp |= 0xC000;
  
  float centigrade = v;

  //centigrade *= 0.25;
  return centigrade;
}

long spiread32() { 
  
  long d = 0;

  digitalWrite(sclk, LOW);
  delay(1);
  digitalWrite(cs, LOW);
  delay(1);

  for (int i=31; i>=0; i--)
  {
    digitalWrite(sclk, LOW);
    delay(1);
    d <<= 1;
    if (digitalRead(miso)) 
    {
      d |= 1;
    }

    digitalWrite(sclk, HIGH);
    delay(1);
  }

  digitalWrite(cs, HIGH);
  //Serial.println(d, HEX);
  return d;
}

byte readError() 
{
  return spiread32() & 0x7;
}

```

---

<div class="post-metadata">

**Author:** ![robtillaart](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/robtillaart/32/1098811_2.png) [@robtillaart](https://forum.arduino.cc/u/robtillaart)\
**Post date:** [February 15, 2014, 6:19pm UTC](https://forum.arduino.cc/t/bad-readings-with-k-thermocouple-max31855-arduino-mega/152163/13 "2014-02-15T18:19:24Z")

</div>

@peko86  
What is typical is that the output in CJC makes jumps of 8 degrees C

Drop to zero often indicate bad wiring - can also if the breadboard is overused

---

<div class="post-metadata">

**Author:** ![mortenx](https://avatars.discourse-cdn.com/v4/letter/m/48db29/32.png) [@mortenx](https://forum.arduino.cc/u/mortenx)\
**Post date:** [September 6, 2019, 5:12am UTC](https://forum.arduino.cc/t/bad-readings-with-k-thermocouple-max31855-arduino-mega/152163/14 "2019-09-06T05:12:34Z")

</div>

i am using chip:  
M31855K  
1746A2  
+783AE

internal temp(temp2) is ok but thermocouple(temp1) readings are jumping up/down by 8 degree .. why so?

![temp.jpg](https://europe1.discourse-cdn.com/arduino/original/4X/e/1/4/e14f3fbf80f7bda71d36120674a3dd11e8dd6505.jpeg)

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 6, 2021, 10:01am UTC](https://forum.arduino.cc/t/bad-readings-with-k-thermocouple-max31855-arduino-mega/152163/15 "2021-05-06T10:01:03Z")

</div>


