void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
// get analog of A0
int adcVal = analogRead(A0);
// calculat voltage
float v = adcVal * (5.0/1024.0);
// calculate resistance of thermistor
float Rt = 10 * v / (5 - v);
// calculate temperature in kelvin
float tempK = 1 / (log(Rt / 10) / 3950 + 1 / (273.15 + 25));
// calculate temperature in celsius
float tempC = tempK - 273.15;
// send result to computer via serial port
Serial.print("Current temperature is: ");
Serial.print(tempK);
Serial.print(" K, ");
Serial.print(tempC);
Serial.println(" C");
delay(500);
}