-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathplant_watering_system.ino
49 lines (44 loc) · 1.07 KB
/
plant_watering_system.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
//Analog pin (Moisture Sensor)
#define ANA A0
//Digital pin (Moisture Sensor)
#define DIGI D5
#define SENSOR D7
//Power pin (Pump via transistor)
#define POMPOUT D6
double analogValue = 0.0;
int digitalValue = 0;
unsigned long checkInterval=5000;
unsigned long nextCheckAt = 5000;
void setup() {
// put your setup code here, to run once:
pinMode(ANA, INPUT);
pinMode(DIGI, INPUT);
pinMode(SENSOR, OUTPUT);
pinMode(POMPOUT, OUTPUT);
Serial.begin(115200);
}
void loop() {
if(millis()>nextCheckAt)
{
digitalWrite(SENSOR, HIGH);
delay(100);
analogValue = analogRead(ANA);
digitalValue = digitalRead(DIGI);
digitalWrite(SENSOR, LOW);
// Serial data
Serial.print("Analog raw: ");
Serial.println(analogValue);
Serial.print("Digital raw: ");
Serial.println(digitalValue);
Serial.println(" ");
if (digitalValue == 0) {
digitalWrite(POMPOUT, LOW);
} else {
Serial.println("Pumping");
digitalWrite(POMPOUT, HIGH);
}
//Set the next check time
nextCheckAt = millis()+checkInterval;
}
yield();
}