I'm trying to read temperature data in Celsius and Fahrenheit by using Teensy's 2.0 on chip temperature sensor. I know that since i'm trying to use the on chip temperature sensor, I have to work with ADMUX and MUX to get the voltage value then convert them to Celsius and Fahrenheit but i'm not sure what to do regarding the ADMUX and MUX.
Code:
int sensorPin = 0; //the analog pin is connected to
//the resolution is 10 mV / degree centigrade with a
//500 mV offset to allow for negative temperatures
/*
* setup() - this function runs once when you turn your Arduino on
* We initialize the serial connection with the computer
*/
void setup()
{
Serial.begin(9600); //Start the serial connection with the computer
//to view the result open the serial monitor
}
void loop() // run over and over again
{
// gets voltage reading from the temperature sensor at analog in 0
int reading = analogRead(sensorPin);
// converts reading to voltage, for 3.3v arduino use 3.3
float voltage = reading * 5.0;
voltage /= 1024.0;
// Print sensor 1
Serial.println("Temperature Sensor 1");
// Print out the voltage
Serial.print(voltage);
Serial.println(" volts");
// converts voltage reading to temperature in degree Celsius
float temperatureC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offset
//to degrees ((voltage - 500mV) times 100)
// Prints out temperature with unit Celcius
Serial.print(temperatureC);
Serial.println(" degrees C");
// converts Celcius to Fahrenheit
float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
// Prints out temperature with unit Fahrenheit
Serial.print(temperatureF);
Serial.println(" degrees F");
// Converts Celcius to Kelvin
float temperatureK = temperatureC + 273;
// Prints out temperature with unit Kelvin
Serial.print(temperatureK);
Serial.println(" degrees K");
delay(1000); //waiting a second
}