Skip to content

Instantly share code, notes, and snippets.

@michaelsarduino
Created October 25, 2015 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelsarduino/75fdc7af4c6989f4a278 to your computer and use it in GitHub Desktop.
Save michaelsarduino/75fdc7af4c6989f4a278 to your computer and use it in GitHub Desktop.
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;
}
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println( readTemp(), DEC );
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment