Saturday, 29 January 2022

ESP32 Internal Temperature Sensor


We know that ESP32 is featured with multiple inbuilt sensors. Today we will discuss one of those inbuilt sensors.

Hello readers, I hope you all doing great.

We have already discussed the Hall effect sensor and Capacitive touch sensor of ESP32 in our previous tutorials. In this tutorial, we will learn about the Internal Temperature Sensor of ESP32.

ESP32 Internal Temperature Sensor

ESP32 Internal Temperature Sensor, ESP32 temperature sensor, temperature sensor esp32, esp32 thermometer, esp32 temperature sensor in Arduino IDE

Fig. 1

ESP32’s on-chip temperature sensor cannot be used for monitoring external temperature. It can only be used to monitor the temperature of the core.

This temperature sensor is available on some selective ESP32 boards and is obsolete on most of the ESP32.

We are using the DOIT ESP32 Dev-Kit V1 development board which is featured with the internal temperature sensor.

How does this temperature sensor work?

This temperature sensor module consists of a temperature sensor digital to analog converter (DAC) and an 8-bit Sigma Delta analog to digital converter (ADC).

Measurement range and conversion relationships are shown below:

ESP32 Internal Temperature Sensor, ESP32 temperature sensor, temperature sensor esp32, esp32 thermometer, esp32 temperature sensor in Arduino IDE

Table (1) Table from espressif.com

Offset =0 is the main measurement value while the rest are the extended ones.

Converting Fahrenheit into Celsius

Formula to convert observed temperature i.e., in Fahrenheit into Celsius :

(F-32) *(5/9) = degree Celsius

Programming ESP32 for to measure core temperature using Arduino IDE

#ifdef __cplusplus

extern “C” {

#endif

uint8_t temprature_sens_read();

#ifdef __cplusplus

}

#endif

uint8_t temprature_sens_read();

 

void setup()

{

Serial.begin(115200);

}

//====================================================

// Loop

//====================================================

void loop()

{

Serial.print(“Temperature: “);

Serial.print(temprature_sens_read() );

Serial.print(” F”);

Serial.print(“______”);

// Convert raw temperature in F to Celsius degrees

Serial.print((temprature_sens_read() – 32) / 1.8);

Serial.println(” C”);

delay(1000);

}

  • We are using the Arduino IDE as a compiler and upload into the ESP32 module. To know more about Arduino IDE and how to use it, follow our previous tutorial i.e., on the ESP32 programming series.

Code Description

  • Style guard is used at the beginning to declare some function to be of “C” linkage, instead of “C++” Basically, to allow C++ code to interface with C code.

ESP32 Internal Temperature Sensor, ESP32 temperature sensor, temperature sensor esp32, esp32 thermometer, esp32 temperature sensor in Arduino IDE

Fig. 2: Style guard

Setup()

  • Initialize the Serial monitor with a 115200 baud rate for debugging purposes.

ESP32 Internal Temperature Sensor, ESP32 temperature sensor, temperature sensor esp32, esp32 thermometer, esp32 temperature sensor in Arduino IDE

Fig. 3: Setup function

Loop()

  • Temperature_sens_read() function is used to read the temperature of core.
  • Print the observer temperature on the serial monitor.

ESP32 Internal Temperature Sensor, ESP32 temperature sensor, temperature sensor esp32, esp32 thermometer, esp32 temperature sensor in Arduino IDE

Fig. 4: loop function

 

  • Convert the temperature from Fahrenheit to degree Celsius and print on the serial monitor.
  • Result will be printed with a delay of 1sec.

ESP32 Internal Temperature Sensor, ESP32 temperature sensor, temperature sensor esp32, esp32 thermometer, esp32 temperature sensor in Arduino IDE

Testing or Results

  • Upload the code into the ESP32 board.
  • Open the serial monitor with a 115200 baud rate.
  • Press the EN button from the ESP32 development board.
  • See the result on the serial monitor as shown below:

ESP32 Internal Temperature Sensor, ESP32 temperature sensor, temperature sensor esp32, esp32 thermometer, esp32 temperature sensor in Arduino IDEFig. 6: ESP32 Core’s temperature in Fahrenheit

ESP32 Internal Temperature Sensor, ESP32 temperature sensor, temperature sensor esp32, esp32 thermometer, esp32 temperature sensor in Arduino IDEFig. 7: ESP32 Core’s temperature in Celsius

This concludes the tutorial. I hope you found this of some help and also to see you soon with the new tutorial on ESP32.

The post ESP32 Internal Temperature Sensor appeared first on The Engineering Projects.



No comments:

Post a Comment