-
Notifications
You must be signed in to change notification settings - Fork 13
/
sketch_aug23b.ino
29 lines (27 loc) · 942 Bytes
/
sketch_aug23b.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
const int AirValue = 640; // you might need to calibrate this number, instruction is down below
const int WaterValue = 353; // you might need to calibrate this number, instruction is down below
const int DrySoilMoisturePercentage = 50;
const int SoilMoisturePin = A0;
const int RelayPin = D2;
int soilMoistureValue = 0;
int soilmoisturepercent = 0;
void setup() {
Serial.begin(115200);
pinMode(SoilMoisturePin, INPUT);
pinMode(RelayPin, OUTPUT);
digitalWrite(RelayPin, HIGH);
}
void loop() {
soilMoistureValue = analogRead(SoilMoisturePin);
soilmoisturepercent = map(soilMoistureValue, AirValue, WaterValue, 0, 100);
Serial.print(soilmoisturepercent);
Serial.println("%");
if (soilmoisturepercent <= DrySoilMoisturePercentage) {
Serial.println("Water pumps running...");
digitalWrite(RelayPin, LOW);
delay(5000);
}
Serial.println("Water pumps stopped...");
digitalWrite(RelayPin, HIGH);
delay(60000);
}