mirror of
https://github.com/Eigenbaukombinat/ebk_co2ampel.git
synced 2024-12-28 22:13:08 +01:00
Aktiviere DHT22
This commit is contained in:
parent
38f29d371e
commit
402dbd6ba0
4 changed files with 79 additions and 0 deletions
|
@ -28,3 +28,18 @@
|
|||
// Anzahl der angeschlossenen LEDs am Ring
|
||||
#define NUMPIXELS 8
|
||||
|
||||
// ######## DHT Temperatur Sensor ########
|
||||
|
||||
// Kommentiere enable_DHT aus um das laden zu deaktivieren
|
||||
#define enable_DHT
|
||||
|
||||
// Pins für Temperatursensor DHT22
|
||||
#define DHT_PIN 18
|
||||
// DHT22 Typ
|
||||
#define DHT_TYPE DHT22
|
||||
//#define DHT_TYPE DHT11 // DHT 11
|
||||
//#define DHT_TYPE DHT22 // DHT 22 (AM2302), AM2321
|
||||
//#define DHT_TYPE DHT21 // DHT 21 (AM2301)
|
||||
|
||||
// DHT Sensor Wartezeit zwischen messungen
|
||||
unsigned long sampletime_ms = 10000; // 10 Sekunden
|
50
include/dht_sensor.h
Normal file
50
include/dht_sensor.h
Normal file
|
@ -0,0 +1,50 @@
|
|||
#include "DHT.h"
|
||||
|
||||
#ifndef DHT_PIN
|
||||
#define DHT_PIN 18
|
||||
#endif
|
||||
#ifndef DHT_TYPE
|
||||
#define DHT_TYPE DHT22
|
||||
#endif
|
||||
|
||||
String dht_s_temperature;
|
||||
String dht_s_humidity;
|
||||
String dht_s_hic;
|
||||
|
||||
DHT dht(DHT_PIN, DHT_TYPE);
|
||||
String Float2String(float value)
|
||||
{
|
||||
// Convert a float to String with two decimals.
|
||||
String s;
|
||||
s = String(int(value));
|
||||
s += '.';
|
||||
s += int((value - int(value)) * 100);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
void sensorDHT(){
|
||||
String data;
|
||||
float h = dht.readHumidity();
|
||||
float t = dht.readTemperature();
|
||||
|
||||
// check if Not a Number
|
||||
if (isnan(t) || isnan(h)) {
|
||||
Serial.println("DHT Sensordaten konnten nicht gelesen werden");
|
||||
} else {
|
||||
//false = Celcius | true = Farenheit
|
||||
float hic = dht.computeHeatIndex(t, h, false);
|
||||
dht_s_temperature=Float2String(t);
|
||||
dht_s_humidity=Float2String(h);
|
||||
dht_s_hic=Float2String(hic);
|
||||
Serial.print("Luftfeuchte: ");
|
||||
Serial.print(dht_s_humidity);
|
||||
Serial.print(" %\n");
|
||||
Serial.print("Temperatur: ");
|
||||
Serial.print(dht_s_temperature);
|
||||
Serial.print(" °C\n");
|
||||
Serial.print("Gefühlte Temperatur: ");
|
||||
Serial.print(dht_s_hic);
|
||||
Serial.print(" °C\n");
|
||||
}
|
||||
}
|
|
@ -17,5 +17,7 @@ lib_deps =
|
|||
squix78/ESP8266 and ESP32 OLED driver for SSD1306 displays @^4.2.0
|
||||
yiannisbourkelis/Uptime Library @ ^1.0.0
|
||||
wifwaf/MH-Z19@^1.5.3
|
||||
adafruit/DHT sensor library@^1.4.1
|
||||
adafruit/Adafruit Unified Sensor@^1.1.4
|
||||
monitor_speed = 115200
|
||||
upload_speed = 921600
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
#include <Preferences.h>
|
||||
#include "uptime_formatter.h"
|
||||
|
||||
#ifdef enable_DHT
|
||||
#include "dht_sensor.h"
|
||||
long lastMsg = 0;
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -85,6 +88,10 @@ void setup() {
|
|||
Serial.println("Starte...");
|
||||
Serial.print("CO2-Ampel Firmware: ");Serial.println(ampelversion);
|
||||
|
||||
#ifdef enable_DHT
|
||||
dht.begin();
|
||||
#endif
|
||||
|
||||
// Ab hier Bootmodus initialisieren und festlegen
|
||||
preferences.begin("co2", false);
|
||||
currentBootMode = preferences.getUInt("cal", BOOT_UNKNOWN); // Aktuellen Boot-Mode lesen und speichern
|
||||
|
@ -309,5 +316,10 @@ void loop() {
|
|||
if(currentBootMode == BOOT_NORMAL) { set_led_color(co2); }
|
||||
}
|
||||
}
|
||||
long now = millis();
|
||||
if (now - lastMsg > sampletime_ms) {
|
||||
lastMsg = now;
|
||||
sensorDHT(); // Temperatur, gefühlte Temperatur und Luftfeuchte
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue