28 lines
597 B
C
28 lines
597 B
C
#include "themistor-temp.h"
|
|
|
|
float calculate_thermistor_temp(float readValue){
|
|
float R_therm;
|
|
float V_1;
|
|
float ln;
|
|
float T_therm;
|
|
float V_therm;
|
|
uint8_t V_tot = 5;
|
|
// Calculate Voltage over thermistor
|
|
V_therm = (V_tot/1024)*readValue;
|
|
|
|
// Voltage accross R_1
|
|
V_1 = V_tot - V_therm;
|
|
|
|
// Calculate Thermistor resistanse
|
|
R_therm = (V_therm)/ (V_1 / R_1);
|
|
|
|
// Steinhart-Harts formula
|
|
ln = log(R_therm/R_t0);
|
|
T_therm = (1/ ((ln/B) + (1/T_0)));
|
|
|
|
// Temperatur in celcius
|
|
T_therm -= 273.15;
|
|
|
|
return T_therm;
|
|
}
|