I use a VDO negative temperature coefficient (NTC) sensor to measure temperature with an Arduino Nano. The circuit is a 200 Ohm resistor to the sensor supplied by 5 volts. The voltage is read on the sensor. The following code snippets show how it is done.
Setup variables:
/
/CONSTANTS
//Analog Pin
const int tsense0Pin = 1; // input pin for VDO sensor
//Piecewwise cal vars
int sensorIndex = 0;
//Cal aray formed by (Temp@ADC 0, Temp@ADC 100, ..., Temp@ADC900, Temp@ADC1000, //temp@ADC1100) temps are in 0.1 deg C increments. Creates a peicewise cal
int calAry2[12] = {1800,1160,880,720,590,495,400,305,200,80,-20,-100}; // calibration for VDO //Sensor with 200 Ohm 5v pullup, conversion table feeds a map() command 0.1 /digit Deg C
int displayVal = 0;
code inside the loop():
// process the value from a VDO WaterTemp sensor, 200 Ohm 5V pullup -- pin A6 PlugP9 pin 16
//map the value to a piece wise calibration curve
displayVal = analogRead(tsense0Pin);
sensorIndex = displayVal/100;
displayVal = map(displayVal,sensorIndex*100,(sensorIndex+1)*100,calAry2[sensorIndex],calAry2[sensorIndex+1] );
displayVal now contains the temperature in degrees C in 0.1 deg increments. It can be displayed or converted to deg F with a simple formula and then displayed.
To create the calibration array (calary2[]), I first created a XY chart in Excel using A to D data vs temperature ( as measured or calculated from datasheet information). Then I created a second XY trace in the chart using 0, 100 200 ...1000,1100. I then adjusted the temperature values on this trace to place each data point on the original curve. These data points then become the calibration array.
Though not as elegant as using a complex formula, it is a simple, empirical way to calculate any non-linear function from gathered or calculated data. It is flexible. Need to double the cal points? Just change the increments to 50 ADC values (from 100).