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
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:
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.
Fig. 2: Style guard
Setup()
- Initialize the Serial monitor with a 115200 baud rate for debugging purposes.
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.
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.
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:
Fig. 6: ESP32 Core’s temperature in Fahrenheit
Fig. 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.
JLCPCB – Prototype 10 PCBs for $2 (For Any Color)
China’s Largest PCB Prototype Enterprise, 600,000+ Customers & 10,000+ Online Orders Daily
How to Get PCB Cash Coupon from JLCPCB: https://bit.ly/2GMCH9w
The post ESP32 Internal Temperature Sensor appeared first on The Engineering Projects.
No comments:
Post a Comment