There are a few AVR microcontrollers with onboard temperature sensors. These temperature sensors are neither accurate nor precise, but they do work for a few use cases. [Thomas] came up with a little bit of code that runs on all AVR microcontrollers, and is at least as accurate as the sensors in the rare AVRs that have them.
Although not all AVRs have a temperature sensor, they do all have RC oscillators, and these RC oscillators are temperature sensitive. By combining the RC oscillator and watchdog timer, [Thomas]’ code can get a vague idea if it’s getting hotter or colder.
To prove his code works, [Thomas] took an ATtiny13A chip loaded up with a few bits of code and placed a heated coin on it. The chip was programmed to turn on an LED when it detected a rise in temperature, and predictably, the LED lit up. With a coin chilled in a bowl of ice water, another bit of code ran, flashing the LED.
While we’re sure it’s neither accurate nor precise, it does have its uses – overheating protection or a simple thermostat. You can check out a video of the code in action below.
It’s probably also sensitive to voltage.
They definitely are sensitive to the power supply as I was playing with a half-completed IoT project.
Taking a running average definitely cut down on some of the completely wild fluctuations I was seeing over a few seconds of time.
When powered via a powered usb hub, every 30 minutes the readings would dip about 15F for about a 5 minute period before coming back up. Then I moved it to a USB wall charger and everything consistently read 40 degrees cooler but without the intermittent dip.
To avoid this you can tie AREF to the 5v, so that when drops also the reference drops.
It’s not using the ADC, but the timing of the RC oscillator.
Wasn’t the same thing posted over a year ago?
Then stop reading hackaday. Find a blog that never ever repeats things ever. Go find one.
This is most common answer to any criticism. It’s already quite lame counter-attack nowadays..
Not the first “then go away” reply and not the first double-post here. I wish the writers could find the search button before writing a new post. Atleast mention “this has been posted here before but because .. (choose:) I cannot find search button I will post this again OR because we’re lacking good posts we post this again.. hey: it’s new project to someone!”
you should go and complain on instructables for people “reinventing the wheel” lol
Legit question, Has the project been updated since then?
how much is left for your own code?
“in the rare AVRs that have them” Rare, huh? There are 263 atmel microcontrollers with internal temperature sensors and 222 without.
Respect for checking this out. Still, probably the original claim will stay as “fact” (nobody edit’s the post). And so the story continues.. Sad.
Atmega328 has a temp sensor inside?
It does not. It does have peripheral support through the ADC though. I think this may be what [David] is talking about.
Incorrect.
It has a built in Temperature Sensor that is accessed as ADC8.
See section 24.8 of the datasheet here: http://www.atmel.com/images/Atmel-8271-8-bit-AVR-Microcontroller-ATmega48A-48PA-88A-88PA-168A-168PA-328-328P_datasheet_Complete.pdf
David (OP) was talking about all the AVR devices, not just the A328.
In reference to the entire AVR line: “Advanced on-chip analog capabilities include an internal temperature sensor” from http://www.atmel.com/simply-avr/
The register settings vary significantly so I wrote a bit of code that does the right ADC settings.
http://nerdralph.blogspot.ca/2014/08/writing-library-for-internal.html