I'm currently working on a hotplate project with an ESP32, utilizing a 10k ohm NTC thermistor (B57550G1103F000) capable of measuring temperatures up to 300°C. However, I'm encountering issues with temperature accuracy. Below 50°C, there's about 5°C discrepancy between the measured and actual temperatures. Strangely, as the temperature increases beyond 50°C, this discrepancy becomes significantly larger (can go up to 300°c discrepancy).
I've experimented with both 3.3V and 5V connected to the voltage divider circuit. With 3.3V, the accuracy improves at lower temperatures but worsens as the temperature rises. Conversely, with a 5V supply, the accuracy is better at higher temperatures but remains problematic overall.
Here's the relevant portion of my code:
void checkTemperature() {
int ThermistorPin = 34; // Pin connected to the thermistor
double adcMax = 4095.0; // Maximum value of the ADC (analog-to-digital converter)
double Vs = 5; // Supply voltage
double R1 = 10000.0; // Voltage divider resistor value
double Beta = 3478.0; // Beta value of the thermistor
double To = 298.15; // Temperature in Kelvin for 25 degrees Celsius
double Ro = 10500.0; // Resistance of the thermistor at 25 degrees Celsius
// Variables for calculations
double Vout, Rt = 0;
double T, Tc, Tf = 0;
double totalTemperature = 0; // Accumulator for summing up temperature readings
// Read the temperature three times and calculate the average
for (int i = 0; i < 3; i++) {
// Read analog input and convert it to voltage
Vout = analogRead(ThermistorPin) * Vs / adcMax;
// Calculate resistance of the thermistor
Rt = R1 * Vout / (Vs - Vout);
// Calculate temperature using the Steinhart-Hart equation
T = 1 / (1 / To + log(Rt / Ro) / Beta); // Temperature in Kelvin
// Convert temperature to Celsius
Tc = T - 273.15; // Celsius
// Check if temperature is below 0 Celsius
if (Tc <= 0) {
// Re-read the temperature if it's below or equal to 0 Celsius
Vout = analogRead(ThermistorPin) * Vs / adcMax;
Rt = R1 * Vout / (Vs - Vout);
T = 1 / (1 / To + log(Rt / Ro) / Beta); // Temperature in Kelvin
Tc = T - 273.15; // Celsius
} else {
// Add current temperature reading to the accumulator
totalTemperature += Tc;
}
}
// Calculate the average temperature over the three readings
currentTemp = totalTemperature / 3;
// Print the temperature
Serial.print("Temperature: ");
Serial.println(currentTemp);
Serial.println(" °C");
}
I've linked the datasheet of the thermistor for reference: Thermistor Datasheet.
Digikey link to the thermistor: https://www.digikey.ca/en/products/detail/epcos-tdk-electronics/B57550G1103F000/3500386
I'd appreciate any insights into resolving this temperature accuracy issue. Thanks in advance!