simulate this circuit – Schematic created using CircuitLab
This is the code that I'm using to get the temperature:
#define COEFF_A 0.8662984364E-03
#define COEFF_B 2.780704551E-04
#define COEFF_C -0.9395108479E-07
float VRT, Temp;
float Vref = 2.52;
void setup() {
Serial.begin(9600);
analogReference(EXTERNAL);
}
void loop() {
long Resistance;
VRT = analogRead(A3);
Resistance = 10000 / ((1023.0 / VRT) - 1);
Temp = log(Resistance);
Temp = 1 / (COEFF_A + (COEFF_B * Temp) + (COEFF_C * pow(Temp, 3)));
Temp += -273.15;
Serial.println(Temp);
delay(500);
}
I know that the calculation should be: V = Vref × VRT ÷ 1023
but i don't know how to implant it in this code, any help appreciated.
Update
After Edgar Bonet answer, the edited code is:
#define COEFF_A 0.8662984364E-03
#define COEFF_B 2.780704551E-04
#define COEFF_C -0.9395108479E-07
float VRT, Temp, VR;
void setup() {
Serial.begin(9600);
analogReference(EXTERNAL);
}
void loop() {
long Resistance;
VRT = analogRead(A3);
VR = 2.52 * VRT / 1024;
Resistance = 10000 * VR / (2.52 - VR);
Temp = log(Resistance);
Temp = 1 / (COEFF_A + (COEFF_B * Temp) + (COEFF_C * pow(Temp, 3)));
Temp += -273.15;
Serial.println(Temp);
delay(500);
}
But the temperature reading is 2 centigrade less than what it should be, when i remove the analogReference(EXTERNAL);
it shows the normal/correct temperature readings.