If you have a requirement of working with accurate and fast temperature sensing application using a thermocouple, this post is for you. We use a thermocouple to digital IC which can work with many types of thermocouple.
{tocify} $title={Table of Contents}
MAX31856
MAX31856 is a thermocouple-to-digital converter made by Maxim Integrated. It can be used to measure the temperature of a thermocouple, which is a type of temperature sensor that uses the thermoelectric effect to measure the temperature difference between two points. The MAX31856 is able to measure temperatures from -270°C to +1800°C with an accuracy of ±2°C. It can also be used with a variety of different types of thermocouples, including K, J, N, T, E, R, S, and B. It communicate via SPI interface. It also includes cold-junction compensation, which is used to accurately measure the temperature of the thermocouple even when the temperature of the cold junction (where the thermocouple wire is connected to the circuit) is not known.=
ESP32
ESP32 is a low-cost, low-power microcontroller with built-in Wi-Fi and Bluetooth capabilities. It is made by Espressif Systems and is based on the company's ESP32 series of chips. The ESP32 is a highly integrated chip that includes a dual-core processor, 520 KB SRAM, and various peripheral interfaces such as I2C, SPI, UART, and more.
The ESP32 also includes built-in support for Bluetooth and Wi-Fi
communication, making it well-suited for a wide range of Internet of Things
(IoT) and other wireless applications. Additionally, it has many digital and
analog interfaces, including capacitive touch sensors, ADCs, and DACs. It also
supports OTA firmware updates and can act as a web server or a client.
It
also has multiple power modes to save energy and can support multiple sleep
modes. It can be programmed using ESP-IDF, Arduino or MicroPython
environments, and the SDKs are open-source.
It is widely used in
various IoT applications such as home automation, industrial control, and
sensor networks.
For this tutorial we will be using Arduino IDE with ESP 32 breakout board.
Hooking up MAX31856 to ESP32
Here we are using readily available breakout board for ESP32 and MAX31856. Note ESP32 breakout board are available in various formats and your's may not look like the one shown here. Nevertheless figure out the pin marking and make connection as instructed.MAX31856 | ESP32 |
---|---|
VIN | VIN |
3V | NC |
GND | GND |
SCK | D18 |
SDO | D19 |
SDI | D23 |
CS | D5 |
FLT | NC |
DRDY | D4 |
*NC - Not Connected
Now, before we go to code, we will need MAX31856 libraries. Fortunately, Adafruit had created a great library for MAX31856.
In Arduino got to TOOLS > MANAGE LIBRARY. Search for MAX31856 and install Adafruit MAX31856 Library.
Copy below code to Arduino IDE, compile and upload to ESP32
Note the code is valid for the above pin configuration and K type thermocouple. You can make changes in code to match your own configuration
Arduino Code
// This example demonstrates continuous conversion mode using the
// DRDY pin to check for conversion completion.
#include <Adafruit_MAX31856.h>
#define DRDY_PIN 4
// Use software SPI: CS, DI, DO, CLK
Adafruit_MAX31856 maxthermo = Adafruit_MAX31856(5, 23, 19, 18);
// use hardware SPI, just pass in the CS pin
//Adafruit_MAX31856 maxthermo = Adafruit_MAX31856(10);
void setup() {
Serial.begin(115200);
while (!Serial) delay(10);
Serial.println("MAX31856 thermocouple test");
pinMode(DRDY_PIN, INPUT);
if (!maxthermo.begin()) {
Serial.println("Could not initialize thermocouple.");
while (1) delay(10);
}
maxthermo.setThermocoupleType(MAX31856_TCTYPE_K);
Serial.print("Thermocouple type: ");
switch (maxthermo.getThermocoupleType() ) {
case MAX31856_TCTYPE_B: Serial.println("B Type"); break;
case MAX31856_TCTYPE_E: Serial.println("E Type"); break;
case MAX31856_TCTYPE_J: Serial.println("J Type"); break;
case MAX31856_TCTYPE_K: Serial.println("K Type"); break;
case MAX31856_TCTYPE_N: Serial.println("N Type"); break;
case MAX31856_TCTYPE_R: Serial.println("R Type"); break;
case MAX31856_TCTYPE_S: Serial.println("S Type"); break;
case MAX31856_TCTYPE_T: Serial.println("T Type"); break;
case MAX31856_VMODE_G8: Serial.println("Voltage x8 Gain mode"); break;
case MAX31856_VMODE_G32: Serial.println("Voltage x8 Gain mode"); break;
default: Serial.println("Unknown"); break;
}
maxthermo.setConversionMode(MAX31856_CONTINUOUS);
}
void loop() {
// The DRDY output goes low when a new conversion result is available
int count = 0;
while (digitalRead(DRDY_PIN)) {
if (count++ > 200) {
count = 0;
Serial.print(".");
}
}
Serial.println(maxthermo.readThermocoupleTemperature());
}
You should now get temperature output in your Serial Monitor.
Happy Building! Take Care, Wear Mask & Save Soil