commit 76eff37d926acd5603a0b5db030528b3dcfe7040 Author: Stephan Richter Date: Mon Jul 8 15:20:41 2024 +0200 inital commit Signed-off-by: Stephan Richter diff --git a/Taupunkt/Taupunkt.ino b/Taupunkt/Taupunkt.ino new file mode 100644 index 0000000..90fb17d --- /dev/null +++ b/Taupunkt/Taupunkt.ino @@ -0,0 +1,208 @@ +/* + LiquidCrystal Library - Hello World + + Demonstrates the use a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch prints "Hello World!" to the LCD + and shows the time. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * LCD VSS pin to ground + * LCD VCC pin to 5V + * 10K resistor: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + modified 7 Nov 2016 + by Arturo Guadalupi + + This example code is in the public domain. + + http://www.arduino.cc/en/Tutorial/LiquidCrystalHelloWorld + +*/ + +// include the library code: +#include +#include + +int pinDHT22a = A1; +DHT22 dht22a(pinDHT22a); +int status1 = 0; + +int pinDHT22b = A0; +DHT22 dht22b(pinDHT22b); +int status2 = 0; + +const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; +LiquidCrystal lcd(rs, en, d4, d5, d6, d7); + +double sum_diff_temp = 0; +double sum_diff_humi = 0; +float temp1 = 0, temp2 = 0, humi1 = 0, humi2 = 0; +long count = 0; + +byte degree[8] = { + 0b00010, + 0b00101, + 0b00010, + 0b00000, + 0b00000, + 0b00000, + 0b00000, + 0b00000 +}; + +byte tau[8] = { + 0b00000, + 0b00000, + 0b11110, + 0b01000, + 0b01000, + 0b01001, + 0b00110, + 0b00000 +}; + + +void setup() { + // set up the LCD's number of columns and rows: + lcd.begin(16, 4); + lcd.createChar(0, degree); + lcd.createChar(1, tau); + // Print a message to the LCD. + pinMode(6,OUTPUT); + digitalWrite(6,LOW); + + lcd.setCursor(0,0); + lcd.print("Initializing..."); +} + +void relayOff(){ + +} + +void fehler(String tx){ + lcd.setCursor(0,2); + lcd.print(tx); + lcd.print(" failed!"); + relayOff(); +} + +float taupunkt(float t, float r) { + float a, b; + + if (t >= 0) { + a = 7.5; + b = 237.3; + } else if (t < 0) { + a = 7.6; + b = 240.7; + } + + // Sättigungsdampfdruck in hPa + float sdd = 6.1078 * pow(10, (a*t)/(b+t)); + + // Dampfdruck in hPa + float dd = sdd * (r/100); + + // v-Parameter + float v = log10(dd/6.1078); + + // Taupunkttemperatur (°C) + return (b*v) / (a-v); +} + +void loop() { + delay(2500); + temp1 = dht22a.getTemperature(); + humi1 = dht22a.getHumidity(); + status1 = dht22a.getLastError(); + temp2 = dht22b.getTemperature(); + humi2 = dht22b.getHumidity(); + status2 = dht22b.getLastError(); + + lcd.setCursor(0, 0); + if (status1 != dht22a.OK || isnan(temp1)||isnan(humi1)) { + lcd.print("Sensor 1"); + lcd.setCursor(0,1); + lcd.print("Error: "); + lcd.print(status1); + temp1 = 0; + } else { + lcd.print(temp1); + lcd.write((int)0); + lcd.print("C "); + lcd.setCursor(0,1); + lcd.print(humi1); + lcd.print(" % "); + } + + lcd.setCursor(9, 0); + if (status2 != dht22b.OK) { + lcd.setCursor(8, 0); + lcd.print("Sensor 2"); + lcd.setCursor(8,1); + lcd.print(status2); + temp2 = 0; + } else { + lcd.setCursor(9, 0); + lcd.print(temp2); + lcd.write((int)0); + lcd.print("C"); + lcd.setCursor(9,1); + lcd.print(humi2); + lcd.print(" %"); + } + + if (humi1<0 || humi1>100){ + fehler("Humi 1"); + return; + } + if (temp1<-40 || temp1>80){ + fehler("Temp 1"); + return; + } + if (humi2<0 || humi2>100){ + fehler("Humi 2"); + return; + } + if (temp2<-40 || temp2>80){ + fehler("Temp 2"); + return; + } + if (status1 == dht22a.OK && status2 == dht22b.OK){ + float tau1 = taupunkt(temp1,humi1); + float tau2 = taupunkt(temp2,humi2); + lcd.setCursor(0,2); + lcd.write((int)1); + lcd.print("1: "); + lcd.print(tau1); + lcd.setCursor(0,3); + lcd.write((int)1); + lcd.print("2: "); + lcd.print(tau2); + } + + + + +}