The ESP32 has an integrated temperature sensor within the SoC, which allows us to measure the temperature of the processor accurately, without the need for additional components.
The purpose of this sensor is not to measure the ambient temperature, but rather the CPU temperature. Normally, it is used to detect if it is overheating excessively.
However, if the ESP32 has just been powered on after a period of being disconnected (for example, after a long Deep Sleep), it can provide a rough estimate of the ambient temperature.
It is important to note that the accuracy of the integrated temperature sensor may vary due to environmental conditions and hardware tolerances.
To obtain more accurate measurements, it is recommended to perform calibration. This involves comparing the temperature sensor readings with a reference thermometer and applying adjustments in the software as necessary.
Temperature Reading
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);
}