-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathElecrow-smart_pump.ino
79 lines (65 loc) · 1.69 KB
/
Elecrow-smart_pump.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
// set all moisture sensors PIN ID
int moisture1 = A0;
int moisture2 = A1;
int moisture3 = A2;
int moisture4 = A3;
// declare moisture values
int moisture1_value = 0;
int moisture2_value = 0;
int moisture3_value = 0;
int moisture4_value = 0;
// set water relays
int relay1 = 3;
int relay2 = 4;
int relay3 = 5;
int relay4 = 6;
// set water pump
int pump = 2;
void setup() {
// declare relay as output
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
pinMode(relay4, OUTPUT);
// declare pump as output
pinMode(pump, OUTPUT);
// declare the ledPin as an OUTPUT:
Serial.begin(9600);
}
void loop() {
// read the value from the moisture sensors:
moisture1_value = analogRead(moisture1);
moisture2_value = analogRead(moisture2);
moisture3_value = analogRead(moisture3);
moisture4_value = analogRead(moisture4);
// check which plant need water
// and open the switch for that specific plant
if(moisture1_value<=450){
digitalWrite(relay1, HIGH);
}
if(moisture2_value<=450){
digitalWrite(relay2, HIGH);
}
if(moisture3_value<=450){
digitalWrite(relay3, HIGH);
}
if(moisture4_value<=450){
digitalWrite(relay4, HIGH);
}
// make sure there is at least one plant that needs water
// if there is, open the motor
if(moisture1_value<=450 || moisture2_value<=450 || moisture3_value<=450 || moisture4_value<=450){
digitalWrite(pump, HIGH);
}
// let it water the plant for 5 seconds
delay(5000);
// turn the pump off
digitalWrite(pump, LOW);
// go each switch and turn them off
digitalWrite(relay1, LOW);
digitalWrite(relay2, LOW);
digitalWrite(relay3, LOW);
digitalWrite(relay4, LOW);
// wait 5 minutes and repeat the process
delay(300000);
}