War interessant!!!!!
Measure temperature with the TMP36
FunduinoLast updated on
Analogwerte mit map() in Grad Celsius umrechnen
Connect the TMP36
The map command - from measured value to temperature
Read and display temperature
Program code - read and display temperature
int TMP36 = A0; // The sensor is connected to analog pin A0. From now on, we’ll call this pin "TMP36".
int sensorwert;
int temperatur = 0; // The temperature value will later be stored in the variable "temperatur".
int t = 500; // The value of "t" determines the time intervals between individual measurements.
void setup()
{
Serial.begin(9600); // Serial communication starts in setup so that the temperature can be sent to the Serial Monitor. The board sends the measured values to the computer via serial communication. In the Arduino software, start the "Serial Monitor" under "Tools" to see the measured values.
}
void loop()
{
sensorwert = analogRead(TMP36); // Read the sensor value.
temperatur = map(sensorwert, 0, 410, -50, 150); // Convert the sensor value using the "map" command.
delay(t); // A short pause lasting "t" milliseconds follows each measurement.
Serial.print(temperatur); // The value "temperatur" is now sent to the PC via serial communication.
Serial.println(" Degrees Celsius"); // The unit is displayed after the temperature in the Serial Monitor.
}Extension: warning signal for exceeding the temperature limit
Program code - Warning signal when temperature is exceeded
int TMP36 = A0;
int sensorwert;
int temperatur = 0;
int t = 500;
int piezo = 5; // Das Wort "piezo" steht jetzt für die Zahl 5, an Pin 5 wird also der Lautsprecher angeschlossen.
void setup()
{
Serial.begin(9600);
pinMode(piezo, OUTPUT); // Der Pin für den Lautsprecher wird als Ausgang definiert, da zum Piepsen eine Spannung nötig ist.
}
void loop()
{
sensorwert = analogRead(TMP36);
temperatur = map(sensorwert, 0, 410, -50, 150);
delay(t);
Serial.print(temperatur);
Serial.println(" Grad Celsius");
if (temperatur >= 30) // Eine IF-Bedingung: Wenn der Wert für die Temperatur größer oder gleich 30 ist, dann ...
{
digitalWrite(piezo, HIGH); // ... fange an zu piepsen.
}
else // Und wenn das nicht so ist ...
{
digitalWrite(piezo, LOW); // ... dann sei leise.
}
}Rate the instructions