Temperature spikes and drops with ds18b20

Those errors wouldn't get through if you were checking the CRC (*).
You need to fix the code so that if the CRC fails, you read the temperature again. And, just in case, put a limit of, say, 3 consecutive CRC errors in which case return the temperature as zero and give up this time through.

  if(OneWire::crc8(data, 9)) {
    // CRC failed. Handle the error
  }
  // CRC is OK.

Pete

  • assuming that the error is from the sensor. If the error occurs elsewhere, the CRC check won't help. But it won't hurt and it should be there anyway.