Browse Source

first working version

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
main
Stephan Richter 5 months ago
parent
commit
3340a2f7ce
  1. 209
      Taupunkt/Taupunkt.ino

209
Taupunkt/Taupunkt.ino

@ -44,21 +44,22 @@
#include <LiquidCrystal.h> #include <LiquidCrystal.h>
#include <DHT22.h> #include <DHT22.h>
int pinDHT22a = A1; int pinDHT22a = 8;
DHT22 dht22a(pinDHT22a); DHT22 dht22a(pinDHT22a);
int status1 = 0; int status1 = 0;
int pinDHT22b = A0; int pinDHT22b = 9;
DHT22 dht22b(pinDHT22b); DHT22 dht22b(pinDHT22b);
int status2 = 0; int status2 = 0;
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7); 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; 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] = { byte degree[8] = {
0b00010, 0b00010,
@ -82,28 +83,82 @@ byte tau[8] = {
0b00000 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() { void setup() {
// set up the LCD's number of columns and rows: // set up the LCD's number of columns and rows:
lcd.begin(16, 4); lcd.begin(16, 4);
lcd.createChar(0, degree); lcd.createChar(0, degree);
lcd.createChar(1, tau); lcd.createChar(1, tau);
// Print a message to the LCD. lcd.createChar(2, on);
pinMode(6,OUTPUT); lcd.createChar(3, off);
digitalWrite(6,LOW); pinMode(relay,OUTPUT);
lcd.setCursor(0,0); 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(){ 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){ void fehler(int col, int code){
lcd.setCursor(0,2); lcd.setCursor(col,1);
lcd.print(tx); lcd.print("Err ");
lcd.print(" failed!"); lcd.setCursor(col,2);
lcd.print(" ");
lcd.print(code);
lcd.print(" ");
lcd.setCursor(col,3);
lcd.print("--- ");
relayOff(); relayOff();
} }
@ -140,69 +195,77 @@ void loop() {
humi2 = dht22b.getHumidity(); humi2 = dht22b.getHumidity();
status2 = dht22b.getLastError(); status2 = dht22b.getLastError();
lcd.setCursor(0, 0); boolean err1 = false;
boolean err2 = false;
if (status1 != dht22a.OK || isnan(temp1)||isnan(humi1)) { if (status1 != dht22a.OK || isnan(temp1)||isnan(humi1)) {
lcd.print("Sensor 1"); fehler(5,status1);
lcd.setCursor(0,1); err1 = true;
lcd.print("Error: "); } else {
lcd.print(status1); if (temp1<-40 || temp1>80){
temp1 = 0; lcd.setCursor(5,1);
} else { lcd.print("oor!");
lcd.print(temp1); err1 = true;
lcd.write((int)0); } else {
lcd.print("C "); lcd.setCursor(5,1);
lcd.setCursor(0,1); printVal(temp1);
lcd.print(humi1); }
lcd.print(" % "); 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) { if (status2 != dht22b.OK) {
lcd.setCursor(8, 0); fehler(10,status2);
lcd.print("Sensor 2"); err2 = true;
lcd.setCursor(8,1); } else {
lcd.print(status2); if (temp2<-40 || temp2>80){
temp2 = 0; lcd.setCursor(10,1);
} else { lcd.print("oor!");
lcd.setCursor(9, 0); err2 = true;
lcd.print(temp2); } else {
lcd.write((int)0); lcd.setCursor(10,1);
lcd.print("C"); printVal(temp2);
lcd.setCursor(9,1); }
lcd.print(humi2); if (humi2<0 || humi2>100){
lcd.print(" %"); lcd.setCursor(10,2);
lcd.print("oor!");
err2 = true;
} else {
lcd.setCursor(10,2);
printVal(humi2);
}
} }
if (humi1<0 || humi1>100){ lcd.setCursor(5,3);
fehler("Humi 1"); float tau1, tau2;
return; if (err1){
} lcd.print("----");
if (temp1<-40 || temp1>80){ } else {
fehler("Temp 1"); tau1 = taupunkt(temp1,humi1);
return; printVal(tau1);
}
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(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();
}
}
} }

Loading…
Cancel
Save