Author Topic: readout internal temperature sensor  (Read 10152 times)


  • Sr. Member
  • ****
  • Posts: 398
readout internal temperature sensor
« on: February 05, 2014, 09:04:35 am »
While reading the SAM3X8E documentation, I figured out, that there is a built in temperature sensor on ADC15.  See chapter 46.8.
Unfortunately this analog port has no pin-definition, which would allow analogRead(TEMPSENSOR).  Furthermore the temperature sensor is not enabled by default, however adc.c contains an enable function.

So created an adapted analogRead() function, which returns the temperature.

Code: [Select]
// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:

float readTemperature()
  uint32_t ulValue = 0;
  float currTemp = 0.0;
  adc_enable_channel( ADC, adc_channel_num_t(15) );
  adc_start( ADC );
  while ((adc_get_status(ADC) & ADC_ISR_DRDY) != ADC_ISR_DRDY) ;
  ulValue = adc_get_latest_value(ADC);
  // (ulValue * 3.3 V / 4096 steps resolution / 0.00265 V/°C) - ( 0.8 / 0.00265 V/°C - 27°C)
  // see  Table 46-37 in Atmel Doc 11057B SAM3X/A
  currTemp = (0.304025390625*ulValue)-274,89;
  return currTemp;

// the loop routine runs over and over again forever:
void loop() {
  float sensorValue = readTemperature();
  // print out the value you read:
  delay(1500);        // delay in between reads for stability

For the calculation see the documentation:
  • 27°C is equal to 0.8 V
  • 3.3 V are measured with 12bit resolution, so 1 step equals 3.3V/4096
  • slope voltage versus temperature is 0.00265 V/°C
  • the calculation/documentation is based on °C and not °F!

The sensor can't be used to measure environmental temperature, as the CPU produces to much own heat.
However with some calibration it may be sufficient for some projects.

In my tests the temperature was between 1°C and 3°C higher, than the temperature measured on the top of the chip. Stressing the chip, I measured temperatures from 27°C to 78°C.


  • Sr. Member
  • ****
  • Posts: 289
Re: readout internal temperature sensor
« Reply #1 on: February 05, 2014, 10:01:49 am »
Nice find! We should probably put this and the info about the ATTiny85 temperature sensor for the DigiSpark on the wiki...