Hi everyone, I have a question for my plant watering system. I am attempting to set up a watering system. I wrote the code so I have 2 potentiometers, one to set the high moisture level and one to set the low. There are 4 zones/valves for four plants. Once the moisture level reaches the lower moisture setting it SHOULD water in three minute intervals until the high moisture level has been reached. There is also a control valve in the system which is the main valve attached to the water supply. I am having 2 problems so far. When I put the moisture sensor in water, the resistance goes down, which I am in the process of fixing. THe main problem I could use some help with is that none of the valves open when the setting goes below the lower moisture range. The valves are 12v valves wired up to a separate 12v power source which are controlled by an arduino and 4 relays. I am kind of confused why this is happening. Can anyone please give me some insight? And before the online "tough guys" attack my code yet again, I realize it could be written more efficiently with for statements but I am using if statements because that's what I knew how to write when I started and I intent to use what I have. THanks in advance.
//Completed 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
#include <LiquidCrystal.h>
LiquidCrystal lcd(7,8,9,10,11,12); //initialize library with the interface pins (these might need to be adjusted in the future)
const int zone1 = A0; //soil sensor for zone 1
const int zone2 = A1; //soil sensor for zone 2
const int zone3 = A2; //soil sensor for zone 3
const int zone4 = A3; //soil sensor for zone 4
const int potPinLow = A4; //low moisture pot
const int potPinHigh = A5; //high moisture pot
int potLow;
int potHigh;
const int valve1 = 2; //water valve 1
const int valve2 = 3; //water valve 2
const int valve3 = 4; //water valve 3
const int valve4 = 5; //water valve 4
const int controlValve = 6; //main valve control
int percent1; //mapped value of zone1
int percent2; //mapped value of zone2
int percent3; //mapped value of zone3
int percent4; //mapped value of zone4
int display1;
int display2;
int display3;
int display4;
int display7;
int display8;
void setup()
{
lcd.begin(16,2);
pinMode(valve1,OUTPUT);
pinMode(valve2,OUTPUT);
pinMode(valve3,OUTPUT);
pinMode(valve4,OUTPUT);
pinMode(potLow,INPUT);
pinMode(potHigh,INPUT);
}
void loop()
{
potLow = analogRead(potPinLow);
potHigh = analogRead(potPinHigh);
percent1 = analogRead(zone1);
percent2 = analogRead(zone2);
percent3 = analogRead(zone3);
percent4 = analogRead(zone4);
if(percent1 <= potLow){ //read the value from the soil moisture sensor
digitalWrite(valve1,HIGH); //open the valve
digitalWrite(controlValve,HIGH);} //open the main control valve
delay(180000); //delay 3 minutes
if(percent1 >= potHigh){ //when value from soil moisture sensor reaches the upper limit
digitalWrite(valve1,LOW);} //close the valve
if(percent2 <= potLow){ //read the value from the soil moisture sensor
digitalWrite(valve2,HIGH); //open the valve
digitalWrite(controlValve,HIGH);} //open the main control valve
delay(180000); //delay 3 minutes
if(percent2 >= potHigh){ //when value from soil moisture sensor reaches the upper limit
digitalWrite(valve2,LOW);} //close the valve
if(percent3 <= potLow){ //read the value from the soil moisture sensor
digitalWrite(valve3,HIGH); //open the valve
digitalWrite(controlValve,HIGH);} //open the main control valve
delay(180000); //delay 3 minutes
if(percent3 >= potHigh){ //when value from soil moisture sensor reaches the upper limit
digitalWrite(valve3,LOW);} //close the valve
if(percent4 <= potLow){ //read the value from the soil moisture sensor
digitalWrite(valve4,HIGH); //open the valve
digitalWrite(controlValve,HIGH);} //open the main control valve
delay(180000); //delay 3 minutes
if(percent4 >= potHigh){ //when value from soil moisture sensor reaches the upper limit
digitalWrite(valve4,LOW);} //close the valve
{
{
display1 = map(percent1,0,1023,0,99); //map zone1 range to 0-99
display2 = map(percent2,0,1023,0,99); //map zone2 range to 0-99
display3 = map(percent3,0,1023,0,99); //map zone3 range to 0-99
display4 = map(percent4,0,1023,0,99); //map zone4 range to 0-99
display7 = map(potLow,0,1023,0,100); //map potLow range to 0-100
display8 = map(potHigh,0,1023,0,100); //map potHigh range to 0-100
lcd.setCursor(0,0); //set the cursor to the first row and the first column
lcd.print(display1); //print mapped value of zone1
lcd.setCursor(6,0); //set the cursor to the first row and the seventh column
lcd.print(display2); //print mapped value of zone2
lcd.setCursor(0,1); //set the cursor to the second row and the first column
lcd.print(display3); //print mapped value of zone3
lcd.setCursor(6,1); //set the cursor to the second row and the seventh column
lcd.print(display4); //print mapped value of zone4
lcd.setCursor(12,0); //set cursor to first row and the 13th column
lcd.print(display8); //print mapped value for potHigh
lcd.setCursor(12,1); //set cursor to the second row and the 13th column
lcd.print(display7); //print the mapped value for potLow
}
}
}