After many hours of experimenting, researching, and overheating, I've found a way to get much higher resolution with an LM35 temperature sensor. it's on the playground:
I didn't know there was any other way than using the 1.1v reference!
Although avoiding using floats is also going to contribute to accuracy, I use fixed point arithmetic to deal with floats, and also since I use a light sensor which works better on a 5v reference
I also use 2 x lm35 to get an average reading, and take 20 readings from each sensor to loose any minor fluctuations.
Temperature returns an int in the range of 0 - 1000 (0.0-100.0°C), light 0-1000 (0%-100%) in practice 5-95. (perhaps more English weather!)
One thing to note when using ints always multiply BEFORE dividing, that way you retain your accuracy!
(note if using 1 sensor change the 550 to 1100 in the last function!!!)
//*********************************************************************
// Set internal reference discard next results
//*********************************************************************
void SetInternalReference() {
analogReference(INTERNAL) ;
ChangeOverDelay();
}
//*********************************************************************
// Set DEFAULT reference discard next results
//*********************************************************************
void SetDefaultReference() {
analogReference(DEFAULT) ;
ChangeOverDelay();
}
//*********************************************************************
// Read Some Values and Delay while reference changes
//*********************************************************************
void ChangeOverDelay() {
for (int j =0 ; j<10 ; j++) {
analogRead(0) ;
delay(40) ;
}
}
//*********************************************************************
// Averaging Read From Port
//*********************************************************************
long readAnalog(int Port, int Samples) {
long Accumulator = 0 ;
for (int i = 0; i < Samples ; i++) {
Accumulator = Accumulator + analogRead(Port);
}
return(Accumulator / Samples) ;
}
// *****************************************************************************
// Read value from light sensor re-scale 0-1000
// *****************************************************************************
int readLight(int analogPort) {
SetDefaultReference() ;
LastLight = int(readAnalog(LightSensor,SAMPLES_TO_AVERAGE)*1000/1023) ;
return(LastLight) ;
}
//*********************************************************************
// Read Tempreature from LM35 in F
//*********************************************************************
int readTempF() {
LastTemp = readTempC() * 9 / 5 + 320 ;
return(LastTemp);
}
//*********************************************************************
// Read Tempreature from LM35 in C
//*********************************************************************
int readTempC() {
SetInternalReference();
LastTemp = ((550*readAnalog(TempSensor,SAMPLES_TO_AVERAGE))/1024) ;
LastTemp += ((550*readAnalog(TempSensor1,SAMPLES_TO_AVERAGE))/1024) ;
return(LastTemp);
}
.... yield higher resolution, if only for appearances' sake.
This is very true
The LM has main advantage (over NTKs) that it need not be calibrated, however there is still an error of +/- 0.5K (don't confuse it with its non-linearity!).
The 1.1 volts of the ADC are very precise!
However there is a generic issue will all voltage sensors when you have any wires, clips, fittings, or jacks inbetween... Voltage sensors need to be connected directly to some high impedance input.
We have an untranslatable saying in German electronics: "Wer misst, der misst Mist!" ("Whoever is measuring, he will get garbage.") "Mist" is "bullsheet", "dung", "droppings" ... ;D