-
Notifications
You must be signed in to change notification settings - Fork 0
/
Soil_moisture.ino
52 lines (51 loc) · 1.48 KB
/
Soil_moisture.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
int soil_moisture_1 = A0; //soil moisture sensor for plant no. 1
int soil_moisture_2 = A1; //soil moisture sensor for plant no. 2
int soil_moisture_3 = A3; //soil moisture sensor for plant no. 3
void setup() {
Serial.begin(9600);
pinMode(2, OUTPUT); //pin 2 - diode to inform to water plant no. 1
pinMode(3, OUTPUT); //pin 3 - diode to inform to water plant no. 2
pinMode(4, OUTPUT); //pin 4 - diode to inform to water plant no. 3
}
void loop() {
int read_soil_moisture_1 = analogRead(soil_moisture_1);
int read_soil_moisture_2 = analogRead(soil_moisture_2);
int read_soil_moisture_3 = analogRead(soil_moisture_3);
// Serial.println("Soil moisture for plant no. 1: ");
Serial.print(read_soil_moisture_1);
Serial.print("\t");
// Serial.println();
// Serial.println("Soil moisture for plant no. 2: ");
Serial.print(read_soil_moisture_2);
Serial.print("\t");
// Serial.println("");
// Serial.println("Soil moisture for plant no. 3: ");
Serial.print(read_soil_moisture_3);
Serial.println("");
// Serial.println("");
if (read_soil_moisture_1 > 500)
{
digitalWrite(2, HIGH);
}
else
{
digitalWrite(2, LOW);
};
if (read_soil_moisture_2 > 500)
{
digitalWrite(3, HIGH);
}
else
{
digitalWrite(3, LOW);
};
if (read_soil_moisture_3 > 500)
{
digitalWrite(4, HIGH);
}
else
{
digitalWrite(4, LOW);
};
delay(10000);
}