The ESP32 has a built-in temperature sensor within the SoC itself, which allows us to measure the processor’s temperature accurately, without the need for additional components.
The purpose of this sensor is not to measure ambient temperature, but the CPU temperature. Typically, to detect if it is overheating.
However, if the ESP32 has just powered on after a period of being disconnected (for example, after a long Deep Sleep), it can provide an approximate measurement of the ambient temperature.
It is important to note that the accuracy of the built-in temperature sensor can vary due to environmental conditions and hardware tolerances.
For more precise measurements, calibration is recommended. This involves comparing the temperature sensor readings with a reference thermometer and applying adjustments in the software as needed.
Reading the Temperature
To read the temperature with the ESP32, you can use the software API provided by Espressif Systems.
Below is an example of how to read the temperature from the sensor in code:
void setup() {
Serial.begin(115200);
}
void loop() {
float temp_celsius = temperatureRead();
Serial.print("Temp onBoard ");
Serial.print(temp_celsius);
Serial.println("°C");
delay(1000);
}

