Thanks Steve, I'm asking rather than testing because I have a few days before the remainder to the parts come in and I would like to work out any issues before hand.
The issue I'm working on now is adding a standard 16x2 LCD screen to display the moisture values. Would you mind also checking out this code also?
I cant seem to get the values to display properly on the display, Im pretty sure it's just a rookie mistake but I am scratching my head getting it figured out.
Thanks
#include <LiquidCrystal.h>
//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
//must be used with Arduino Mega
const int numRows = 2; //two rows
const int numCols = 16; //sixteen columns
LiquidCrystal lcd(12, 11, 10, 9, 8, 7); //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 potLow = A4; //low moisture level setting
const int potHigh = A5; //high moisture level setting
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
int percent1; //mapped value of zone1
int percent2; //mapped value of zone2
int percent3; //mapped value of zone3
int percent4; //mapped value of zone4
void setup()
{
lcd.begin(numCols,numRows);
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
}
{
percent1 = map(zone1,0,1023,0,99); //map zone1 range to 0-99
percent2 = map(zone2,0,1023,0,99); //map zone2 range to 0-99
percent3 = map(zone3,0,1023,0,99); //map zone3 range to 0-99
percent4 = map(zone4,0,1023,0,99); //map zone4 range to 0-99
}
lcd.setCursor(0,0); //set the cursor to the first row and the first column
lcd.print(percent1); //print mapped value of zone1
lcd.setCursor(9,0); //set the cursor to the first row and the ninth column
lcd.print(percent2); //print mapped value of zone2
lcd.setCursor(1,0); //set the cursor to the second row and the first column
lcd.print(percent3); //print mapped value of zone3
lcd.setCursor(1,9); //set the cursor to the second row and the ninth column
lcd.print(percent4); //print mapped value of zone4
}