I'm using the analog input on the Controllino Maxi Automation to determine the temperature of a 10K NTC thermistor. I'm having some difficulty understanding how the ADC works.
On a regular arduino nano, this code from Adafruit works okay, only off by a degree. But on the Controllino it's off by anywhere between 6-10 degrees. Fine tuning the parameters (temp @25C, series resistor and B coff) doesn't help at all.
Looking at the documentation they mention a scaling factor (last couple lines in the image below) but I'm not sure how to apply it or what it means.
I assume this means I can't just convert straight from an ADC value into a voltage reading?
#include <Arduino.h>
#include <Controllino.h>
// which analog pin to connect
#define THERMISTORPIN A0
// resistance at 25 degrees C
#define THERMISTORNOMINAL 10000
// temp. for nominal resistance (almost always 25 C)
#define TEMPERATURENOMINAL 25
// how many samples to take and average, more takes longer
// but is more 'smooth'
#define NUMSAMPLES 5
// The beta coefficient of the thermistor (usually 3000-4000)
#define BCOEFFICIENT 3895 // datasheet - https://www.mouser.com/datasheet/2/240/Littelfuse_Thermistor_Probes_Assemblies_Threaded_U-1372560.pdf
// the value of the 'other' resistor
#define SERIESRESISTOR 9760
void setup(void) {
Serial.begin(921600);
}
void loop(void) {
float reading;
reading = analogRead(THERMISTORPIN);
Serial.print("Analog reading ");
Serial.println(reading);
// convert the value to resistance
reading = (1023/ reading) - 1; // (1023/ADC - 1)
reading = SERIESRESISTOR / reading; // 10K / (1023/ADC - 1)
Serial.print("Thermistor resistance ");
Serial.println(reading);
float steinhart;
steinhart = reading / THERMISTORNOMINAL; // (R/Ro)
steinhart = log(steinhart); // ln(R/Ro)
steinhart /= BCOEFFICIENT; // 1/B * ln(R/Ro)
steinhart += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To)
steinhart = 1.0 / steinhart; // Invert
steinhart -= 273.15; // convert absolute temp to C
Serial.print("Temperature ");
Serial.print(steinhart);
Serial.println(" *C");
delay(1000);
}
The schematic editor didn't have the thermistor symbol just btw