-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocument.ino
More file actions
132 lines (115 loc) · 2.87 KB
/
document.ino
File metadata and controls
132 lines (115 loc) · 2.87 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
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
#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>
#include <NTPClient.h>
#include <WiFiUdp.h>
#define WIFI_SSID "Readmi"
#define WIFI_PASSWORD "01234567"
#define FIREBASE_HOST "washing-timetable.firebaseio.com"
#define FIREBASE_AUTH "jhstNsBXERw9uhfLvb77K8mBNLbCIlzC90ir3FSb"
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org");
int LED1 = 16;
int LED2 = D6;
int LED3 = D7;
int LED4 = D8;
int StartB = D5;
int Str;
int pot = A0;
int potential;
int set;
void wifiConnect()
{
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to ");
Serial.print(WIFI_SSID); Serial.println(" ...");
int teller = 0;
while (WiFi.status() != WL_CONNECTED)
{
delay(1000);
Serial.print(++teller); Serial.print(' ');
}
Serial.println('\n');
Serial.println("Connection established!");
Serial.print("IP address:\t");
Serial.println(WiFi.localIP());
}
void setup()
{
Serial.begin(115200);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
pinMode(StartB, INPUT);
pinMode(pot, INPUT);
/*pinMode(LED1, INPUT);
pinMode(LED1, INPUT);
pinMode(LED1, INPUT);*/
Serial.println('\n');
wifiConnect();
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
timeClient.begin();
timeClient.setTimeOffset(+3);
delay(10);
}
void firebasereconnect()
{
Serial.println("Trying to reconnect");
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
Serial.println();
}
void loop()
{
while(WiFi.status() != WL_CONNECTED)
{
wifiConnect();
}
if (Firebase.failed()) {
Serial.print("Failed to connect");
Serial.println(Firebase.error());
Serial.println();
Serial.println();
firebasereconnect();
wifiConnect();
delay(2000);
return;
}
potential = analogRead(pot) / 4;
Str = digitalRead(StartB);
if(potential > 150){
set = 5400;
digitalWrite(LED2, HIGH);
}
else if(potential < 150){
digitalWrite(LED2, LOW);
}
if(potential < 100){
set = 1800;
digitalWrite(LED3, HIGH);
}
else if(potential > 100){
digitalWrite(LED3, LOW);
}
if(100 < potential&&potential < 150){
set = 3600;
digitalWrite(LED4, HIGH);
}
else if(100 > potential||potential > 150){
digitalWrite(LED4, LOW);
}
if(Str != HIGH)
{
digitalWrite(LED1, HIGH);
}
if(Str == HIGH)
{
digitalWrite(LED1, LOW);
timeClient.update();
int epochTime = timeClient.getEpochTime();
Serial.print("Epoch Time: ");
Serial.println(epochTime);
Firebase.setString("hostels/hostel1/floors/floor1/washingMachines/washingMachine1/startTime",String(epochTime));
Firebase.setString("hostels/hostel1/floors/floor1/washingMachines/washingMachine1/endTime",String(set + epochTime));
}
delay(50);
}