arduinoesp8266arduino-idearduino-esp8266

D1 mini ESP8266 - Temperature monitor


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
}

Solution

  • I added this line before calculating the temperature in kelvin:

    steinhart += 1.0 / (25 + 273.15);  //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.

    Here you can see the full answere