/**
Basic NTC Thermistor demo
https://wokwi.com/arduino/projects/299330254810382858
Assumes a 10K@25℃ NTC thermistor connected in series with a 10K resistor.
Copyright (C) 2021, Uri Shaked
*/
const float BETA = 3950; // should match the Beta Coefficient of the thermistor
#define ntc_pin A0 // Pin,to which the voltage divider is connected
#define vd_power_pin 0 // [12.8.2023: MERACI PRIPRAVOK NTC&LM35: 0 ORIGINAL:2] 5V for the voltage divider
#define nominal_resistance 10000 //Nominal resistance at 25⁰C
#define nominal_temeprature 25 // temperature for nominal resistance (almost always 25⁰ C)
#define samplingrate 5 // Number of samples
#define beta 3950 // The beta coefficient or the B value of the thermistor (usually 3000-4000) check the datasheet for the accurate value.
#define Rref 10000 //Value of resistor used for the voltage divider = r2
int samples = 0; //array to store the samples
void setup() {
Serial.begin(9600);
}
void loop() {
float analogValue = analogRead(A0);
Serial.print("Analog ");
Serial.println(analogValue);
uint8_t i;
samples = 0;
// take voltage readings from the voltage divider
digitalWrite(vd_power_pin, HIGH);
for (i = 0; i < samplingrate; i++) {
samples += analogRead(ntc_pin);
delay(10);
}
float average;
average = 0;
average = samples / samplingrate;
Serial.print("ADC readings: ");
Serial.println(analogValue);
float celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
Serial.print("Temperature: ");
Serial.print(celsius);
Serial.println(" ℃");
average = 1023 / average - 1;
average = Rref / average;
Serial.print("Thermistor resistance ");
Serial.println(average);
delay(1000);
float rNTC = Rref/(1023/analogValue-1);
Serial.print("rNTC:");
Serial.println(rNTC);
delay(1000);
// Vout = Vin*[R2/(R1+R2)] (3)
// R2,rNTC=(Vout*R1) / (Vin-Vout)
//Vout = (a0 *Vin)/1024
// R2=(Vout*R1) / (Vin-Vout)
float voltage = analogValue *(5.0/1023.0);
float vout =(analogValue*voltage)/1024;
//float rNTC1 =(vout*Rref) / (voltage-vout) ;
float rNTC1 =(((analogValue*voltage)/1024)*Rref) / ((analogValue *(5.0/1023.0))-((analogValue*voltage)/1024)) ;
Serial.print("voltage: ");
Serial.println(voltage);
Serial.print("rNTC1: ");
Serial.println(rNTC1);
}