// https://forum.arduino.cc/t/temperature-status/1408491/
// https://mm.digikey.com/Volume0/opasdata/d220001/medias/docus/6536/TDC03C322J5.pdf
// From datasheet: TDC05C310□-5 NTCrefR = 10K NTCbeta = 4100
// parameters from DATASHEET
#define NTCrefT 25 // calibrated reference temperature
#define NTCrefR 10000 // thermistor zero-power resistance at reference temperature
#define NTCbeta 3095 // beta coefficient for thermistor
#define Rseries 10000 // 10k Ohm series resistor (module has one on-board)
/* +----------+
| UNO/NANO |
| 5V |---|NTC|--+
| | | (VCC - A0 changes with NTC/temperature)
| A0 |----------+
| | | (A0 - GND remains constant/GND)
| GND |--|R10k|--+
+----------+
*/
float VCC = 5.00, ADCMAX = 1023.00, VoltsPerBits = VCC / ADCMAX, Koffset = 273.15; // constants
float TcalcOld, Tref = NTCrefT + Koffset; // calculations
unsigned long timer, timeout = 100; // periodic reading in milliseconds
byte NTCpin = A0; // ADC input from NTC
void setup() {
Serial.begin(115200); // start serial communication
}
void loop() {
int NTCread = analogRead(NTCpin); // read NTC
float Vread = (VCC / ADCMAX) * (float)NTCread; // volts across thermistor = (volt/bit) * readbits
float Vseries = VCC - Vread; // volts across series resistor (diff = whole - part)
float Rread = Vread / (Vseries / Rseries); // resistance across thermistor
float Rlog = log(Rread / NTCrefR); // R = log of (thermistor R / reference R)
float Tcalc = (1 / ((Rlog / NTCbeta) + (1 / Tref))) - Koffset; // use NTCbeta to calculate temperature
// simplified calculation: https://docs.wokwi.com/parts/wokwi-ntc-temperature-sensor
// float Tcalc = 1 / (log(1 / (ADCMAX / NTCread - 1)) / NTCbeta + 1.0 / (Koffset + NTCrefT)) - Koffset;
// Not using Steinhart-Hart Equation: https://en.wikipedia.org/wiki/Steinhart%E2%80%93Hart_equation
// periodic check for change in value
if (millis() - timer > timeout) {
timer = millis(); // reset timer
if (Tcalc != TcalcOld) { // update on change
TcalcOld = Tcalc; // store old value
Serial.print("(update on change) Temperature: ");
Serial.print(Tcalc);
Serial.print("C\t");
Serial.print((Tcalc * 1.8) + 32); // f = c * 9 / 5 +32
Serial.print("F\t");
Serial.print(Tcalc + Koffset);
Serial.print("K");
Serial.println();
}
}
}