The TMP35/TMP36/TMP37 are low-voltage, precision Celsius temperature sensors. They provide a voltage output that is linear and proportional to the Celsius temperature. The TMP35/TMP36/TMP37 does not require external calibration to achieve typical accuracies of ±1°C at +25°C and ±2°C over the temperature range from -40°C to +125°C.
TMP36-Pin | Function | Arduino Uno |
---|---|---|
1 | VCC (+2.7V to +5.5V) | 3.3V or 5V |
2 | Signal | A0 (or other analog Pin) |
3 | GND (Ground) | GND |
#define TMP36_PIN A0
#define AREF_VOLTAGE 5.0 // depends if we´re using 3.3V or 5.0V for operating the TMP36
void setup() {
Serial.begin(9600);
}
void loop() {
unsigned int sensorValue;
float voltage, degreesCelsius;
sensorValue = analogRead(TMP36_PIN);
voltage = getVoltage(sensorValue);
degreesCelsius = getTemperature(voltage);
Serial.print("SensorValue: ");
Serial.print(sensorValue);
Serial.print("; Voltage: ");
Serial.print(voltage);
Serial.print("V; Temperature: ");
Serial.print(degreesCelsius);
Serial.println("°C");
delay(1000);
}
/**
* Converts the 0 to 1023 value from analogRead() into a 0.0 to 5.0
* value that is the true voltage being read at that pin.
*/
float getVoltage(int sensorValue) {
return (sensorValue * AREF_VOLTAGE / 1024);
}
/**
* Converting the voltage to degrees Celsius.
* The formula comes from the datasheet of the TMP36
*/
float getTemperature(float voltage) {
return (voltage - 0.5) * 100.0;
}