milesburton / Arduino-Temperature-Control-Library

Arduino Temperature Library
https://www.milesburton.com/w/index.php/Dallas_Temperature_Control_Library
973 stars 487 forks source link

Why the lib do not calibrate the DS18B20 sesor #215

Closed pierrot10 closed 2 years ago

pierrot10 commented 2 years ago

Hello

I leant to calibrate the sensors by taking a measure in the ice (rowLow), a measure in the boiled water (rawRange) with DS18B20 sensor. I also mesure the ice (referenceLow) and boiled eater (referenceRange) with an accurate temometer which resist to the boiled water.

Then the bellow function, adjust the temperature.

Why your library doe not do that? Or offer that option?

float ds18b20_corrected(float *temperature, float rawLow, float referenceLow, float rawRange, float referenceRange)
{
  //Return the calculate value following the calibration step
  float correctedValue;

  //RawRange = RawHigh - RawLow
  //ReferenceRange = ReferenceHigh - ReferenceLow

  correctedValue = (((*temperature - rawLow) * referenceRange) / rawRange) + referenceLow;
  return correctedValue;
}
RobTillaart commented 2 years ago

Good question. There are several thoughts about calibration made in the past, I do not recall them all but here are my thoughts at the moment.

If the function would be in the library it should calculate the correction factors once, so the performance is optimal.

void setCalibration (float low , float high, float range, ...);
{
  // calculate _A and _B
}

float correct (float temperature)
{
  return temperature * _A + _B;
}

For non-linear mapping you might have a look at multimap()

RobTillaart commented 2 years ago

@pierrot10 If there are no further questions please close the issue

ecosensors commented 2 years ago

Pressure for measuring should be1013 mBar

Are you sure about that? If you measure the low,high,rangeLow, rangeHigh at the same altitude and close to the location where the DS18B20 will work, the pressure should not be considered? Isn't?

RobTillaart commented 2 years ago

Depends on how you define calibration.

milesburton commented 2 years ago

Per Rob's comments, please reopen if you feel this requires more investigation