Arduino + Raspberry Pi Lovers
Discussion and Q&A about Arduino and Raspberry Pi projects.
186 Members
Join this group to post and comment.
Kunal Gokhe
Kunal Gokhe
29 Jan 2019

Arduino Internal Temperature Sensor

Most new AVR chips have an internal temperature sensor. It is not often used, since it is not accurate. There are however a number of situations that this sensor can be used. The internal temperature is the temperature inside the chip, just like the cpu-temperature of a computer. If the Arduino is not sleeping, this temperature will increase. If output pins are used to drive current (for example to drive a led) the internal temperature increases more. This internal temperature can not be used to read the ambient temperature. The ambient temperature could be measured if the Arduino turns on, but only if the Arduino was off for more than 10 minutes.

void setup() 
  Serial.println(F("Internal Temperature Sensor")); 
 void loop() 
  // Show the temperature in degrees Celsius.  

double GetTemp(void) 
  unsigned int wADC;  double t;
  ADMUX = (_BV(REFS1) | _BV(REFS0) | _BV(MUX3));  
  delay(20);            // wait for voltages to become stable.     
  ADCSRA |= _BV(ADSC);  // Start the ADC
  while (bit_is_set(ADCSRA,ADSC));
  // Reading register "ADCW" takes care of how to read ADCL and ADCH.  
  wADC = ADCW;   
  // The offset of 324.31 could be wrong. It is just an indication.  
  t = (wADC - 324.31 ) / 1.22;   
  // The returned temperature is in degrees Celsius.  
  return (t); 

Try this code on your Arduino Board.

AVR chips that have an internal temperature sensor:

  • ATmega8 : No
  • ATmega8L : No
  • ATmega8A : No
  • ATmega168 : No
  • ATmega168A : Yes
  • ATmega168P : Yes
  • ATmega328 : Yes
  • ATmega328P : Yes
  • ATmega1280 (Arduino Mega) : No
  • ATmega2560 (Arduino Mega 2560) : No
  • ATmega32U4 (Arduino Leonardo) : Yes