#include int CS = 10; // Chip Select pin void setup() { Serial.begin(9600); pinMode(CS, OUTPUT); digitalWrite(CS, HIGH); SPI.begin(); } double readThermocouple() { uint16_t v; digitalWrite(CS, LOW); // Select MAX6675 delay(1); // Let MAX6675 stabilize v = SPI.transfer16(0x00) << 3; // Read 16-bit data and shift for bits v |= SPI.transfer(0x00) >> 5; // Finish shifting and get temperature digitalWrite(CS, HIGH); // Deselect MAX6675 if (v & 0x4) return NAN; // Check for thermocouple open return (v >> 3) * 0.25; // Convert to Celsius } void loop() { double temperature = readThermocouple(); if (isnan(temperature)) { Serial.println("Thermocouple not connected"); } else { Serial.print("Temperature: "); Serial.print(temperature); Serial.println(" °C"); } delay(1000); // Wait for next reading }