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.
271 lines
5.0 KiB
271 lines
5.0 KiB
/* |
|
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 <LiquidCrystal.h> |
|
#include <DHT22.h> |
|
|
|
int pinDHT22a = 8; |
|
DHT22 dht22a(pinDHT22a); |
|
int status1 = 0; |
|
|
|
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); |
|
|
|
float temp1 = 0, temp2 = 0, humi1 = 0, humi2 = 0; |
|
float treshold = 5.0; |
|
float hyster = 1.0; |
|
float min_temp = 5; |
|
|
|
int relay = 7; |
|
|
|
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); |
|
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 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(); |
|
|
|
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(); |
|
} |
|
} |
|
}
|
|
|