-
Notifications
You must be signed in to change notification settings - Fork 0
/
flower code.txt
71 lines (66 loc) · 1.5 KB
/
flower code.txt
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
int sensor1_pin =D2;
int sensor2_pin =D3;
int sensor3_pin =D5;
int sensor4_pin =D6;
int sensor5_pin =D7;
int relay_pin=D1;
int reset_pin=D0;
int sleepSeconds = 43200;
int average;
void setup() {
//pinMode(BUILTIN_LED, OUTPUT);
pinMode(relay_pin, OUTPUT);
pinMode(sensor1_pin, INPUT);
pinMode(sensor2_pin, INPUT);
pinMode(sensor3_pin, INPUT);
pinMode(sensor4_pin, INPUT);
pinMode(sensor5_pin, INPUT);
// Connect D0 to RST to wake up
pinMode(reset_pin, WAKEUP_PULLUP);
}
void loop() {
if(digitalRead(sensor1_pin) == HIGH){
average += 1;
}
if(digitalRead(sensor2_pin) == HIGH){
average += 1;
}
if(digitalRead(sensor3_pin) == HIGH){
average += 1;
}
if(digitalRead(sensor4_pin) == HIGH){
average += 1;
}
if(digitalRead(sensor5_pin) == HIGH){
average += 1;
}
if(average >= 3) {
//digitalWrite(BUILTIN_LED, HIGH);
digitalWrite(relay_pin, HIGH);
while(average >=3){
average=0;
if(digitalRead(sensor1_pin) == HIGH){
average += 1;
}
if(digitalRead(sensor2_pin) == HIGH){
average += 1;
}
if(digitalRead(sensor3_pin) == HIGH){
average += 1;
}
if(digitalRead(sensor4_pin) == HIGH){
average += 1;
}
if(digitalRead(sensor5_pin) == HIGH){
average += 1;
}
delay(500);
}
//digitalWrite(BUILTIN_LED, LOW);
digitalWrite(relay_pin, LOW);
}
Serial.println("Sleep for 10 seconds");
delay(1000);
// convert to microseconds
ESP.deepSleep(sleepSeconds * 1000000);
}