Temperature spikes and drops with ds18b20

you can do

  1. recognize the spike, and reread the value until a reasonable value comes up
do
{
  T = getTemperature();
} while (abs(T-prevT)> 10);
prevT = T;
  1. use a low pass filter
T = 0.85 * T + 0.15 * getTemperature();

The new read value will only count for 15% of the read value. Spikes will be tampered, but the effect is that T smoothes a bit, becomes "slower"in following the real temp

  1. a mix
T = getTemperature();
if (abs(T-prevT) > 10) T = 0.85 * prevT + 0.15 * T;
prevT = T;

hope this helps