Atmega328 internal temperature sensor (yes it exists!)

I few days ago I learned something new about the atmega328: it has an internal temperature sensor.

The specs are awful: +-10 degrees C! This is uncompensated though.

Also, the internal temperature sensor will (of course) read a higher temperature when the mcu is running. But many MySensors nodes sleep almost all the time, and will not generate heat because if it did it would drain the battery pretty quickly.

I added the (linear) compensation to bring it back to 23 and let it log data for almost 40 hours. This was the result:

The difference:

After adjusting the compensation (not sure why the original compensation was so off):

Difference:

So for normal indoor temperatures, it seems like the internal temperature sensor can be quite OK, as long as it is compensated. I think I'll add this temperature reading to my plant monitor nodes. It is free, and it probably has the same level of accuracy as the DHT22.

It would be interesting to see the difference over a larger temperature span, but that will have to wait for another day.

@nca78 if a single calibration at room temperature is enough, I’d say it is. Quick and simple. But if i need to put the node in the freezer to get a second calibration point, it would take too much time.

My guess is that one calibration point is insufficient, since my tests show increased drifting both at ~24C (-0.4C) and ~21.5C (+0.3C). So as soon as we get away from the 23C calibration point the accuracy becomes bad.

It would be an interesting experiment to gather data at every point over a wide temperature range. That chip would then be perfectly calibrated. The question would then be: how well do other chips follow the same curve? Maybe they follow it reasonably closely. Or, maybe they don't. I suppose it depends on manufacturing tolerances.

Interesting to know that atmega328 has a temperature sensor!
I'm thinking the calibration doesn't need to be completely manual and shouldn't be requiring us to flash the µC again just to recalibrate. we could connect an I2C sensor just during calibration and disconnect it after calibration is done. the firmware could get data from both internal and external sensors and store the calibration data in eeprom. This data can then be read back to measure properly using internal sensor after deploying.
It is even possible to remove the need to flash the µC after the calibration, if the calibration logic is part of the production firmware itself.

While browsing the MySensors source code, I stumbled on this code that shows that support for the internal temperature sensor is already included in the MySensors library, including offset and gain calibration.