-
-
Save haeshh/ce64261930eec7c3a58b85dba112844d to your computer and use it in GitHub Desktop.
Beispielcode zur Abfrage des SHT20-Sensors für Temperatur und Luftfeuchtigkeit (ESP32, Arduino)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Messung von Sensorwerten: SHT20 | |
* (Temperatur und rel. Luftfeuchtigkeit) | |
* | |
* 2020-11-24 Heiko (unsinnsbasis.de) | |
*/ | |
// Bibliothek für den SHT20-Sensor | |
#include <uFire_SHT20.h> | |
uFire_SHT20 sht20; // Datenstruktur für den Sensor | |
// Bitrate für die Datenübertragung zum seriellen Monitor | |
// (ESP: z.B. 115200, Arduino: zwingend 9600) | |
#define BITRATE 115200 // Arduino: 9600 | |
float temp, hum; // Variablen für Temperatur und Luftfeuchtigkeit | |
void setup() { | |
// Übertragungsrate zum seriellen Monitor setzen | |
Serial.begin(BITRATE); | |
Wire.begin(); | |
sht20.begin(); // Sensor initialisieren | |
} | |
void loop() { | |
temp = sht20.temperature(); | |
hum = sht20.humidity(); | |
// taupunkt = sht20.dew_pointC(); | |
// saettigung = sht20.vpd(); | |
Serial.print("Temperatur: "); | |
Serial.print(temp,1); | |
Serial.println(" °C"); | |
Serial.print("rel. Luftfeuchtigkeit: "); | |
Serial.print(hum,1); | |
Serial.println(" %"); | |
delay(5000); // vor der nächsten Messung etwas warten | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Messung von Sensorwerten: SHT20 | |
* (Temperatur und rel. Luftfeuchtigkeit) | |
* | |
* Einsatz der SHT20-Bibliothek von DFRobot | |
* https://github.com/DFRobot/DFRobot_SHT20 | |
* (funktioniert anders als uFire SHT20 auch mit | |
* dem ESP8266) | |
* | |
* 2021-03-24 Heiko (unsinnsbasis.de) | |
*/ | |
// Bibliotheken für I2C und den SHT20-Sensor | |
#include <Wire.h> | |
#include "DFRobot_SHT20.h" | |
DFRobot_SHT20 sht20; // Datenstruktur für den Sensor | |
// Bitrate für die Datenübertragung zum seriellen Monitor | |
// (ESP: z.B. 115200, Arduino: zwingend 9600) | |
#define BITRATE 115200 // Arduino: 9600 | |
float temp, hum; // Variablen für Temperatur und Luftfeuchtigkeit | |
void setup() { | |
// Übertragungsrate zum seriellen Monitor setzen | |
Serial.begin(BITRATE); | |
Wire.begin(); | |
sht20.initSHT20(); // Sensor initialisieren | |
delay(100); | |
sht20.checkSHT20(); | |
} | |
void loop() { | |
temp = sht20.readTemperature(); | |
hum = sht20.readHumidity(); | |
Serial.print("Temperatur: "); | |
Serial.print(temp,1); | |
Serial.println(" °C"); | |
Serial.print("rel. Luftfeuchtigkeit: "); | |
Serial.print(hum,1); | |
Serial.println(" %"); | |
delay(5000); // vor der nächsten Messung etwas warten | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment