Gauging ambient temps with Atmel’s ATmega32u4

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.

tempcodeatmelmcu

“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:

  • AT90PWM161
  • AT90PWM81
  • ATmega168A
  • ATmega168P
  • ATmega168PA
  • ATmega16M1
  • ATmega16U4
  • ATmega328
  • ATmega328P
  • ATmega32M1
  • ATmega32U4
  • ATmega48A
  • ATmega48P
  • ATmega48PA
  • ATmega64M1
  • ATmega88A
  • ATmega88P
  • ATmega88PA

Interested in learning more? You can check out Connor’s blog post here and Atmel’s extensive megaAVR portfolio here.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s