-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArduino_Wetterstation_BME280_Display.ino
240 lines (205 loc) · 5.46 KB
/
Arduino_Wetterstation_BME280_Display.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#include <Wire.h>
#include <math.h>
#include <LiquidCrystal_I2C.h>
#include <Adafruit_BME280.h>
LiquidCrystal_I2C lcd(0x27, 20, 4); //I2C Displayadresse 0x27 -> 20 chars und 4 Zeilen Display
Adafruit_BME280 bme;
//Globale Variablen
int counter = 0;
int _LoopDelay = 1000;
int DisplayCounter = 0; //Umschalten zwischen Aktuellen Werten und Min/Max Werten
float LastTemp = 0;
float LastPressure = 0;
float LastHumidity = 0;
float LastWasserdampfgehalt = 0;
float MinTemp = 1000;
float MinPressure = 10000;
float MinHumidity = 1000;
float MinWasserdampfgehalt = 1000;
float MaxTemp = -1000;
float MaxPressure = -10000;
float MaxHumidity = -1000;
float MaxWasserdampfgehalt = -1000;
//Prototyp
void BlinkBacklight(int count = 3);
void setup()
{
bool status = false;
pinMode(LED_BUILTIN, OUTPUT); //integrierte LED initialisieren
Serial.begin(9600);
status = bme.begin(0x76); //Adresse I2C Temp, Feuchte, Druck Sensor
if (!status)
{
Serial.println("Could not find a valid BME280 sensor, check wiring!");
for (int i = 0; i < 3; i++)
{
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000);
}
//while (1); //Zwangsstopp --> Reset durchführen
}
lcd.begin(); //LCD Initalisieren
lcd.backlight(); //Hintergrundbeleuchtung einschalten
}
void loop()
{
// lcd.print(0x30+val/100,BYTE);
// lcd.print(0x30+(val0)/10,BYTE);
// lcd.print(0x30+val,BYTE);
ReadSensorData();
CalcWaterValue();
CalcMinMaxValues();
SerialLoopAusgabe();
if (DisplayCounter == 30)
{
lcd.clear();
PrintMinMaxValuesOnLCD();
DisplayCounter = 0;
delay(5000);
lcd.clear();
}
else
{
PrintLastValuesOnLCD();
if (CheckForAlarm()) //Alarmwerte abfragen z.B Feuchte >= 60%rF
BlinkBacklight(1);
delay(_LoopDelay);
}
DisplayCounter++;
}
void PrintLastValuesOnLCD()
{
//Temp, Feuchte, Druck Sensor (Bosch BME280)
lcd.setCursor(0, 0);
lcd.print(LastTemp); //°C
lcd.setCursor(17, 0);
lcd.print("\337C");
lcd.setCursor(0, 1);
lcd.print(LastHumidity); //%rF
lcd.setCursor(17, 1);
lcd.print("%rF");
lcd.setCursor(0, 2);
lcd.print(LastPressure); //hPa
lcd.setCursor(17, 2);
lcd.print("hPa");
lcd.setCursor(0, 3);
lcd.print(LastWasserdampfgehalt); //g/m^3
lcd.setCursor(16, 3);
lcd.print("g/m3");
}
void PrintMinMaxValuesOnLCD()
{
//Temp, Feuchte, Druck Sensor (Bosch BME280)
lcd.setCursor(0, 0);
lcd.print("Min");
lcd.print(MinTemp); //°C
lcd.setCursor(8, 0);
lcd.print("Max:");
lcd.print(MaxTemp); //°C
lcd.setCursor(17, 0);
lcd.print("\337C");//°C
lcd.setCursor(0, 1);
lcd.print("Min");
lcd.print(MinHumidity); //%rF
lcd.setCursor(8, 1);
lcd.print("Max:");
lcd.print(MaxHumidity); //%rF
lcd.setCursor(17, 1);
lcd.print("%rF");
lcd.setCursor(0, 2);
lcd.print("Min");
lcd.print((int)MinPressure); //hPa
lcd.setCursor(8, 2);
lcd.print("Max:");
lcd.print((int)MaxPressure); //hPa
lcd.setCursor(17, 2);
lcd.print("hPa");
lcd.setCursor(0, 3);
lcd.print("Min");
lcd.print(MinWasserdampfgehalt); //g/m³
lcd.setCursor(8, 3);
lcd.print("Max:");
lcd.print(MaxWasserdampfgehalt); //g/m³
lcd.setCursor(17, 3);
lcd.print("g/m");
}
void BlinkBacklight(int count)
{
lcd.noBacklight(); //Hintergrundbeleuchtung ausschalten
delay(_LoopDelay / 2);
lcd.backlight(); //Hintergrundbeleuchtung einschalten
}
bool CheckForAlarm()
{
if (LastHumidity >= 60)
return true;
else
return false;
}
void ResetMinMax24h()
{
}
void ReadSensorData()
{
//Temp, Feuchte, Druck Sensor (Bosch BME280)
LastTemp = bme.readTemperature();
LastPressure = bme.readPressure() / 100.0f;
LastHumidity = bme.readHumidity();
}
void CalcMinMaxValues()
{
CalcMinValues();
CalcMaxValues();
}
void CalcMinValues()
{
if (MinTemp >= LastTemp)
MinTemp = LastTemp;
if (MinPressure >= LastPressure )
MinPressure = LastPressure;
if (MinHumidity >= LastHumidity )
MinHumidity = LastHumidity;
if (MinWasserdampfgehalt >= LastWasserdampfgehalt)
MinWasserdampfgehalt = LastWasserdampfgehalt;
}
void CalcMaxValues()
{
if (MaxTemp <= LastTemp)
MaxTemp = LastTemp;
if (MaxPressure <= LastPressure)
MaxPressure = LastPressure;
if (MaxHumidity <= LastHumidity )
MaxHumidity = LastHumidity;
if (MaxWasserdampfgehalt <= LastWasserdampfgehalt)
MaxWasserdampfgehalt = LastWasserdampfgehalt;
}
void CalcWaterValue()
{
float Saettingsungsdampfdruck = 0;
float TatsaechlicherDampfdruck = 0;
float MaxWasserdampfgehalt = 0;
float TatsaechlicherWasserdampfgehalt = 0;
Saettingsungsdampfdruck = 6.112 * exp((17.62 * LastTemp) / (243.12 + LastTemp));
TatsaechlicherDampfdruck = Saettingsungsdampfdruck / 100 * LastHumidity;
MaxWasserdampfgehalt = (Saettingsungsdampfdruck / (461.5 * (273.15 + LastTemp))) * 100000;
TatsaechlicherWasserdampfgehalt = (TatsaechlicherDampfdruck / (461.5 * (273.15 + LastTemp))) * 100000;
LastWasserdampfgehalt = TatsaechlicherWasserdampfgehalt;
}
void SerialLoopAusgabe()
{
//Loop Ausgabe
String ausgabe = "Loop: ";
Serial.println(ausgabe + counter);
Serial.println(LastTemp);
Serial.println(MinTemp);
Serial.println(MaxTemp);
Serial.println(LastPressure);
Serial.println(MinPressure);
Serial.println(MaxPressure);
Serial.println(LastHumidity);
Serial.println(MinHumidity);
Serial.println(MaxHumidity);
counter++;
}