Hello everyone,
I want to use NTC thermistors to read surface temperature of metals, but I have 2 questions:
- Are these NTC thermistors appropiate for measuring surface temperature? They are used for measuring 3D printers extruder temperature.
- Will the analogRead() function of the ESP32 let me read the temperature properly? I have read that the ADC pins are not linear, so I’m worried the values won’t be correct.
I will appreciate any advice to help me measure surface temperatures with the ESP32 (or other boards).
Thanks in advance!
Xabi
Hi Xabi,
- Yes, using an NTC thermistor like that is probably the best way of measuring surface temperature for most applications
- As you also said, unfortunately the analogRead() is non-linear (read the “ADC Non-linear” section): https://rntlab.com/esp32-reading-analog-inputs/
Here’s the graph, so the ESP32 is not accurate and it will produce wrong readings:
If it never reaches “higher voltages” (around 3.1V), it will probably give you results that are good enough for most applications.
Regards,
Rui
Hi Rui and everyone,
I’m trying to read the NTC thermistor from aliexpress but I’m not getting any values (I’m getting super high values that don’t change). I’m using an example I found on the internet:
//Pins #define THERMISTORPIN 25 // Series resistor value #define SERIESRESISTOR 100000 // Number of samples to average #define SAMPLERATE 5 // Nominal resistance at 25C #define THERMISTORNOMINAL 100000 // Nominal temperature in degrees #define TEMPERATURENOMINAL 25 // Beta coefficient #define BCOEFFICIENT 3950 void setup() { Serial.begin(115200); } int getTemp() { double thermalSamples[SAMPLERATE]; double average, kelvin, resistance, celsius; int i; // Collect SAMPLERATE (default 5) samples for (i=0; i<SAMPLERATE; i++) { thermalSamples[i] = analogRead(THERMISTORPIN); delay(10); } // Calculate the average value of the samples average = 0; for (i=0; i<SAMPLERATE; i++) { average += thermalSamples[i]; } average /= SAMPLERATE; // Convert to resistanceresistance = 4095 / average - 1;resistance = SERIESRESISTOR/resistance; /* * Use Steinhart equation (simplified B parameter equation) to convert resistance to kelvin * B param eq: T = 1/( 1/To + 1/B * ln(R/Ro) ) * T = Temperature in Kelvin * R = Resistance measured * Ro = Resistance at nominal temperature * B = Coefficent of the thermistor * To = Nominal temperature in kelvin */ kelvin = resistance/THERMISTORNOMINAL; // R/Ro kelvin = log(kelvin); // ln(R/Ro) kelvin = (1/BCOEFFICIENT) * kelvin; // 1/B * ln(R/Ro) kelvin = (1/(TEMPERATURENOMINAL+273.15)) + kelvin; // 1/To + 1/B * ln(R/Ro) kelvin = 1/kelvin; // 1/( 1/To + 1/B * ln(R/Ro) ) // Convert Kelvin to Celsius celsius = kelvin - 273.15; // Send the value back to be displayed return celsius; } void loop() { int temp; // Call the function to get the temperature in degrees celsius temp = getTemp(); // Output the temp to serial Serial.print("Temp: "); Serial.print(temp); Serial.println(" C"); }
And I’m wiring it with a 100k ohm resistor like this:
In my case, the blue wire goes to the D25 pin of the ESP32 DOIT Board.
What am I doing wrong? Could you please help me with a simple example or anything? I would appreciate it so much.
Thanks in advance!
Xabi
Hi Xabi,
I don’t have any example on that exact subject at the moment, but what’s the values that are being printed in the serial monitor?
I recommend that you take a look and use this example to see, if it works with your circuit: https://learn.adafruit.com/thermistor/using-a-thermistor
Thanks Rui!
I made my thermistor work properly with the example you told me and this great video of G6EJD explaining the ADC in ESP32. I think you should take a look a it since it can be nice information to add to the ADC pins Unit of the course 🙂