Problem with reading from thermistor

Hello. I got problem with my project. When i try to read value from thermistor results are shown as NAN. I found that this mean not a number, but that doesn’t help. I’m using 10k thermistor and 10k resistor connected as below, i add this basic code that i use to test thermisotr.

#include <math.h>
 double Thermistor(int RawADC)
 {
 double Temp;
 Temp=log(10000.0*((1024.0/RawADC-1)));
 Temp=1/(0.001129148+(0.000234125+(0.0000000876741 * Temp * Temp)) * Temp);
 Temp=Temp - 273.15;
 Temp=(Temp*9.0)/5.0+32;
 return Temp;
  
 }
void setup()
{
  Serial.begin(9600);
}
void loop()
{
  int val;
  double temp;
  val=analogRead(1);
  temp=Thermistor(val);
  Serial.print("t=");
  Serial.print(temp);
  Serial.println("f");
  delay(1000);
  
  
}

Przechwytywanie.PNG

thermistor_basic.ino (490 Bytes)

Hello miczurek96,
Welcome to the forum.

Please read 'how to use this forum - please read' (big clues in the title) then go back and modify your post according to the instructions for posting your code in part 7. Thank you.

Your circuit looks reasonable.

Here’s OP’s code posted properly:

#include <math.h>
 double Thermistor(int RawADC)
 {
 double Temp;
 Temp=log(10000.0*((1024.0/RawADC-1)));
 Temp=1/(0.001129148+(0.000234125+(0.0000000876741 * Temp * Temp)) * Temp);
 Temp=Temp - 273.15;
 Temp=(Temp*9.0)/5.0+32;
 return Temp;
  
 }
void setup()
{
  Serial.begin(9600);
}
void loop()
{
  int val;
  double temp;
  val=analogRead(1);
  temp=Thermistor(val);
  Serial.print("t=");
  Serial.print(temp);
  Serial.println("f");
  delay(1000);
  
  
}
  1. You’d get NaN if you tried to calculate log(0) or log(-1) at the start of the Thermistor() function (line 5). I think this means that RawADC must be zero. This could happen if the thermistor wasn’t properly connected at either end, or if it had failed open circuit somehow.

  2. It’s probably just a typo, but which pin is your thermistor connected to? Diagram says A0, sketch says A1.

GypsumFantastic:
2. It's probably just a typo, but which pin is your thermistor connected to? Diagram says A0, sketch says A1.

Yeah it was a typo

GypsumFantastic:

  1. You'd get NaN if you tried to calculate log(0) or log(-1) at the start of the Thermistor() function (line 5). I think this means that RawADC must be zero. This could happen if the thermistor wasn't properly connected at either end, or if it had failed open circuit somehow.

That was my first thought, but i checked it with multimeter and everything is conected properly

What do you get if you just print the value from

  val=analogRead(1);

With the other code and the function Thermistor commented out?

Ok, so i dont know why, but after turning thermistor around it's working. It's extreamly weird,like the thermistor would have polarization. Anyway, i'm greatfull for your effort. :slight_smile: