user18720: This is a follow-up question from this other question
I followed of the user Jot (get the sensor away from the sun and use a delay in arduino program)
But the results are still varying.
I recorded the temperature measured in the sensor, the temperature measured using a mercury thermometer and calculated the difference. The data was collected within 8 days
Here's the data (sorted):
SENSOR  THERM   DIFF
32.69   31.25   1.44
32.00   30.25   1.75
31.94   30.50   1.44
31.87   30.50   1.37
31.44   29.50   1.94
31.00   29.00   2.00
30.75   29.00   1.75
30.50   29.00   1.50
30.44   28.80   1.64
30.31   28.90   1.41
30.25   28.75   1.50
29.87   28.00   1.87
29.81   28.00   1.81
29.81   28.00   1.81
29.81   28.25   1.56
29.75   28.20   1.55
29.69   28.00   1.69
29.56   27.00   2.56
28.75   27.25   1.50
28.69   27.00   1.69
28.56   27.00   1.56
28.44   27.00   1.44
28.25   26.80   1.45
28.00   26.50   1.50
28.00   25.50   2.50
28.00   25.00   3.00
27.75   25.50   2.25

The average difference is around +1.76°C but that's not linear, and as you can see there are fluctuation in the same sensor value, 28.00 has three associated temperatures(25.0, 25.5, 26.5). 
I'm not sure what to do, if the difference was regular I could simply subtract that from the sensor readings, but it seems that it varies a lot(Min: 1.37°C, Max: 3.00°C)
Any ideas?

user6628: This isn't so much an Arduino question, but you are asking how to do better than a simple offset.  The next level of complexity is to do an offset and scale.
If this is the best data you can get from your setup, a better calibration than just an offset would be finding the best offset and scale.  You can do this with your data in R with:
> x<- read.table(header=TRUE,text="SENSOR  THERM   DIFF
 32.69   31.25   1.44
 32.00   30.25   1.75
 31.94   30.50   1.44
 31.87   30.50   1.37
 31.44   29.50   1.94
 31.00   29.00   2.00
 30.75   29.00   1.75
 30.50   29.00   1.50
 30.44   28.80   1.64
 30.31   28.90   1.41
 30.25   28.75   1.50
 29.87   28.00   1.87
 29.81   28.00   1.81
 29.81   28.00   1.81
 29.81   28.25   1.56
 29.75   28.20   1.55
 29.69   28.00   1.69
 29.56   27.00   2.56
 28.75   27.25   1.50
 28.69   27.00   1.69
 28.56   27.00   1.56
 28.44   27.00   1.44
 28.25   26.80   1.45
 28.00   26.50   1.50
 28.00   25.50   2.50
 28.00   25.00   3.00
 27.75   25.50   2.25
 ")

summary(lm(THERM ~ SENSOR,x))

... to get:
Call:
lm(formula = THERM ~ SENSOR, data = x)

Residuals:
     Min       1Q   Median       3Q      Max 
-1.05217 -0.16263  0.08482  0.21809  0.47224 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) -4.81422    1.60425  -3.001  0.00602 ** 
SENSOR       1.10237    0.05369  20.533  < 2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.3816 on 25 degrees of freedom
Multiple R-squared:  0.944, Adjusted R-squared:  0.9418 
F-statistic: 421.6 on 1 and 25 DF,  p-value: < 2.2e-16

... from which you can use the intercept and SENSOR parameters as an intercept and scale like:
therm_estimate = -4.81422 + 1.10237 * sensor;

You could plot the data in R like:
library(ggplot2)
ggplot(x,aes(x=SENSOR,y=THERM))+geom_point() +geom_smooth(method='lm')

 
Looking at the graph and data, your mercury thermometer is reading sometimes to the nearest 0.1th, and sometime to the 0.25th, and that is causing patterns in your data.  Maybe use a better, high-accuracy, calibrated lab thermometer if you want to be sure you aren't calibrating against something unreliable.

18720: <p>This is a follow-up question from <a href="https://arduino.stackexchange.com/questions/35318/ds18b20-temperature-a-bit-off">this other question</a></p>

<p>I followed of the user Jot (get the sensor away from the sun and use a delay in arduino program)</p>

<p>But the results are still varying.</p>

<p>I recorded the temperature measured in the sensor, the temperature measured using a mercury thermometer and calculated the difference. The data was collected within 8 days</p>

