//https://viereck.ch/ntc/
//Input voltage
float inputVoltage = 3.3;
//Serial resistance, KOhm
float R1 = 4.7;
//Thermistor resistance, KOhm
float ntcR25 = 100;
//Thermistor Beta coefficient
float ntcBeta = 3950;
float minVoltage = 0.000;
float maxVoltage = 3.300;
float maxValue = 1024;
float rNtc;
int analogPin = A0;
int T1;
void setup() {
Serial.begin(9600);
}
void loop()
{
T1 = GetTemperature(inputVoltage, R1, ntcR25, ntcBeta, minVoltage, maxVoltage, maxValue, analogPin);
Serial.println("Calculated Temperature " + String(T1));
}
int GetTemperature(float inputVoltage, float R1, float ntcR25, float ntcBeta, float minVoltage, float maxVoltage, float maxValue, int analogPin)
{
int value = 0;
value = analogRead(analogPin);
Serial.println("ADC Output " + String(value));
float measuredVoltage = value / maxValue * (maxVoltage - minVoltage) + minVoltage;
float rNtc = measuredVoltage * R1 / (inputVoltage - measuredVoltage);
float temperature = 1 / (log(rNtc / ntcR25) / ntcBeta + 1 / (273.15 + 25)) - 273.15;
return temperature;
}