Thermocouple over-temperature alarm (MAX6675)
Read a K-type thermocouple up to 1024 °C through a MAX6675 and sound an alarm above a set temperature.
Sensors · Beginner
In a real product: Pottery kiln controller (Industrial): A thermocouple watches temperatures above 1000 degrees and alarms on overheating.
Ovens, kilns, 3D printer hot ends and exhausts are too hot for an ordinary sensor. A thermocouple, two different metals welded together, survives them, and a MAX6675 board turns its tiny voltage into a temperature.
What you'll learn
- Reading a read-only SPI device bit by bit
- Why the MAX6675 needs a quarter of a second between readings
- Detecting a broken (open) thermocouple
How it works
Pulling CS LOW makes the MAX6675 shift out a 16-bit word on SO, one bit per SCK clock. Bits 14 to 3 are the temperature in quarter degrees; bit 2 is set when no thermocouple is connected, and readCelsius() then returns NAN.
Each conversion takes about 220 ms and starts when CS goes HIGH. Read it faster and you get the same value back, so the sketch waits 300 ms between readings. Above 250 °C the LED lights and the buzzer sounds; it clears 10 °C lower (hysteresis), so a reading hovering at the limit does not make the alarm chatter.
Try this
- Click the board while it runs and raise the temperature past 250 °C.
- Set the thermocouple to "open" in its settings: the sketch reports the fault.
- Remove the
delay(300)and see that the reading only changes every 220 ms.
sketch.ino
// Over-temperature alarm: a K-type thermocouple on a MAX6675 (SCK 6, CS 5, SO 4), an LED on 8 and a buzzer on 9.
#include <max6675.h>
const int SCK_PIN = 6, CS_PIN = 5, SO_PIN = 4, LED = 8, BUZZER = 9;
const float ALARM_C = 250, CLEAR_C = 240;
MAX6675 thermocouple(SCK_PIN, CS_PIN, SO_PIN);
bool alarm = false;
void setup() {
Serial.begin(9600);
pinMode(LED, OUTPUT);
delay(500); // let the first conversion finish
}
void loop() {
float c = thermocouple.readCelsius();
if (isnan(c)) {
Serial.println("Thermocouple open: check the wiring");
noTone(BUZZER);
} else {
if (!alarm && c >= ALARM_C) alarm = true;
if (alarm && c <= CLEAR_C) alarm = false;
Serial.print(c, 2);
Serial.println(alarm ? " C ALARM" : " C");
digitalWrite(LED, alarm);
if (alarm) tone(BUZZER, 2000); else noTone(BUZZER);
}
delay(300);
}