-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCode_TheWeather.ino
91 lines (67 loc) · 1.82 KB
/
Code_TheWeather.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
#define SPI_CS 10
#include <Wire.h>
#include <DS1307RTC.h>
#include <SPI.h>
#include <SD.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
float temp;
float feuchte;
float druck;
float hohe;
float sonne = 0;
int sensorPin = A0;
int ledPin = 13;
Adafruit_BME280(bme);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
setSyncProvider(RTC.get);
if (!bme.begin(0x76)) {
Serial.println("Kein BME280 angeschlossen! Prüfe die Kabel");
while (1);
}
Serial.println("SD-Karte initialisieren");
if (!SD.begin(SPI_CS)) {
Serial.println("SD-Karte nicht lesbar! Überprüfe die SD-Karte!");
while (1);
}
Serial.println("Erfolgreich initialisiert");
}
void loop() {
// put your main code here, to run repeatedly:
temp = bme.readTemperature();
feuchte = bme.readHumidity();
druck = bme.readPressure() / 100.0F;
sonne = analogRead(sensorPin);
String Datensatz = String(temp) +
"," +
String(feuchte) +
"," +
String(druck) +
"," +
String(sonne) +
",";
String Zeit = String(hour()) +
":" +
String(minute()) +
":" +
String(second()) +
"," +
String(year()) +
"-" +
String(month()) +
"-" +
String(day());
Serial.println(Datensatz);
Serial.println(Zeit);
File Zieldatei = SD.open("temp_log.csv", FILE_WRITE);
if (Zieldatei) {
Zieldatei.print(Datensatz);
Zieldatei.println(Zeit);
Zieldatei.close();
} else {
Serial.println("Datensatz konnte nicht geschrieben werden");
}
delay(600000);
}