Die TMP35/TMP36/TMP37 sind Niedervolt-, Präzisions-Celsius-Temperatursensoren. Sie liefern einen Spannungsausgang, der linear proportional zur Celsius-Temperatur ist. Der TMP35/TMP36/TMP37 erfordert keine externe Kalibrierung, um typische Genauigkeiten von ±1°C bei +25°C und ±2°C über den Temperaturbereich von -40°C bis +125°C zu liefern.
#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;
}
zurück