Thermocouple on an Arduino Uno
A K-type thermocouple on a MAX6675 board, read twice a second with Adafruit’s max6675 library, in Celsius and Fahrenheit. The whole build, an Arduino Uno and 1 more part, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.
Teaching? Assign it to your class in one click.
Beginner Runs in your browser. Free, and no account needed.
The parts retail for about $31. On Mokxi they're free.
Step by step, with the wiring and the common mistakes: Arduino MAX6675 Thermocouple: Wiring and Code
The code
The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.
// Thermocouple: a K-type thermocouple on a MAX6675 board, read twice a
// second with Adafruit's max6675 library.
//
// MAX6675 SCK -> 6, CS -> 5, SO -> 4, VCC -> 5 V, GND -> GND
//
// A thermocouple is two different metals joined at the tip. The junction
// makes a few microvolts per degree, far too little for the Uno's ADC, so
// the MAX6675 measures it, corrects for the temperature of its own terminals
// and sends the result as a 16-bit word: pull CS low and clock out sixteen
// bits. The temperature is bits 14 to 3, a quarter degree a count.
//
// The chip converts while CS is high and a conversion takes up to 0.22 s.
// Reading faster than that returns the same number again, which is why
// every MAX6675 sketch waits between reads.
//
// Things to try. Drag the slider on the board and watch the reading follow.
// Then open the board's properties and untick probe: the open thermocouple
// reads as NAN, and the sketch says so.
#include <max6675.h>
const int SCK_PIN = 6;
const int CS_PIN = 5;
const int SO_PIN = 4;
MAX6675 thermocouple(SCK_PIN, CS_PIN, SO_PIN);
void setup() {
Serial.begin(9600);
Serial.println("MAX6675 ready");
// Give the chip time to finish its first conversion.
delay(500);
}
// Hundredths printed as a whole number and two decimals, which keeps the
// float printing code out of the sketch.
void printHundredths(long h) {
if (h < 0) {
Serial.print('-');
h = -h;
}
Serial.print(h / 100);
Serial.print('.');
if (h % 100 < 10) Serial.print('0');
Serial.print(h % 100);
}
void loop() {
float celsius = thermocouple.readCelsius();
if (isnan(celsius)) {
Serial.println("No thermocouple");
} else {
Serial.print("C = ");
printHundredths((long)(celsius * 100));
Serial.print(" F = ");
printHundredths((long)(celsius * 180) + 3200);
Serial.println();
}
delay(500);
}
Parts list
3 parts, plus the jumper wires. They retail for about $31; on Mokxi they're free.
How it is wired
5 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.
- Ground: Arduino Uno R3 pin GND; Thermocouple converter, MAX6675 pin GND
- Arduino Uno R3 pin 6; Thermocouple converter, MAX6675 pin SCK
- Arduino Uno R3 pin 5; Thermocouple converter, MAX6675 pin CS
- Arduino Uno R3 pin 4; Thermocouple converter, MAX6675 pin SO
- 5 V: Thermocouple converter, MAX6675 pin VCC
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.