<p>Here's the data (sorted):</p>

<pre><code>SENSOR  THERM   DIFF
32.69   31.25   1.44
32.00   30.25   1.75
31.94   30.50   1.44
31.87   30.50   1.37
31.44   29.50   1.94
31.00   29.00   2.00
30.75   29.00   1.75
30.50   29.00   1.50
30.44   28.80   1.64
30.31   28.90   1.41
30.25   28.75   1.50
29.87   28.00   1.87
29.81   28.00   1.81
29.81   28.00   1.81
29.81   28.25   1.56
29.75   28.20   1.55
29.69   28.00   1.69
29.56   27.00   2.56
28.75   27.25   1.50
28.69   27.00   1.69
28.56   27.00   1.56
28.44   27.00   1.44
28.25   26.80   1.45
28.00   26.50   1.50
28.00   25.50   2.50
28.00   25.00   3.00
27.75   25.50   2.25
</code></pre>

<p>The average difference is around <strong>+1.76°C</strong> but that's not linear, and as you can see there are fluctuation in the same sensor value, 28.00 has three associated temperatures(25.0, 25.5, 26.5). </p>

<p>I'm not sure what to do, if the difference was regular I could simply subtract that from the sensor readings, but it seems that it varies a lot(Min: 1.37°C, Max: 3.00°C)</p>

<p>Any ideas?</p>
 6628: <p>This isn't so much an Arduino question, but you are asking how to do better than a simple offset.  The next level of complexity is to do an offset and scale.</p>

<p>If this is the best data you can get from your setup, a better calibration than just an offset would be finding the best <strong>offset</strong> and <strong>scale</strong>.  You can do this with your data in R with:</p>

<pre><code>&gt; x&lt;- read.table(header=TRUE,text="SENSOR  THERM   DIFF
 32.69   31.25   1.44
 32.00   30.25   1.75
 31.94   30.50   1.44
 31.87   30.50   1.37
 31.44   29.50   1.94
 31.00   29.00   2.00
 30.75   29.00   1.75
 30.50   29.00   1.50
 30.44   28.80   1.64
 30.31   28.90   1.41
 30.25   28.75   1.50
 29.87   28.00   1.87
 29.81   28.00   1.81
 29.81   28.00   1.81
 29.81   28.25   1.56
 29.75   28.20   1.55
 29.69   28.00   1.69
 29.56   27.00   2.56
 28.75   27.25   1.50
 28.69   27.00   1.69
 28.56   27.00   1.56
 28.44   27.00   1.44
 28.25   26.80   1.45
 28.00   26.50   1.50
 28.00   25.50   2.50
 28.00   25.00   3.00
 27.75   25.50   2.25
 ")

summary(lm(THERM ~ SENSOR,x))
</code></pre>

<p>... to get:</p>

<pre><code>Call:
lm(formula = THERM ~ SENSOR, data = x)

Residuals:
     Min       1Q   Median       3Q      Max 
-1.05217 -0.16263  0.08482  0.21809  0.47224 

Coefficients:
            Estimate Std. Error t value Pr(&gt;|t|)    
(Intercept) -4.81422    1.60425  -3.001  0.00602 ** 
SENSOR       1.10237    0.05369  20.533  &lt; 2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.3816 on 25 degrees of freedom
Multiple R-squared:  0.944, Adjusted R-squared:  0.9418 
F-statistic: 421.6 on 1 and 25 DF,  p-value: &lt; 2.2e-16
</code></pre>

<p>... from which you can use the intercept and SENSOR parameters as an intercept and scale like:</p>

<pre><code>therm_estimate = -4.81422 + 1.10237 * sensor;
</code></pre>

<p>You could plot the data in R like:</p>

<pre><code>library(ggplot2)
ggplot(x,aes(x=SENSOR,y=THERM))+geom_point() +geom_smooth(method='lm')
</code></pre>

<p><a href="https://i.stack.imgur.com/N3dpV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/N3dpV.png" alt="Plot of THERM vs SENSOR with best-fit line"></a>   </p>

<p>Looking at the graph and data, your mercury thermometer is reading sometimes to the nearest 0.1th, and sometime to the 0.25th, and that is causing patterns in your data.  Maybe use a better, high-accuracy, calibrated lab thermometer if you want to be sure you aren't calibrating against something unreliable.</p>
