Example Code for Arduino-Read Temperature
Last revision 2025/12/11
Use the DFRobot Digital High Temperature Sensor (K-type) with Arduino to read current temperature and print it every one second. Users can learn how to connect the sensor to Arduino via I2C, install the DFRobot_MAX31855 library, and use the library to read temperature data.
Hardware Preparation
- DFRduino UNO R3 + Gravity IO Expansion Shield * 1
- Gravity: Digital High Temperature Sensor (K-type) * 1
- K-Type Thermocouple Probe * 1 (Comes with Gravity Digital High Temperature Sensor)
- Gravity 4P sensor wire * 1 (Comes with Gravity Digital High Temperature Sensor)
Software Preparation
- Arduino IDE: Click to Download Arduino IDE from Arduino®
- Search and install 'DFRobot_MAX31855' library in the Arduino IDE library manager
- Or download and install the .zip library via Github
Wiring Diagram
Other Preparation Work
- Connect the probe and Arduino to the module according to the connection diagram. The I2C address is fixed to 0x10.
- Install DFRobot_MAX31855 library.
- Open Arduino IDE, upload the sample code to the Arduino UNO.
- Open the serial monitor of Arduino IDE.
Sample Code
/*!
* file ReadTemp.ino
*
* Connect MAX31855 to arduino via I2C interface,then download this example
* @n open serial monitor to check the temperature.
*
* Copyright [DFRobot](https://www.dfrobot.com), 2016
* Copyright GNU Lesser General Public License
*
* version V0.1
* date 2018-3-6
*/
#include <DFRobot_MAX31855.h>
DFRobot_MAX31855 max31855;
void setup(){
Serial.begin(9600);
}
void loop(){
int stat;
/*Detect I2C device*/
stat = max31855.scan();
if(!stat){
Serial.println("No I2C devices!");
}
else{
/*Read Celsius*/
float temp = max31855.readCelsius();
Serial.print("Temperature:");
Serial.print(temp);
Serial.println(" ℃");
}
delay(1000);
}
Result
- Arduino prints current temperature every one second.
Was this article helpful?
