mikrokontrollersystemer-pro.../prosjekt.X/thermistor-temp.c

29 lines
598 B
C
Raw Normal View History

2024-03-13 09:25:36 +00:00
#include "themistor-temp.h"
2024-03-08 10:48:49 +00:00
2024-03-13 10:21:14 +00:00
2024-03-13 09:25:36 +00:00
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;
}