-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAgruminoWithPump.ino
88 lines (75 loc) · 1.91 KB
/
AgruminoWithPump.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
//// Agrumino your personal gardener
/// Created by [email protected]
#include <Agrumino.h>
#define PUMP 12
#define SLEEP_TIME_SEC 120 ///s Time
#define THRESHOLD 25 ///% soil moisture
#define THRESHOLDTEMP 22 ////°C
#define SERIALBAUD 115200
#define WATERINGTIME 1000 //// set Time in ms
int counter = 0;
Agrumino agrumino;
void setup() {
agrumino.setup();
Serial.begin(SERIALBAUD);
pinMode(PUMP, OUTPUT);
digitalWrite(PUMP, LOW);
}
void loop() {
agrumino.turnBoardOn();
counter ++;
if (counter == 100) {
wateringControl();
delay(1200);
}
else if (counter == 2000) {
int timetominutes = SLEEP_TIME_SEC / 60 ;
Serial.print("Bye......I'm sleep for " + String(timetominutes) + " minutes");
counter = 0;
deepSleepSec(SLEEP_TIME_SEC);
agrumino.turnBoardOff();
}
}
void blinkLed() {
agrumino.turnLedOn();
delay(200);
agrumino.turnLedOff();
}
void wateringLed() {
agrumino.turnLedOn();
delay(300);
agrumino.turnLedOff();
delay(100);
agrumino.turnLedOn();
delay(300);
agrumino.turnLedOff();
delay(100);
agrumino.turnLedOn();
delay(300);
agrumino.turnLedOff();
}
void wateringControl() {
int soilPerc = agrumino.readSoil();
int temp = agrumino.readTempC();
Serial.println("****************");
Serial.println("Temperature = " + String(temp));
Serial.println("Soil Moisture % = " + String(soilPerc));
if (soilPerc < THRESHOLD && temp < THRESHOLDTEMP) {
agrumino.turnLedOn();
Serial.print("I'm Watering your plant");
agrumino.turnWateringOn();
delay(WATERINGTIME);
agrumino.turnWateringOff();
delay(1000);
agrumino.turnLedOff();
}
else if (soilPerc < THRESHOLD && temp > THRESHOLDTEMP) {
Serial.println("Soil moisture is not ok, but temperature is very high....I'm waiting..");
}
}
void delaySec(int sec) {
delay (sec * 1000);
}
void deepSleepSec(int sec) {
ESP.deepSleep(sec * 1000000); // microseconds
}