#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "DHT.h"
#define DHTPIN 4
#define DHTTYPE DHT11
#define SCREEN_WIDTH 128 // OLED Breite in Pixel
#define SCREEN_HEIGHT 64 // OLED Höhe in Pixels
DHT dht(DHTPIN, DHTTYPE);
Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
void setup() {
Serial.begin(9600);
dht.begin();
if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("problem das SSD1306 OLED zu starten"));
while (1);
}
oled.setTextSize(1);
oled.setTextColor(WHITE);
oled.setCursor(0, 0);
oled.clearDisplay();
oled.display();
delay(2000);
}
void loop() {
delay(2000);
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println("Kein Signal von Sensor!");
oled.setCursor(0, 0);
oled.clearDisplay();
oled.println("Error");
oled.display();
return;
}
float hic = dht.computeHeatIndex(t, h, false);
oled.clearDisplay();
oled.setCursor(0, 0);
oled.println("Luftfeuchtigkeit: ");
oled.println(h);
oled.println("% Temperatur : ");
oled.println(t);
oled.println("°C ");
oled.display();
}