void setup()
{
Serial.begin(9600);
//Serial.println(F("Internal Temperature Sensor"));
}
void loop()
{
// Show the temperature in degrees Celsius.
Serial.println(GetTemp(),1);
delay(1000);
}
double GetTemp(void)
{
unsigned int wADC;
double t;
//https://playground.arduino.cc/Main/InternalTemperatureSensor/
// 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.
byte _bit0 = 0b0;
byte _bit1 = _BV(_bit0);
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;
// The returned temperature is in degrees Celsius.
return (t);
}