diff --git a/Taupunkt/Taupunkt.ino b/Taupunkt/Taupunkt.ino index 90fb17d..7ad9117 100644 --- a/Taupunkt/Taupunkt.ino +++ b/Taupunkt/Taupunkt.ino @@ -44,21 +44,22 @@ #include #include -int pinDHT22a = A1; +int pinDHT22a = 8; DHT22 dht22a(pinDHT22a); int status1 = 0; -int pinDHT22b = A0; +int pinDHT22b = 9; 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; +float treshold = 5.0; +float hyster = 1.0; +float min_temp = 5; + +int relay = 7; byte degree[8] = { 0b00010, @@ -82,28 +83,82 @@ byte tau[8] = { 0b00000 }; +byte on[8] = { + 0b11111, + 0b10001, + 0b11111, + 0b11111, + 0b11111, + 0b11111, + 0b10001, + 0b11111 +}; + +byte off[8] = { + 0b11111, + 0b10001, + 0b10001, + 0b10001, + 0b10001, + 0b10001, + 0b10001, + 0b11111 +}; + 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.createChar(2, on); + lcd.createChar(3, off); + pinMode(relay,OUTPUT); lcd.setCursor(0,0); - lcd.print("Initializing..."); + lcd.print(" IN OUT"); + + lcd.setCursor(0,1); + lcd.print("Temp . . "); + lcd.write((int)0); + lcd.print("C"); + + lcd.setCursor(0,2); + lcd.print("Humi . . %"); + + lcd.setCursor(0,3); + lcd.print(" "); + lcd.write((int)1); + lcd.print(" . . "); + lcd.write((int)0); + lcd.print("C"); +} + +void printVal(float v){ + if (v<10) lcd.print(" "); + lcd.print(v,1); } void relayOff(){ - + lcd.setCursor(0,0); + lcd.print("OFF"); + digitalWrite(relay,LOW); +} + +void relayOn(){ + lcd.setCursor(0,0); + lcd.print("ON "); + digitalWrite(relay,HIGH); } -void fehler(String tx){ - lcd.setCursor(0,2); - lcd.print(tx); - lcd.print(" failed!"); +void fehler(int col, int code){ + lcd.setCursor(col,1); + lcd.print("Err "); + lcd.setCursor(col,2); + lcd.print(" "); + lcd.print(code); + lcd.print(" "); + lcd.setCursor(col,3); + lcd.print("--- "); relayOff(); } @@ -140,69 +195,77 @@ void loop() { humi2 = dht22b.getHumidity(); status2 = dht22b.getLastError(); - lcd.setCursor(0, 0); + boolean err1 = false; + boolean err2 = false; 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(" % "); + fehler(5,status1); + err1 = true; + } else { + if (temp1<-40 || temp1>80){ + lcd.setCursor(5,1); + lcd.print("oor!"); + err1 = true; + } else { + lcd.setCursor(5,1); + printVal(temp1); + } + if (humi1<0 || humi1>100){ + lcd.setCursor(5,2); + lcd.print("oor!"); + err1 = true; + } else { + lcd.setCursor(5,2); + printVal(humi1); + } } - - 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(" %"); + fehler(10,status2); + err2 = true; + } else { + if (temp2<-40 || temp2>80){ + lcd.setCursor(10,1); + lcd.print("oor!"); + err2 = true; + } else { + lcd.setCursor(10,1); + printVal(temp2); + } + if (humi2<0 || humi2>100){ + lcd.setCursor(10,2); + lcd.print("oor!"); + err2 = true; + } else { + lcd.setCursor(10,2); + printVal(humi2); + } } - 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); + lcd.setCursor(5,3); + float tau1, tau2; + if (err1){ + lcd.print("----"); + } else { + tau1 = taupunkt(temp1,humi1); + printVal(tau1); } - + lcd.setCursor(10,3); + if (err2){ + lcd.print("----"); + } else { + tau2 = taupunkt(temp2,humi2); + printVal(tau2); + } - + if (err1 || err2){ + relayOff(); + } else { + if (tau1 > tau2 + treshold + hyster) { + relayOn(); + } + if (tau1 < tau2 + treshold) { + relayOff(); + } + } }