Thermocouple returning erratic temperatures

Hi all,

I recently purchased the MAX6675 thermocouple and breakout board from SainSmart. The data I’m getting through Serial is erratic. From the demos I’ve seen online, I should be getting pretty consistent temperature read outs. I’m not sure what’s wrong with my setup.

MAX6675 PRODUCT LINK

Here’s the datasheet:

DATASHEET LINK

I’m using the adafruit library.

LIBRARY LINK

Code is listed below. I feel that my problem may be the pin setup. I’m still a noobie, so I’m not sure what I did wrong. I read online that the so, cs, and sck pins should be 12, 10, and 13, respectively. Not sure about the gnd and vcc pins, but I figured they wouldn’t matter as much… theoretically, they just need 0v and 5v, right? So I set them up to be pin 8 (gnd) and pin 9 (vcc). Then I set pin 8 and 9 to output, with 8 set to LOW and 9 set to HIGH.

Any help would be greatly appreciated. If needed, I can post a picture of my setup. But the code pretty much explains the pin setup.

Any ideas why this isn’t working?

My code is as follows:

#include <max6675.h>

//Thermocouple Pins
int thermo_gnd_pin = 8;
int thermo_vcc_pin = 9;
int thermo_so_pin = 12;
int thermo_cs_pin = 10;
int thermo_sck_pin = 13;

MAX6675 thermocouple(thermo_sck_pin, thermo_cs_pin, thermo_so_pin);

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);

  pinMode(thermo_vcc_pin, OUTPUT);
  pinMode(thermo_gnd_pin, OUTPUT);
  digitalWrite(thermo_vcc_pin, HIGH);
  digitalWrite(thermo_gnd_pin, LOW);

}

void loop() {
  Serial.print("Temp: ");
  Serial.println(thermocouple.readCelsius());

  delay(1000);

}

Example of erratic output:

UPDATE: I bought two of these sensors. Using my current setup, I switched out the first thermocouple with my second one. I didn’t change anything else.

Now the data is being outputted much more consistently. Everything seems to be working fine.

Welcome to the club! Programmers always point to the hardware as causing the problem!

Paul

Why do you connect the sensor Vcc and Gnd to digital pins, instead to Arduino Vcc and Gnd?

You are connecting it to the SPI pins (10, 12, 13), but you’re not using the internal SPI hardware. Change this:

MAX6675 thermocouple(thermo_sck_pin, thermo_cs_pin, thermo_so_pin);

To this:

MAX6675 thermocouple(thermo_cs_pin);

Pins 11, 12 and 13 (plus your CS pin 10) will be used by the internal hardware to talk to the MAX6675.

The first one is used if pins 11-13 are not available, and you have other pins that can act like SPI with software.

As others have mentioned, connect the MAX6675 Vcc/Gnd to the Arduino Vcc/Gnd.

Cheers,
/dev