/*
 Reads the temperature on an Arduino with an Atmega328 or later (Duemilanove, Uno, etc)

Based on an example by Peter Knight, at

http://code.google.com/p/tinkerit/wiki/SecretThermometer

 */


void setup() {
  Serial.begin(9600);
}

void loop() {
  float temperature = readTemp() / 10000.0;
  Serial.println( temperature );
  delay(1000);
}

long readTemp() {
  long result;
  // Read temperature sensor against 1.1V reference
  ADMUX = _BV(REFS1) | _BV(REFS0) | _BV(MUX3);
  delay(2); // Wait for Vref to settle
  ADCSRA |= _BV(ADSC); // Convert
  while (bit_is_set(ADCSRA,ADSC));
  result = ADCL;
  result |= ADCH<<8;
  result = (result - 125) * 1075;
  return result;
}