42 lines
850 B
Arduino
42 lines
850 B
Arduino
|
/*
|
||
|
DS18B20 Basic Code
|
||
|
Temperatur auslesen mit einem DS18B20 Temperaturfühlers
|
||
|
Created by cooper.bin, 2020
|
||
|
https://makesmart.net/
|
||
|
*/
|
||
|
|
||
|
#include <OneWire.h>
|
||
|
#include <DallasTemperature.h>
|
||
|
|
||
|
// Der PIN D4 wird als Daten-Pin verwendet
|
||
|
#define ONE_WIRE_BUS 2
|
||
|
|
||
|
OneWire oneWire( ONE_WIRE_BUS );
|
||
|
DallasTemperature DS18B20( &oneWire );
|
||
|
|
||
|
// In dieser Variable wird die Temperatur gespeichert
|
||
|
float temperature;
|
||
|
|
||
|
|
||
|
void setup(){
|
||
|
// Seriellen Monitor initialisieren
|
||
|
Serial.begin(115200);
|
||
|
|
||
|
// DS18B20 initialisieren
|
||
|
DS18B20.begin();
|
||
|
}
|
||
|
|
||
|
void loop(){
|
||
|
|
||
|
// Temperatur auslesen
|
||
|
DS18B20.requestTemperatures( );
|
||
|
// Temperatur in einer Variable speichern
|
||
|
temperature = DS18B20.getTempCByIndex( 0 );
|
||
|
|
||
|
// Die Ausgabe über den seriellen Monitor
|
||
|
Serial.println( String( temperature ) + " °C");
|
||
|
|
||
|
// 5 Sekunden Pause
|
||
|
delay( 5000 );
|
||
|
|
||
|
}
|