You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

231 lines
4.0 KiB

// include the library code:
#include <LiquidCrystal.h>
#include <DHT22.h>
int pinDHT22a = 7;
DHT22 dht22a(pinDHT22a);
int status1 = 0;
int pinDHT22b = 6;
DHT22 dht22b(pinDHT22b);
int status2 = 0;
const int rs = 13, en = 12, d4 = 11, d5 = 10, d6 = 9, d7 = 8;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
float temp1 = 0, temp2 = 0, humi1 = 0, humi2 = 0;
float treshold = 2;
float hyster = 1;
float min_temp = 5;
int relay = 5;
byte degree[8] = {
0b00010,
0b00101,
0b00010,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000
};
byte tau[8] = {
0b00000,
0b00000,
0b11110,
0b01000,
0b01000,
0b01001,
0b00110,
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);
lcd.createChar(2, on);
lcd.createChar(3, off);
pinMode(relay,OUTPUT);
pinMode(4,OUTPUT);
digitalWrite(4,LOW);
lcd.setCursor(0,0);
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(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();
}
float taupunkt(float t, float r) {
float a, b;
if (t >= 0) {
a = 7.5;
b = 237.3;
} else {
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();
boolean err1 = false;
boolean err2 = false;
if (status1 != dht22a.OK || isnan(temp1)||isnan(humi1)) {
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);
}
}
if (status2 != dht22b.OK) {
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);
}
}
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();
}
}
}