ATmega Internal Temperature Sensor

Hi all. here my projects for reading internal ATmega core temperature sensor. it’s good for measuring the arduino temperature not for measuring air temperature.

for this projecs I’m using arduino UNO. temperature widget is on V1

supported chip:

ATmega168A
ATmega168P
ATmega328
ATmega328P
ATmega32U4 (Arduino Leonardo)

The sketch:

#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <SimpleTimer.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "b6ae5b065c0f461fb679e4fca7c8bd03";
char server[] = "10.5.51.5";

SimpleTimer timer;

void setup()
{
  Blynk.begin(auth, server, 8080);
  Serial.begin(9600);
  Serial.println(F("Internal Temperature Sensor"));
  timer.setInterval(2000L, atmega);
}

void atmega()
{
  // Show the temperature in degrees Celcius.
  Serial.println(GetTemp(), 1);
  delay(1000);
}

double GetTemp(void)
{
  unsigned int wADC;
  double t;

  // The internal temperature has to be used
  // with the internal reference of 1.1V.
  // Channel 8 can not be selected with
  // the analogRead function yet.

  // Set the internal reference and mux.
  ADMUX = (_BV(REFS1) | _BV(REFS0) | _BV(MUX3));
  ADCSRA |= _BV(ADEN);  // enable the ADC

  delay(20);            // wait for voltages to become stable.

  ADCSRA |= _BV(ADSC);  // Start the ADC

  // Detect end-of-conversion
  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;
  Blynk.virtualWrite(V1, t);

  // The returned temperature is in degrees Celcius.
  return (t);
}

void loop()
{
  Blynk.run();
  timer.run();
}

Screenshot:

good luck :wink:

1 Like