The TMP36 temperature sensor is an easy to use temperature sensor. With a few lines of code you can measure the temperature with reasonable accuracy.
int sensorPin = A0;
float celsius;
float kelvin;
float fahrenheit;
void getTemperature()
{
float val = analogRead(sensorPin);
// analogRead returns a 0 to 5 volts measure on a scale from 0 to 1023,
// i.e. 2*10 bits or 1024 units
val = (val * 5.0) / 1024;
// convert Volts to milliVolts
// the TMP36's linear scale is 10 mV / degree Celsius
// i.e. (* 1000 / 10) = * 100
val = (val) * 100;
celsius = val;
kelvin = val + 273.15;
fahrenheit = ((val * 9)/5.0) + 32;
}
Arduino: TMP36 temperature sensor
Leave a reply