//Measure NTC value
byte NTCPin = A0;
const long SERIESRESISTOR = 10000;
// ~~~~~~ A,B,C ~~~~~~
#define A1 0.000797110609710217//-0.2860629305E-03
#define B1 0.000213433144381270 //4.484292072E-04
#define C1 0.000000065338987554 //-8.321267622E-07
float th_TC;
void setup()
{
Serial.begin(9600);
pinMode(NTCPin, INPUT);
delay(1);
}
void loop()
{
float ADCvalue;
float Resistance;
ADCvalue = analogRead(NTCPin);
Serial.print("Analog value ");
Serial.print(ADCvalue,0);
Serial.print(" = ");
//convert value to resistance
Resistance = (1023 / ADCvalue) - 1;
Resistance = SERIESRESISTOR / Resistance;
Serial.print(Resistance);
Serial.print(" Ohm");
th_TC = f_ReadTemp_ThABC(NTCPin, SERIESRESISTOR, A1, B1, C1); // 22k thermistor; ABC parameters were calculated using a digital precision sensor !
Serial.print(" | Temperature: ");
Serial.print(th_TC);
Serial.print(" | ");
// float A = 1.963175107e-3;
// float B = 0.9048811160e-4;
// float C = 32.66820892e-7;
float T = th_TC + 273.15;
float x,y;
float R;
x = (A1 - 1/T)/C1;
float B_C = B1/C1;
y = sqrt(B_C*B_C*B_C/27 + x*x/4);
R = exp(pow(y - x/2,1/3.) - pow(y + x/2,1/3.));
// Serial.print("R = %10.4f\n",R);
Serial.println(R);
delay(1000);
}
// TPin = Analog Pin
// THERMISTOR = NTC nominal value that is measured at 25*C
// R1 = R Serries
// A, B , C = the Steinhart–Hart coefficients, which vary depending on the type and model of thermistor and the temperature range of interest.
float f_ReadTemp_ThABC(byte TPin, float R1, float A, float B, float C) {
float R2 = R1 / ((1023.0 / analogRead(TPin)) - 1); // for pull-up configuration
float logR2 = log(R2); // Pre-Calcul for Log(R2)
float T = (1.0 / (A + B*logR2 + C*logR2*logR2*logR2));
T = T - 273.15; // convert Kelvin to *C
return T;
}
//end program