-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patheps32_code.ino
More file actions
107 lines (77 loc) · 2.45 KB
/
eps32_code.ino
File metadata and controls
107 lines (77 loc) · 2.45 KB
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
#include <WiFi.h>
#include <Firebase_ESP_Client.h>
#include "DHT.h"
#define WIFI_SSID "WIFI_NAME"
#define WIFI_PASSWORD "WIFI_PASSWORD"
#define DATABASE_URL "FIREBASE_DATABASE_URL"
#define DATABASE_SECRET "FIREBASE_DATABASE_SECRET"
#define DHTPIN 4
#define DHTTYPE DHT11
#define MOISTURE_PIN 34
#define LDR_PIN 32
#define TDS_PIN 35
/* Moisture Calibration */
int DRY_VALUE = 3300;
int WET_VALUE = 1400; // Adjust as per your needs
/* LDR Calibration */
int DARK_VALUE = 3500;
int BRIGHT_VALUE = 200;
DHT dht(DHTPIN, DHTTYPE);
FirebaseData fbdo;
FirebaseAuth auth;
FirebaseConfig config;
void setup() {
Serial.begin(115200);
delay(2000);
dht.begin();
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nWiFi Connected");
config.database_url = DATABASE_URL;
config.signer.tokens.legacy_token = DATABASE_SECRET;
Firebase.begin(&config, &auth);
Firebase.reconnectWiFi(true);
}
void loop() {
/* Read DHT11 */
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
/* Read Soil Moisture */
int moistureRaw = analogRead(MOISTURE_PIN);
int moisturePercent = map(moistureRaw, DRY_VALUE, WET_VALUE, 0, 100);
moisturePercent = constrain(moisturePercent, 0, 100);
/* Read Light (Inverted) */
int lightRaw = analogRead(LDR_PIN);
int lightPercent = map(lightRaw, DARK_VALUE, BRIGHT_VALUE, 0, 100);
lightPercent = constrain(lightPercent, 0, 100);
int tdsRaw = analogRead(TDS_PIN);
/* Print values */
Serial.println("------ SENSOR DATA ------");
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %");
Serial.print("Moisture: ");
Serial.print(moisturePercent);
Serial.println(" %");
Serial.print("Light: ");
Serial.print(lightPercent);
Serial.println(" %");
Serial.print("TDS Raw: ");
Serial.println(tdsRaw);
Serial.println("-------------------------");
/* Send to Firebase */
Firebase.RTDB.setFloat(&fbdo, "/CropData/Temperature", temperature);
Firebase.RTDB.setFloat(&fbdo, "/CropData/Humidity", humidity);
Firebase.RTDB.setInt(&fbdo, "/CropData/Moisture", moisturePercent);
Firebase.RTDB.setInt(&fbdo, "/CropData/Light", lightPercent);
Firebase.RTDB.setInt(&fbdo, "/CropData/TDS", tdsRaw);
Serial.println("Data Sent to Firebase\n");
delay(5000);
}