Hi, I want to get the temperature from a thermistor, so I made a simple a simple voltage divider (5V to thermistor, 10k between thermistor and ground, analogRead() between the 10k resistance and the thermistor.

The nominal value of the thermistor is 10K too,

I looked the datasheet (

http://www.vishay.com/docs/29049/ntcle100.pdf) and found a formula to get the temperature from the thermistor resistance:

K=3977

r ref=10k

A1=3.35401e-3

B1=2.56985e-4

C1=2.620131e-6

D1=6.383091e-8

T=(A1+B1*ln(r/r ref)+C1*ln^2(r/r ref)+D1*ln^3(R/r ref))^-1

and I found that using analogRead(), the resistance of the thermistor is

R=((1024-val)*10000)/val

Then I made a simple sketch to print the temperature on the serial monitor:

#include <avr/math.h>

//double calctemp(int value);

double temp;

void setup() {

// put your setup code here, to run once:

Serial.begin(115200);

}

void loop() {

// put your main code here, to run repeatedly:

temp=calctemp(analogRead(0));

Serial.println((double)temp);

delay(1000);

}

double calctemp(int value)

{

double temp;

temp=(1.0/(0.00335401+0.000256985*(double)log((((double)((1024-value)*10000)/(double)value))/(double)10000)+0.000002620131*(double)pow(log((((double)((1024-value)*10000)/(double)value))/(double)10000),2.0)+0.00000006383091*(double)pow((double)log((((double)((1024-value)*10000)/(double)value))/(double)10000),3.0)));

return temp;

}

But the problem is that I only get "nan" as output...

Has anyone a clue of what might be wrong?