I recently stumbled across an interesting fact in the datasheet for the ATMEGA32u4, the microcontroller I am using for my Einstepper Project. I was surprised to find that Atmel had included a temperature sensor in the core of the device that you can read using the internal ADC. As it turns out, there are many mega AVR devices contain an internal temperature sensor. According to Atmel’s product finder, these devices are:
I was interested to see 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. The Arduino Leonardo and Arduino Pro Micro use the ATMEGA32u4 so all the code below should work without modification. For other AVR boards that use a different chipset, minor modifications to the registers will be necessary.
I am using one of the boards from my Einstepper Project, but any board with one of the supported chips should work. There may be varying thermal characteristics between different packages (TQFP vs. QFN) as well as different chips. These results are specifically for the ATMEGA32u4 in the TQFP package.
The first step was to setup the ADC to be able to read the internal temperature sensor. In order to use the temperature sensor correctly, you must set the ADC reference to the 2.56V internal reference, set the multiplexer to the temperature sensor, and enable the ADC. The code I used to configure the ATMEGA32u4′s temperature sensor is as follows. This is specifically for the ATMEGA32u4 so if you are using a different chip, you should check the datasheet for the correct register values.
Read More: ATMEGA Core Temperature Sensor