D1 mini ESP8266 - Temperature monitor TCC-103

I am trying to monitor temperature with a D1 mini and a NTC, which is working, but the Temperature is calculated wrong. On the Serial Monitor I get Temperatures of around -300°C.

When printing the resistance I get values of around 10kOhm at 25ºC not 10Ohm as expected from the specs. (Zero Power Resistance at 25ºC (Ohm) = 10) But using 10kOhm instead of 10Ohm in the Steinhart-Hart equation doesnt fix the problem...

Can anyone tell me what I am doing wrong?

The Thermistor is connected like this to my D1 Mini ESP8266:

3.3V
 |
 \
 / TCC103
 \ (Thermistor)
 |
 |------ A0 (Analog Input)
 |
 \
 / R1 (10kΩ Resistor)
 \ 
 |
 |
GND

Specifications:

Part No = TTC-103
Zero Power Resistance at 25ºC (Ohm) = 10
B-Value R25/R50 (K) = 4050
Max. Permissible Current at 25ºC (mA) = 20
Thermal Dissipation Constant (mW/mW/ºC) = 8
Thermal Time Constant (Sec.) = 21
Operating Temperature (ºC) = -30~+125

Here is my code:

#include <Arduino.h>

// thermistor values
const int thermistorPin = A0;
const float seriesResistor = 10000;

void setup() {
  // Initialize Serial communication
  Serial.begin(9600);
}

float readTemperature() {
  int rawADC = analogRead(thermistorPin);

  // Convert ADC reading to resistance
  float resistance = seriesResistor / ((1023.0 / rawADC) - 1.0);

  // Calculate the temperature using the Steinhart-Hart equation
  float steinhart;
  steinhart = log(resistance / 10);  // 10 Ohm resistance at 25ºC
  steinhart /= 4050;                 // B-value (beta) = 4050

  // Calculate the temperature in Kelvin
  float kelvin = 1.0 / steinhart;

  // Invert the temperature in Celsius
  float temperature = 1 - (kelvin - 273.15);

  return temperature;
}

void loop() {
  float temperature = readTemperature();

  // Log the temperature to the Serial Monitor
  Serial.print("Temperature: ");
  Serial.print(temperature);
  Serial.println(" °C");

  delay(500); // Delay before checking temperature again
}

you are using A0 to measure the voltage across the 10K resistor
I tend to measure the voltage across the thermistor with the 10K resistor conected to VCC
have a look at ntc-thermistor-with-arduino-and-esp32

I got it to work like this:

I added this line before calculating the temperature in kelvin:

  steinhart += 1.0 / (25 + 273.15);  //25°C
  //in adafruit example code: "temp. for nominal resistance (almost always 25 C)"

I changed the temperature calculation to

  float temperature = kelvin - 273.15;

I also switched the place of the resistor and thermistor, so the thermistor is connected to GND and the resistor to 3V3

I also had to change the resistance at 25°C from 10Ohm to 10kOhm (which is more common as far as i know) but if its 10Ohm for your thermistor you maybe need to change the resistor to a lower value one to get better accuracy.

You can check out:
https://learn.adafruit.com/thermistor/using-a-thermistor

Measuring temp with a thermistor and the A/D of an ESP8266 (or ESP32) is plain wrong.
The ESP has the wrong A/D for that (absolute vs. ratiometric), and the linearity is bad.
Better stick with digital temp sensors with those processors (I2C, DS18B20, etc).
Leo..

2 Likes

I got a DS18B20 and its alot easier than using a NTC... No calculation and it worked right away.
Thanks for the tip!!!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.