In this tutorial, we will learn how to interface K-Type Thermocouple MAX6675 Amplifier with ESP8266 NodeMCU and how to use it to measure temperature. The guide includes a brief introduction of the module with its pinout and connection diagram with ESP8266. Additionally, we will show you two Arduino sketches where we will be able to access the temperature readings from this module and display them on the Serial Monitor as well as on an OLED.
We have a similar guide with ESP32 and Arduino:
K-Type Thermocouple MAX6675 Amplifier
The MAX6675 module comes with a K-type thermocouple along with a driver and amplifier used to measure temperature in the range of 0°C to 1024°C. This is one of the ideal choices for measuring higher temperature readings which the other temperature sensors such as LM35 and others. This module consists of the MAX6675 chip which measures the temperature via the K-type thermocouple. The module uses an SPI interface to communicate with the microcontroller and transfer the output temperature readings.
Below you can view the specifications of this module:
- 12- bit resolution
- Accuracy of 8 LSBs
- Resolution of 0.25°C
- Operating Voltage is 5V
- Operating Current is 50mA
Thermocouple
The thermocouple is made with two different material wires. One end of these wires is connected together for making the junction. This junction is placed in that specific environment or object whose temperature we want to measure. When the temperature is changed then two different materials start to deform, as a result, the resistance is changed. Actually, its output is a millivolt signal whose voltages are changed when resistance is changed. This change in voltages could be measured easily with the help of thermocouples.
Working Principle
The working principle of Thermocouple is based on the Seebect effect. According to Seebeck, when two different metals are connected together for making two junctions then electromotive force would be developed at two junctions. The amount of this force would be different with metal material combinations.
According to the figure above, two different metals such as metal A and B are connected together for making two junctions. They are called ‘measuring end’ and ‘reference end’. Remember, two junctions are necessary for making any thermocouple. Temperature of the reference end is known but the measuring end is unknown. When this unknown temperature end is placed at that place where we want to measure the temperature. In this condition, if both ends would be at the same temperature level then there would be no EMF generated. So the net current in the whole circuit would be also zero.
Similarly, if both ends are at different temperature levels then the EMF would generate and current will be also flowing in the whole circuit. The value of this EMF or current also depends on thermocouple metal material as well as the temperature of both ends. By measuring the value of this current or EMF the user can easily find out the temperature of that specific place.
There are eight different types of thermocouples currently in the market with respect to their material. We use K Type Thermocouple with MAX6675 module. These K-type thermocouples (Nickel-Chromium / Nickel-Alumel) are less costly, more accurate, more reliable, and the most common type thermocouple. It has a wide range of temperatures such as –454 to 2,300F.
Pinout MAX6675
The diagram below shows the pinout of MAX6675 module:
It consists of a total of 7 pins where two are used to connect the thermocouple positive and negative leads, three for the SPI interface, and two for the power and ground.
Pin Name | Function |
GND | This is the ground pin of the module. |
VCC | This is the VCC pin used to supply power to the module in the range of 3-5.5V |
SCK | This is the SPI clock pin. |
CS | This is the SPI Chip select pin. |
SO | This is the serial output pin (data out). |
Thermocouple+ (TH+) | This is where we will connect the positive lead of the thermocouple. |
Thermocouple- (TH-) | This is where we will connect the negative lead of the thermocouple. |
Interfacing K-Type Thermocouple MAX6675 Amplifier with ESP8266 NodeMCU
We will require the following components for this project.
Required Components:
- ESP8266 NodeMCU board
- MAX6675 module with thermocouple
- Connecting Wires
Assemble the devices as shown in the schematic diagram below:
We will connect 5 pins of the MAX6675 module with ESP8266. These include the VCC, GND, SCK, CS and SO pins present on the same side. The VCC will be connected with the 3.3V pin from ESP8266. GND of both the devices will be in common. The default SPI GPIO pins of ESP8266 are being used to connect with each of the remaining SPI terminals of the MAX6675 module. The figure below shows the default SPI pins of ESP8266.
The table below shows the connections between the two devices:
MAX6675 | ESP8266 |
VCC | 3.3V |
GND | GND |
SCK | D5 (GPIO14) |
CS | D8 (GPIO15) |
SO | D7 (GPIO13) |
Now follow the connections between the two devices and connect them accordingly. We have used the same connections as specified above. All devices will have their grounds in common.
The thermocouple will be connected at the TH+ and TH- terminals.
Installing MAX6675 Thermocouple Library
We have an Arduino library for MAX6675 which can be easily used to get values of temperature. Now let’s see how to install the MAX6675 library. This library is provided by Adafruit.
To install the library, we will use the Arduino Library Manager. Open your Arduino IDE and go to Sketch > Include Libraries > Manage Libraries. Type ‘max6675’ in the search bar and install the latest version.
Arduino Sketch: Accessing Temperature Readings
Open your Arduino IDE and go to File > New. A new file will open. Copy the code given below in that file and save it.
This code will use max6675.h library provided by Adafruit. We will display the temperature (degree Celsius) in the Serial Monitor.
#include "max6675.h"
int SO = D7;
int CS = D8;
int sck = D5;
MAX6675 module(sck, CS, SO);
void setup() {
Serial.begin(115200);
}
void loop() {
float temperature = module.readCelsius();
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(F("°C "));
delay(1000);
}
How the Code Works?
We will start off by including the MAX6675 library that we previously installed.
#include "max6675.h"
Then we will create three integer variables each to hold the ESP8266 pins connected with the SPI pins: SO, SCK and CS. We have used the ESP8266 default SPI pins.
int SO = D7;
int CS = D8;
int sck = D5;
Next we will create an instance of MAX6675 called module() and pass the sck, CS and SO variables as parameters inside it.
MAX6675 module(sck, CS, SO);
Inside the setup() function, we will initialize the serial communication with the baud rate of 115200.
void setup() {
Serial.begin(115200);
}
Inside the loop() function, we will first obtain the temperature by readCelsius() method on the module instance and save the reading in a floating variable called ‘temperature.’ This will get printed in the serial monitor along with its unit after a delay of every 1 second.
void loop() {
float temperature = module.readCelsius();
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(F("°C "));
delay(1000);
}
Demonstration
Make sure you choose the correct board and COM port before uploading your code to the board. Go to Tools > Board and select NodeMCU 1.0. Next, go to Tools > Port and select the appropriate port through which your board is connected.
Click on the upload button to upload the code into the board.
After you have uploaded your code to the development board, press its RST button.
Now open the serial monitor in Arduino IDE, you will see temperature readings getting displayed after every one second.
Display MAX6675 K-Type Thermocouple Readings on OLED
In this section, we will see how to display the temperature readings of MAX6675 on a 0.96 SSD1306 OLED display using Arduino IDE and ESP8266.
Installing SSD1306 OLED Library in Arduino IDE
To use the OLED display in our project, we have to install the Adafruit SSD1306 OLED library in Arduino IDE. Follow the steps below to successfully install it.
Open Arduino IDE and click on Sketch > Library > Manage Libraries. Type ‘SSD1306’ in the search tab and install the Adafruit SSD1306 OLED library.
We will also require the Adafruit GFX library which is a dependency for SSD1306. Type ‘Adafruit GFX’ in the search tab and install it as well.
You may like this in-depth guide on OLED interfacing with ESP8266:
Schematic – OLED with ESP8266 and MAX6675 Thermocouple
This section shows how to connect ESP8266 board with MAX6675 and an OLED display. Follow the connections as described in the two tables below.
The tables below show the terminals of the three devices which should be connected together.
OLED Display | ESP8266 |
VCC | 3.3V |
GND | GND |
SCL | D1 (GPIO5) |
SDA | D2 (GPIO4) |
MAX6675 K-type thermocouple | ESP8266 |
GND | GND |
VCC | 3.3V |
CS | D8 (GPIO15) |
SO | D7 (GPIO13) |
SCK | D5 (GPIO14) |
Assemble the circuit as shown in the schematic diagram below:
We will connect the VCC terminal of the OLED display with 3.3V which will be in common with the ESP8266 board and MAX6675 VCC. SCL of the display will be connected with the SCL pin of the ESP8266 board and the SDA of the display will be connected with the SDA of the ESP8266.
Arduino Sketch to Display MAX6675 Readings on OLED
Copy the following code to your Arduino IDE and upload it to ESP8266 after assembling the above circuit diagram.
#include "max6675.h"
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
int SO = D7;
int CS = D8;
int sck = D5;
MAX6675 module(sck, CS, SO);
Adafruit_SSD1306 display = Adafruit_SSD1306(128, 64, &Wire, -1);
void setup() {
Serial.begin(115200);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
delay(2000);
display.clearDisplay();
display.setTextColor(WHITE);
}
void loop() {
float temperature = module.readCelsius();
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(F("°C "));
display.setTextSize(1);
display.setCursor(0,10);
display.print("Temperature: ");
display.setTextSize(2);
display.setCursor(0,30);
display.print(temperature);
display.print(" ");
display.setTextSize(1);
display.cp437(true);
display.write(167);
display.setTextSize(2);
display.print("C");
display.display();
delay(1000);
display.clearDisplay();
}
How the Code Works?
We will first include all the required libraries for MAX6675 as well as the OLED display which we just installed before.
#include "max6675.h"
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
Then we will create three integer variables each to hold the ESP8266 pins connected with the SPI pins: SO, SCK and CS. We have used the default ESP8266 SPI pins.
int SO = D7;
int CS = D8;
int sck = D5;
Next we will create an instance of MAX6675 called module() and pass the sck, CS and SO variables as parameters inside it.
MAX6675 module(sck, CS, SO);
Now, we will create an object named display which will be handling the OLED display and specifying the width, height, I2C instance (&Wire), and -1 as parameters inside it.’ -1′ specifies that the OLED display which we are using does not have a RESET pin. If you are using the RESET pin then specify the GPIO through which you are connecting it with your development board.
Adafruit_SSD1306 display = Adafruit_SSD1306(128, 64, &Wire, -1);
setup()
Inside the setup() function, we will initialize the serial communication with the baud rate of 115200.
Serial.begin(115200);
Moreover, we will also initialize the OLED display by using display.begin(). Make sure you specify the correct address of your display. In our case, it is 0X3C.
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
delay(2000);
Then, we will clear the buffer by using clearDisplay() on the Adafruit_SSD1306 object. Additionally, we will set the colour of the text as white.
display.clearDisplay();
display.setTextColor(WHITE);
loop()
Inside the loop() function, we will first obtain the temperature by readCelsius() method on the module instance and save the reading in a floating variable called ‘temperature.’ This will get printed in the serial monitor along with its unit after a delay of every 1 second.
float temperature = module.readCelsius();
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(F("°C "));
The setTextSize() function is used to set the size of font. We used low size for simple text such as “Temperature” and high size font to display actual temperature readings. The setCursor() method defined where we want to display our text on 128×64 OLED. Finally, the print() functions write the text on the defined position. We will display the updated temperature reading along with its unit on the OLED screen after every second.
display.setTextSize(1);
display.setCursor(0,10);
display.print("Temperature: ");
display.setTextSize(2);
display.setCursor(0,30);
display.print(temperature);
display.print(" ");
display.setTextSize(1);
display.cp437(true);
display.write(167);
display.setTextSize(2);
display.print("C");
display.display();
delay(1000);
display.clearDisplay();
Demonstration
To see the demonstration of the above code, upload the code to ESP8266. But, before uploading code, make sure to select NodeMCU 1.0 from Tools > Board and also select the correct COM port to which the board is connected from Tools > Port.
Once the code is uploaded to the board, the OLED will start displaying the temperature readings in degrees Celsius after every second.
Video demo:
You may also like to read:
- NEO-6M GPS Module with ESP8266 NodeMCU and Track Location on Google Maps
- RS485 Serial Communication between ESP32 and ESP8266
- ESP8266 MPU6050 Web Server Accelerometer and Gyroscope Dashboard with 3-D animation (SSE Events)
- HC-SR04 Ultrasonic Sensor with ESP8266 NodeMCU – Measure Distance
- ESP8266 NodeMCU Stepper Motor WebSocket Web Server using Arduino IDE
- DHT11/DHT22 Web Server ESP8266 NodeMCU using Arduino IDE
- Control ESP8266 Outputs using Blynk App and Arduino IDE