-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpumpTesting.ino
47 lines (43 loc) · 1.53 KB
/
pumpTesting.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
int sensor_pin = A0; //signal from the capacitive soil moisture sensor
int output_value ; // value of soil moisture
int pump = 8; // digital pin where the relay is plugged in
int threshold = 5; //threshold value to trigger pump
void setup() {
Serial.begin(9600);
pinMode(sensor_pin, INPUT); //setup for the soil moisture senor aka
INPUt
pinMode(pump, OUTPUT); //setup for the pump aka OUTPUT
Serial.println("Reading From the Sensor ...");
delay(1000); //1 second delay
}
void loop() {
output_value = analogRead(sensor_pin); //gets the value from the
soil moisture sensor
output_value = map(output_value,550,0,0,100); // this sets the
percentage value
Serial.print("Moisture : ");
Serial.print(output_value); //print the percent of soil moisture -
max is 33% if dipped in a cup of water
Serial.println("%");
delay(1000); //wait 1 second
if (output_value < threshold) //if the soil is try then pump out water
for 1 second
{
digitalWrite(pump, HIGH);
Serial.println("pump on for 3 second");
delay(3000); //run pump for 3 second;
digitalWrite(pump, LOW);
Serial.println("pump off");
//delay(300000); //wait 5 minutes before checking again
delay(3000);//wait 3 second. This is for testing, uncomment the line
above when ready to implement
}
else
{
digitalWrite(pump, LOW);
Serial.println("do not turn on pump");
//delay(300000); //wait 5 minutes
delay(3000);// wait 3 second. This is for testing, uncomment the line
above when implementing
}
}