🌡 Using NTC Thermistor for Temperature Measurement with simple ESP32-C3 Arduino Library

Intro

In one of previous article I described my experience of designing and ordering aluminum board (LED PANEL). One of the feature of this board is small onboard 0402 NTC TS temperature sensors for precise measurement of the board operating temperature at different power.

Image🕯 Aluminum Board 1L JLCPCB LED Panel (PCB + PCBA)

Let's see how to connect onboard NTC thermistor to SoC ESP32 to measureLED PANEL temperature while it work.

Connection Diagram

Image

Note: capacitor 0.1uF-1uF between ADC input and ground is strongly recommended.
Note: Choose R_UP by taking into account maximum operating current (in my case 0.1mA) and supply voltage (in my case 3.3V). Pull up resistor in my case it's 20kOhm. Also prefer 1% or higher tolerance (0.1%) if possible.

Board

Image

Note: NTC connected using twisted wire.

Note: 20kOhm achieved by two 10kOhm in serial

Arduino Board and Configurations 

ImageImage

Adding Library

1) Since original library deleted, here is reserve copy for downloading:

1) GitHub (original repo): https://github.com/suoapvs/NTC_Thermistor

2) Mirror (directly from server): NTC_Thermistor.zip

2) Unzip folder NTC_Thermistor into standard path (change USERNAME to your):

  1. C:\Users\<strong>USERNAME</strong>\Documents\Arduino\libraries

3) Or press Sketch -> Include library -> Add .ZIP Library and choose download achieve with library:

ImageImage

Code

I'm using NCP15XH103F03RC NTC TS from Murata. Several values on B-Coefficient for different ranges are present in datasheet, so I chosen 25/50 °C B3380K.

NTC Thermistor (TS)

Image

Change defines in code according to your sensor and pin:

  1. #define SENSOR_PIN 1 /* NTC_ADC */
  2. #define REFERENCE_RESISTANCE 20000 /* R_UP */
  3. #define NOMINAL_RESISTANCE 10000 /* R_NTC */
  4. #define NOMINAL_TEMPERATURE 25
  5. #define B_VALUE 3380
  6. #define ESP32_ANALOG_RESOLUTION 4095
  7. #define ESP32_ADC_VREF_MV 3300

Full Code (Sketch)

  1. /*
  2.   NTC Thermistor for ESP32 higher accuracy results
  3.  
  4.   Reads a temperature from the NTC 3950 thermistor and displays
  5.   it in the default Serial.
  6.  
  7.   ESP32 devices are 12-bit ADC devices so the defuault is 4095 here.
  8.  
  9.   https://github.com/bobwolff68/NTC_Thermistor
  10.  
  11.   Created by Bob Wolff from Yuri's original - 2024
  12.   Released into the public domain.
  13. */
  14. #include <Thermistor.h>
  15. #include <NTC_Thermistor.h>
  16.  
  17. #define SENSOR_PIN 1 /* NTC_ADC */
  18. #define REFERENCE_RESISTANCE 20000 /* R_UP */
  19. #define NOMINAL_RESISTANCE 10000 /*R_NTC */
  20. #define NOMINAL_TEMPERATURE 25
  21. #define B_VALUE 3380
  22. #define ESP32_ANALOG_RESOLUTION 4095
  23. #define ESP32_ADC_VREF_MV 3300
  24.  
  25. Thermistor* thermistor;
  26.  
  27. // the setup function runs once when you press reset or power the board
  28. void setup() {
  29. Serial.begin(115200);
  30.  
  31. thermistor = new NTC_Thermistor_ESP32(
  32. SENSOR_PIN,
  33. REFERENCE_RESISTANCE,
  34. NOMINAL_RESISTANCE,
  35. NOMINAL_TEMPERATURE,
  36. B_VALUE,
  37. ESP32_ADC_VREF_MV,
  38. ESP32_ANALOG_RESOLUTION
  39. );
  40.  
  41. }
  42.  
  43. // the loop function runs over and over again forever
  44. void loop() {
  45. // Reads temperature
  46. const double celsius = thermistor->readCelsius();
  47. const double kelvin = thermistor->readKelvin();
  48. const double fahrenheit = thermistor->readFahrenheit();
  49.  
  50. // Output of information
  51. Serial.print("Temperature: ");
  52. Serial.print(celsius);
  53. Serial.print(" &deg;C, ");
  54. Serial.print(kelvin);
  55. Serial.print(" K, ");
  56. Serial.print(fahrenheit);
  57. Serial.println(" F");
  58.  
  59. delay(500); // optionally, only to delay the output of information in the example.
  60. }
  61.  

Compare Results

I added voltage read function to compare measured value from multimeter and measured by the ESP32-C3 ADC:

Multimeter

ESP32-C3 ADC

ImageImage

Quick Temperature Test

Serial Print

Multimeter Thermocouple

ImageImage
ImageImage

Big Temperature Test

IN WORK 🐱

Repository

1) GitHub: https://github.com/Egoruch/NTC-ESP32C3-ARDUINO

2) Mirror (directly from server): NTC-ESP32C3-ARDUINO.zip

⭐ Advices

  1. Use stable reference voltage like: 1.25V, 2.048V
  2. Use switch to power NTC TS, only when do measurement (just MCU pin since low power)

Conclusions

  • Using internal ESP32-xx ADC without capacitor very bad idea
  • Library showed very close value in compare to the multimeters' thermocouple measurements
  • Pay attention at the NTC TS maximum current and choose appropriate R_UP to prevent self-heating affection
  • I would say we achieved ±1°C

Image

2.11K
No comments yet. Be the first to add a comment!
Cookies?