Connor of the Narkidae blog recently put together an easy to read tutorial about using the integrated temperature sensor found on Atmel’s ATmega32u4 microcontroller (MCU) in the TQFP package to measure the ambient temperature.
“I was interested [in] seeing what temperature the microcontroller idled at and if this sensor could be used to detect the temperature of the room. By using a known temperature differential between the ambient air and core, it should be possible to calculate the ambient temperature,” Connor wrote in a recent blog post.
“The Arduino Leonardo and Arduino Micro use the ATmega32u4 so all the code should work without modification. For other AVR boards that use a different chipset, minor modifications to the registers will be necessary.”
On the software side, Connor configured the ADC to read the internal temperature sensor by setting it to 2.56V (internal reference), setting the multiplexer to the temperature sensor and enabling the ADC.
“To calibrate the temperature, I held an ice cube against the ATmega32u4 (in a plastic bag so the board doesn’t get wet) until the temperature reading stabilized around 7C,” Connor explained. ”Because water has an enthalpy of fusion of 0C (by definition of Celcius), the ice should be exactly 0C. Assuming there is sufficient thermal conduction, the core should be very close to 0C too. From this we know that the core temperature sensor reads 7C too high so I added an offset variable to the calculation.”
Starting at 20C (room temperature), the microcontroller immediately starts heating rapidly until it reaches thermal equilibrium at approximately 24C within one minute. Meaning, the ATmega32u4 idles around 4C above ambient temperature.
“With this information we can measure ambient temperature by subtracting 4 from the temperature measurement after the chip has come to thermal equilibrium,” he added.
It should be noted that a number of Atmel micro controllers feature integrated temperature sensors, including: