-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharduio.ino
180 lines (158 loc) · 6.2 KB
/
arduio.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
#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>
// WiFi credentials
#define WIFI_SSID "MSI" // Enter your WiFi Name
#define WIFI_PASSWORD "abcd1234" // Enter your password
//Firebase credentials
#define FIREBASE_HOST "iotfinalsystem-default-rtdb.firebaseio.com"
#define FIREBASE_AUTH "lWGL8vUiUHL9cLF4zajUoHWkT8u04dRSn24yHskc"
// Pin connected to the water sensors and motor
#define WATER_SENSOR_PIN D1
#define WATER_SENSOR_PIN2 D2
#define WATER_SENSOR_PIN3 D6
#define WATER_MOTOR_PIN D7
void setup() {
Serial.begin(9600);
// Connect to Wi-Fi
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
// Initialize Firebase
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
// Set the pinMode for the water sensor pins and motor pins
pinMode(WATER_SENSOR_PIN, INPUT);
pinMode(WATER_SENSOR_PIN2, INPUT);
pinMode(WATER_SENSOR_PIN3, INPUT);
pinMode(WATER_MOTOR_PIN, OUTPUT);
}
void loop() {
// Read the values from the water sensors
int waterValue = digitalRead(WATER_SENSOR_PIN);
int waterValue2 = digitalRead(WATER_SENSOR_PIN2);
int waterValue3 = digitalRead(WATER_SENSOR_PIN3);
int motorButtonValue = Firebase.getInt("/Button/motorbutton"); // get value of the motor button
if (motorButtonValue == 1) {
digitalWrite(WATER_MOTOR_PIN, HIGH); // Turn on the motor
Firebase.setString("/Button/motorstatus", "Motor ON");
Serial.println("Motor ON");
}
else if(motorButtonValue == 0){
digitalWrite(WATER_MOTOR_PIN, LOW); // Turn off the motor
Firebase.setString("/Button/motorstatus", "Motor OFF");
Serial.println("Motor OFF");
}
// Water level conditions
if ((waterValue == HIGH) && (waterValue2 == LOW) && (waterValue3 == LOW)) {
Firebase.setString("/Watersensors/WaterLevel", "10 L");
Serial.println("10L ");
while (!(waterValue == HIGH) && (waterValue2 == HIGH) && (waterValue3 == HIGH)) {
digitalWrite(WATER_MOTOR_PIN, HIGH); // Turn on the motor
Firebase.setString("/Button/motorstatus", "Motor ON");
if ((waterValue == HIGH) && (waterValue2 == HIGH) && (waterValue3 == LOW))
{
Firebase.setString("/Watersensors/WaterLevel", "20 L");
Serial.println("20 L ");
}
}
}
else if ((waterValue == HIGH) && (waterValue2 == HIGH) && (waterValue3 == LOW)) {
Firebase.setString("/Watersensors/WaterLevel", "20 L");
Serial.println("20 L ");
}
else if ((waterValue == HIGH) && (waterValue2 == HIGH) && (waterValue3 == HIGH)) {
Firebase.setString("/Watersensors/WaterLevel", "30 L");
Serial.println("30 L ");
digitalWrite(WATER_MOTOR_PIN, LOW);
Firebase.setString("/Button/motorstatus", "Motor OFF");
Firebase.setInt("/Button/motorbutton",0);
}
else if ((waterValue == LOW) && (waterValue2 == LOW) && (waterValue3 == LOW)) {
Firebase.setString("/Watersensors/WaterLevel", "0 L");
digitalWrite(WATER_MOTOR_PIN, HIGH);
Firebase.setString("/Button/motorstatus", "Motor ON");
Serial.println("0 L ");
}
delay(10000); // Delay for 10 seconds
}
#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>
// WiFi credentials
#define WIFI_SSID "MSI" // Enter your WiFi Name
#define WIFI_PASSWORD "abcd1234" // Enter your password
//Firebase credentials
#define FIREBASE_HOST "iotfinalsystem-default-rtdb.firebaseio.com"
#define FIREBASE_AUTH "lWGL8vUiUHL9cLF4zajUoHWkT8u04dRSn24yHskc"
// Pin connected to the water sensors and motor
#define WATER_SENSOR_PIN D1
#define WATER_SENSOR_PIN2 D2
#define WATER_SENSOR_PIN3 D6
#define WATER_MOTOR_PIN D7
void setup() {
Serial.begin(9600);
// Connect to Wi-Fi
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
// Initialize Firebase
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
// Set the pinMode for the water sensor pins and motor pins
pinMode(WATER_SENSOR_PIN, INPUT);
pinMode(WATER_SENSOR_PIN2, INPUT);
pinMode(WATER_SENSOR_PIN3, INPUT);
pinMode(WATER_MOTOR_PIN, OUTPUT);
}
void loop() {
// Read the values from the water sensors
int waterValue = digitalRead(WATER_SENSOR_PIN);
int waterValue2 = digitalRead(WATER_SENSOR_PIN2);
int waterValue3 = digitalRead(WATER_SENSOR_PIN3);
int motorButtonValue = Firebase.getInt("/Button/motorbutton"); // get value of the motor button
if (motorButtonValue == 1) {
digitalWrite(WATER_MOTOR_PIN, HIGH); // Turn on the motor
Firebase.setString("/Button/motorstatus", "Motor ON");
Serial.println("Motor ON");
}
else if(motorButtonValue == 0){
digitalWrite(WATER_MOTOR_PIN, LOW); // Turn off the motor
Firebase.setString("/Button/motorstatus", "Motor OFF");
Serial.println("Motor OFF");
}
// Water level conditions
if ((waterValue == HIGH) && (waterValue2 == LOW) && (waterValue3 == LOW)) {
Firebase.setString("/Watersensors/WaterLevel", "10 L");
Serial.println("10L ");
while (!(waterValue == HIGH) && (waterValue2 == HIGH) && (waterValue3 == HIGH)) {
digitalWrite(WATER_MOTOR_PIN, HIGH); // Turn on the motor
Firebase.setString("/Button/motorstatus", "Motor ON");
if ((waterValue == HIGH) && (waterValue2 == HIGH) && (waterValue3 == LOW))
{
Firebase.setString("/Watersensors/WaterLevel", "20 L");
Serial.println("20 L ");
}
}
}
else if ((waterValue == HIGH) && (waterValue2 == HIGH) && (waterValue3 == LOW)) {
Firebase.setString("/Watersensors/WaterLevel", "20 L");
Serial.println("20 L ");
}
else if ((waterValue == HIGH) && (waterValue2 == HIGH) && (waterValue3 == HIGH)) {
Firebase.setString("/Watersensors/WaterLevel", "30 L");
Serial.println("30 L ");
digitalWrite(WATER_MOTOR_PIN, LOW);
Firebase.setString("/Button/motorstatus", "Motor OFF");
Firebase.setInt("/Button/motorbutton",0);
}
else if ((waterValue == LOW) && (waterValue2 == LOW) && (waterValue3 == LOW)) {
Firebase.setString("/Watersensors/WaterLevel", "0 L");
digitalWrite(WATER_MOTOR_PIN, HIGH);
Firebase.setString("/Button/motorstatus", "Motor ON");
Serial.println("0 L ");
}
delay(10000); // Delay for 10 seconds
}