Hello everyone, I am working on an automatic plant watering system. Here's how it is setup to run
- potLow - potentiometer to set the driest the soil can get (point where valve opens to water plant)
- potHigh - potentiometer to set the wettest the soil can get (point where watering valve closes)
- Four watering zones
Will the 'if' statement I wrote in the loop close the valve once the value for potHigh is reached or will it stay open and continuously flow? The way I have it written, I am not completely sure.
If the code causes the valve to open and stay open, can someone suggest how I should modify the code to correct the issue?
Thanks
//First attempt at making a 4 zone auto watering system
//potPins values are just for setup purposes, must be calibrated once placed in soil
//potPins are to adjust the high and low moisture ranges for each zone
//
const int zone1 = A0;
const int zone2 = A1;
const int zone3 = A2;
const int zone4 = A3;
const int potLow = A4;
const int potHigh = A5;
const int valve1 = 2;
const int valve2 = 3;
const int valve3 = 4;
const int valve4 = 5;
void setup()
{
pinMode(valve1,OUTPUT);
pinMode(valve2,OUTPUT);
pinMode(valve3,OUTPUT);
pinMode(valve4,OUTPUT);
}
void loop()
{
if(analogRead(zone1) <= potLow){ //read the value from the soil moisture sensor
digitalWrite(valve1,HIGH);} //open the valve
if(analogRead(zone1) >= potHigh){ //when value from soil moisture sensor reaches the upper limit
digitalWrite(valve1,LOW); //close the valve
}
}