Created
May 18, 2016 07:43
-
-
Save sleemanj/059fce7f1b8087edfe7d7ef845a5d881 to your computer and use it in GitHub Desktop.
MAX6675 Thermocouple Reader Example Arduino Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** MAX6675 Thermocouple Reader Example Code | |
* | |
* This is so simple a library would be silly! | |
* | |
* 6675 Module ==> Arduino | |
* CS ==> D10 | |
* SO ==> D12 | |
* SCK ==> D13 | |
* Vcc ==> Vcc (5v OK) | |
* Gnd ==> Gnd | |
* | |
* You can change the pin assignments below, any pins you want are fine. | |
* | |
* Upload coade and open your Serial terminal at 9600 to see the temperature | |
* printed every 1.5 seconds. That's all! | |
* | |
*/ | |
#include <SPI.h> | |
#define MAX6675_CS 10 | |
#define MAX6675_SO 12 | |
#define MAX6675_SCK 13 | |
void setup() { | |
Serial.begin(9600); | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
Serial.print(readThermocouple()); | |
Serial.println('c'); | |
// Just for completeness | |
if(readThermocouple() > 33) | |
{ | |
Serial.println("Wow it's hot today!"); | |
} | |
else if(readThermocouple() < 10) | |
{ | |
Serial.println("I hope you have your warm clothes on!"); | |
} | |
delay(1500); | |
} | |
double readThermocouple() { | |
uint16_t v; | |
pinMode(MAX6675_CS, OUTPUT); | |
pinMode(MAX6675_SO, INPUT); | |
pinMode(MAX6675_SCK, OUTPUT); | |
digitalWrite(MAX6675_CS, LOW); | |
delay(1); | |
// Read in 16 bits, | |
// 15 = 0 always | |
// 14..2 = 0.25 degree counts MSB First | |
// 2 = 1 if thermocouple is open circuit | |
// 1..0 = uninteresting status | |
v = shiftIn(MAX6675_SO, MAX6675_SCK, MSBFIRST); | |
v <<= 8; | |
v |= shiftIn(MAX6675_SO, MAX6675_SCK, MSBFIRST); | |
digitalWrite(MAX6675_CS, HIGH); | |
if (v & 0x4) | |
{ | |
// Bit 2 indicates if the thermocouple is disconnected | |
return NAN; | |
} | |
// The lower three bits (0,1,2) are discarded status bits | |
v >>= 3; | |
// The remaining bits are the number of 0.25 degree (C) counts | |
return v*0.25; | |
} |
double myTemperature;
...
myTemperature = readThermocouple();
Works very well! Got a max31855 that's showing half the real value so v*0.5 it will be...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This works great! Uploaded to Arduino Nano 33 Iot.
I am trying to link the temperature to a widget in the Arduino cloud but I can't figure out the proper statement. I generated Variable CloudTemperatureSensor temperature and tried temperature = readTemperature; but it was not successful.