Friday, January 22, 2016

Checking Internal temperature on my Arduino Uno Processor.

Came across this good article to measure the temperature on the Arduino Uno.

http://www.theorycircuit.com/arduino-internal-temperature-sensor/

https://www.arduino.cc/en/Main/ArduinoBoardUno- reports teh chipset is ATmega328P.


First check that the Arduino IDE has the Serial Monitor in the interface.



Next,
Copy this code into Arduino IDE and open the Serial Monitor ,Verify and Upload and open the serial monitor -
You should see these messages indicating the internal temperature of the Micro Controller.




// Internal Temperature Sensor
// Example sketch for ATmega328 types.


voidsetup()
{
 
Serial.begin(9600);

 
Serial.println(F("Internal Temperature Sensor"));
}

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

doubleGetTemp(void)
{
 
unsignedintwADC;
 
doublet;

 
// 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;

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


No comments:

Post a Comment