Measure ESP internal tempearature

1 min read

The ESP32 has a built-in temperature sensor that can be used to measure the internal temperature of the chip. The temperature sensor is designed to measure the temperature of the chip itself, not the ambient temperature. This can be useful for monitoring the temperature of the chip to prevent overheating.

To measure the ESP32 internal temperature, you can use the following steps:

  1. Enable the temperature sensor by calling the temperature_sensor_enable() function.

  2. Get the current temperature by calling the temperature_sensor_get_celsius() function.

  3. Disable the temperature sensor by calling the temperature_sensor_disable() function.

The following code shows how to measure the ESP32 internal temperature.

#include <esp_temp_sensor.h>

void setup() {

Serial.begin(115200);

// Enable the temperature sensor.

temperature_sensor_enable();

}

void loop() {

// Get the current temperature in Celsius.

float temperature = temperature_sensor_get_celsius();

// Print the temperature to the serial monitor.

Serial.print("Temperature: ");

Serial.println(temperature);

// Disable the temperature sensor.

temperature_sensor_disable();

// Delay for 1 second.

delay(1000);

}


The ESP32 temperature sensor has a measurement range of -40 to 125 degrees Celsius. The accuracy of the sensor is +/-2 degrees Celsius.

It is important to note that the ESP32 temperature sensor is primarily designed to measure the temperature of the chip itself, not the ambient temperature. The internal temperature of the chip can be affected by a number of factors, such as the CPU load and the ambient temperature. Therefore, the temperature measured by the ESP32 temperature sensor may not be representative of the actual ambient temperature.