moisture sensors

im having problems with my sketch i just started a month ago so im a newbie....if anyone can help me fix this PLEASE

const int TxPin = 6;
const int buttonPin1 = 2;  
const int buttonPin2 = 3;  
const int buttonPin3 = 4;  
const int buttonPin4 = 5;  
const int pumpPin = 9;                 
const int valvePin1=13;        
const int valvePin2 = 12; 
const int valvePin3 = 11;
const int valvePin4 = 10;
int buttonState1 = LOW; 
int buttonState2 = LOW;
int buttonState3 = LOW; 
int buttonState4 = LOW; 
const int PROBE = A0-A4; // Analog pin 0-3
int MOISTURE_LEVEL = 250; // the value after the LED goes ON

#include <SoftwareSerial.h>
SoftwareSerial mySerial = SoftwareSerial(255, TxPin);

void setup() {
  
   pinMode(PROBE,INPUT);
   pinMode(pumpPin,OUTPUT);
   pinMode(valvePin1,OUTPUT);
   pinMode(valvePin2,OUTPUT);
   pinMode(valvePin3,OUTPUT);
   pinMode(valvePin4,OUTPUT);
   pinMode(TxPin, OUTPUT);
   digitalWrite(TxPin, HIGH);
   digitalWrite(pumpPin, HIGH);
   digitalWrite  (valvePin1,HIGH);
   digitalWrite(valvePin2,HIGH);
   digitalWrite(valvePin3,HIGH);
   digitalWrite(valvePin4,HIGH);
   mySerial.begin(9600);
   mySerial.write(12);                 // Clear  
   delay(5);   
   mySerial.write(17); 
   mySerial.write(22);  // 
                             // Required d
}
void loop(){


   mySerial.write(128); 
  mySerial.print("S1-");
  
   mySerial.write(148);  
  mySerial.print( "S2-");  

 
  mySerial.write(168);
  mySerial.print("S3-");
 

   mySerial.write(188);  
  mySerial.print( "S4-");  
  
  mySerial.write(132);  
  mySerial.print (analogRead(A0)); 
   mySerial.write(152);  
  mySerial.print (analogRead(A1));
   mySerial.write(172); 
  mySerial.print (analogRead(A2));
    mySerial.write(192); 
  mySerial.print (analogRead(A3)); 
    
    
   
  
  if (analogRead(A3) > MOISTURE_LEVEL)
{
    digitalWrite(pumpPin, LOW);
    digitalWrite(valvePin4, LOW);
}  
  if (analogRead(A3) < MOISTURE_LEVEL)
  {
    digitalWrite(pumpPin, HIGH);
    digitalWrite(valvePin4, HIGH);
}
  if (analogRead(A1) > MOISTURE_LEVEL)
  {
    digitalWrite(pumpPin, LOW);
    digitalWrite(valvePin2, LOW);
}
  if (analogRead(A1) < MOISTURE_LEVEL)
  {
    digitalWrite(pumpPin, HIGH);
    digitalWrite(valvePin2, HIGH);
}     
  if (analogRead(A2) > MOISTURE_LEVEL)
  {
    digitalWrite(pumpPin, LOW);
    digitalWrite(valvePin3, LOW);
}
  if (analogRead(A2) < MOISTURE_LEVEL)
  {
    digitalWrite(pumpPin, HIGH);
    digitalWrite(valvePin3, HIGH);
}  
  if (analogRead(A0) > MOISTURE_LEVEL)
  {
    digitalWrite(pumpPin, LOW);
    digitalWrite(valvePin1, LOW);
}
  if (analogRead(A0) < MOISTURE_LEVEL)
{
    digitalWrite(pumpPin, HIGH);
    digitalWrite(valvePin1, HIGH);
}
}

it works sort of...i wanna add buttons for each valve but one step at a time i guess :~

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

Not sure what you are thinking here but am pretty sure it's not right :slight_smile:

const int PROBE = A0-A4; // Analog pin 0-3
...

void setup() {
   pinMode(PROBE,INPUT);
   ...
}

Maybe you want

const int PROBE1=A0, PROBE2=A1, PROBE3=A2, PROBE4=A3;

pinMode( PROBE1,  INPUT);
pinMode( PROBE2,  INPUT);
... etc

But, I would recommend getting ONE of them working before writing all that non-working code for FOUR...

And then you can learn about arrays to expand for the other three :slight_smile:

Cheers,
John

please more help.....im new

please more help.....im new

When learning to walk, one does not enter a triathlon as the first step.

Dump 75% of that code. Deal with ONE sensor.

Give us a clue as to what you are talking to with the mySerial instance. How are we supposed to know if you have it connected correctly without even knowing what it is? How are we supposed to know if you are sending it the right data, without even knowing what it is?

Did you at least connect power and ground to the it, whatever it is?

You don't have any Serial.print() or Serial.println() statements in the code, so how do you have any clue that it is reading the moisture sensors (whatever they are) correctly?

That code does something. You haven't told us what. You want that code to do something. You haven't told us what. Obviously, there are differences between what it does and what you want, but you haven't told us what they are.

Only YOU can help yourself right now. There is a LOT more information you need to provide if you want us to help you.

im trying to read 4 moisture sensors on a parallax lcd, and turn a pump and valve on when they hit a certain level i got all the led the represent the pumps and valves to light up and turn off when i want except the last one A0 it flashes instead of being solid i have everything hook up right i think i have no problem doing one sensor more then that

Code:
const int TxPin = 6; \lcd pin
const int buttonPin1 = 2; \pins that are for
const int buttonPin2 = 3; \buttons to open valves
const int buttonPin3 = 4; \ and pumps
const int buttonPin4 = 5;
const int pumpPin = 9; \pin that turns on the pump
const int valvePin1=13; \pins that run valves
const int valvePin2 = 12;
const int valvePin3 = 11;
const int valvePin4 = 10;
int buttonState1 = LOW; \setting the button state to low
int buttonState2 = LOW;
int buttonState3 = LOW;
int buttonState4 = LOW;
const int PROBE1= A0 \analog pin A0-A4 moisture sensors
const int PROBE2= A1 \called PROBE1- PROBE4
const int PROBE3= A2
const int PROBE4= A0
int MOISTURE_LEVEL = 250; // the value after the valves and pump goes ON

#include <SoftwareSerial.h>
SoftwareSerial mySerial = SoftwareSerial(255, TxPin);

void setup() {

pinMode(PROBE1,INPUT); \ sets PROBE1-PROBE4 TO input
pinMode(PROBE2,INPUT);
pinMode(PROBE3,INPUT)
pinMode(PROBE4,INPUT);
pinMode(pumpPin,OUTPUT); \ sets pumpPin to output
pinMode(valvePin1,OUTPUT); \ sets valvePins to output
pinMode(valvePin2,OUTPUT);
pinMode(valvePin3,OUTPUT);
pinMode(valvePin4,OUTPUT);
pinMode(TxPin, OUTPUT); \lcd pin to output
digitalWrite(TxPin, HIGH);
digitalWrite(pumpPin, LOW);
digitalWrite (valvePin1,LOW);
digitalWrite(valvePin2,LOW);
digitalWrite(valvePin3,LOW);
digitalWrite(valvePin4,LOW);
mySerial.begin(9600);
mySerial.write(22); \ turns display on
mySerial.write(17); \ turn on lcd back light
mySerial.write(12); \ Clear LCD
delay(5); \ required delay after clear Lcd

}
void loop(){

mySerial.write(128); \ sets sets lcd cursor to line 0 space 0
mySerial.print("S1-");

mySerial.write(148); \ sets lcd cursor to line 1 space 0
mySerial.print( "S2-");

mySerial.write(168); \sets lcd cursor to line 2 space 0
mySerial.print("S3-");

mySerial.write(188); \sets lcd cursor to line3 space 0
mySerial.print( "S4-");

mySerial.write(132); \sets lcd cursor to line 0 space 4
mySerial.print (analogRead(A0));
mySerial.write(152); \sets lcd cursor to line 1 space 4
mySerial.print (analogRead(A1));
mySerial.write(172); \sets lcd cursor to line 2 space 4
mySerial.print (analogRead(A2));
mySerial.write(192); \sets lcd cursor to line 3 space 4
mySerial.print (analogRead(A3));

if (analogRead(A3) > MOISTURE_LEVEL)
{
digitalWrite(pumpPin, LOW);
digitalWrite(valvePin4, LOW);
}
if (analogRead(A3) < MOISTURE_LEVEL)
{
digitalWrite(pumpPin, HIGH);
digitalWrite(valvePin4, HIGH);
}
if (analogRead(A1) > MOISTURE_LEVEL)
{
digitalWrite(pumpPin, LOW);
digitalWrite(valvePin2, LOW);
}
if (analogRead(A1) < MOISTURE_LEVEL)
{
digitalWrite(pumpPin, HIGH);
digitalWrite(valvePin2, HIGH);
}
if (analogRead(A2) > MOISTURE_LEVEL)
{
digitalWrite(pumpPin, LOW);
digitalWrite(valvePin3, LOW);
}
if (analogRead(A2) < MOISTURE_LEVEL)
{
digitalWrite(pumpPin, HIGH);
digitalWrite(valvePin3, HIGH);
}
if (analogRead(A0) > MOISTURE_LEVEL)
{
digitalWrite(pumpPin, LOW);
digitalWrite(valvePin1, LOW);
}
if (analogRead(A0) < MOISTURE_LEVEL)
{
digitalWrite(pumpPin, HIGH);
digitalWrite(valvePin1, HIGH);
}
}

const int PROBE1= A0                \\analog pin A0-A4 moisture sensors
const int PROBE2= A1                 \\called PROBE1- PROBE4
const int PROBE3= A2
const int PROBE4= A0

Why do you have two probe pins defined as A0? And why are there no semicolons?

And please you code tags when you post code.

im trying to read 4 moisture sensors on a parallax lcd

Why? Is the LCD getting wet? You really want to stop that from happening.

i got all the led the represent the pumps and valves to light up and turn off when i want except the last one A0 it flashes

According to the comments in the code, A0 has a moisture sensor attached to it. How can a moisture sensor flash?

      pinMode(PROBE1,INPUT);                    \\ sets PROBE1-PROBE4 TO input
      pinMode(PROBE2,INPUT);                   
   pinMode(PROBE3,INPUT)                                     
   pinMode(PROBE4,INPUT);

This is not doing anything for the analog pins. Analog pins are input only.

  if (analogRead(A3) > MOISTURE_LEVEL)
{
    digitalWrite(pumpPin, LOW);
    digitalWrite(valvePin4, LOW);
} 
  if (analogRead(A3) < MOISTURE_LEVEL)
  {
    digitalWrite(pumpPin, HIGH);
    digitalWrite(valvePin4, HIGH);
}

Why are you not using else? If the reading is not greater than MOISTURE_LEVEL (so the first block is skipped), the only choices are for it to be equal to or less than MOISTURE_LEVEL.

As the code is written, you are ignoring the cases where the readings are equal to MOISTURE_LEVEL. Why?

Hope this is better, any more suggestions? Sorry i for the forgotten semi colons when i was typing it out. at the moment i have leds to represent the pump and valve relays.

const int TxPin = 6;       //lcd pin
const int buttonPin1 = 2;  //pins that are for
const int buttonPin2 = 3;  //buttons to open valves
const       int buttonPin3  =  4;                       // and pumps
const int buttonPin4 = 5;    
const int pumpPin = 9;        //pin that turns on the pump    
const int valvePin1 = 13;        //pins that run valves
const int valvePin2 = 12;       
const int valvePin3 = 11;
const int valvePin4 = 10;
int buttonState1 = LOW;           //setting the button state to low
int buttonState2 = LOW;
int buttonState3 = LOW; 
int buttonState4 = LOW; 
const int PROBE1=A0, PROBE2=A1, PROBE3=A2, PROBE4=A3;
int MOISTURE_LEVEL = 250;                              //the value after the valves and pump goes ON

#include <SoftwareSerial.h>
SoftwareSerial mySerial = SoftwareSerial(255, TxPin);

void setup() {

    
   pinMode(pumpPin,OUTPUT);    // sets pumpPin to output
   pinMode(valvePin1,OUTPUT);    // sets valvePins to output
   pinMode(valvePin2,OUTPUT);
   pinMode(valvePin3,OUTPUT);
   pinMode(valvePin4,OUTPUT);
   pinMode(TxPin, OUTPUT);          //lcd pin to output
   digitalWrite(TxPin, HIGH);         
   digitalWrite(pumpPin, LOW);      
   digitalWrite  (valvePin1,LOW);
   digitalWrite(valvePin2,LOW);
   digitalWrite(valvePin3,LOW);
   digitalWrite(valvePin4,LOW);
   mySerial.begin(9600); 
   mySerial.write(22);                // turns display on
   mySerial.write(17);                // turn on lcd back light   
   mySerial.write(12);                 // Clear  LCD
   delay(5);                          //required delay after clear Lcd
  
    
                             
}
void loop(){


   mySerial.write(128);        // sets sets lcd cursor to line 0 space 0
  mySerial.print("S1-");
  
   mySerial.write(148);           // sets lcd cursor to line 1 space 0
  mySerial.print( "S2-");  

 
  mySerial.write(168);              //sets lcd cursor to line 2 space 0
  mySerial.print("S3-");
 

   mySerial.write(188);              //sets lcd cursor to line3 space 0
  mySerial.print( "S4-");  
 
  mySerial.write(132);               //sets lcd cursor to line 0 space 4
  mySerial.print (analogRead(A0)); 
   mySerial.write(152);               //sets lcd cursor to line 1 space 4
  mySerial.print (analogRead(A1));
   mySerial.write(172);                //sets lcd cursor to line 2 space 4
  mySerial.print (analogRead(A2));
    mySerial.write(192);               //sets lcd cursor to line 3 space 4
  mySerial.print (analogRead(A3)); 
    
    
   
  
  if (analogRead(A3) < MOISTURE_LEVEL)
{
    digitalWrite(pumpPin, HIGH);
    digitalWrite(valvePin1, HIGH);
}  
  else
  {
    digitalWrite(pumpPin, LOW);
    digitalWrite(valvePin4, LOW);
}
  if (analogRead(A1) < MOISTURE_LEVEL)
  {
    digitalWrite(pumpPin, HIGH);
    digitalWrite(valvePin2, HIGH);
}
  else
  {
    digitalWrite(pumpPin, LOW);
    digitalWrite(valvePin2, LOW);
}     
  if (analogRead(A2) < MOISTURE_LEVEL)
  {
    digitalWrite(pumpPin, HIGH);
    digitalWrite(valvePin3, HIGH);
}
  else
  {
    digitalWrite(pumpPin, LOW);
    digitalWrite(valvePin3, LOW);
}  
  if (analogRead(A0) < MOISTURE_LEVEL)
  {
    digitalWrite(pumpPin,HIGH );
    digitalWrite(valvePin1, HIGH);
}
  else
{
    digitalWrite(pumpPin, LOW);
    digitalWrite(valvePin1, LOW);
}
   pinMode(TxPin, OUTPUT);          //lcd pin to output

You should not be diddling with the SoftwareSerial instance's pin(s).

I'd like to see you add Serial.begin() to setup() (with some baud rate), and read the pins differently.

int val0 = analogRead(PROBE0);
Serial.print("Probe 0: ");
Serial.println(val0);
if(val0 < MOISTURE_LEVEL)
{
  // Stuff goes here
}
else
{
  // Stuff goes here
}

Then, open the Serial Monitor, and tell us what output you see. You may have a hardware problem.

So your problem was that the LED was flickering. After your most recent code iteration, is the LED still flickering? What is the latest status of problems you see?

Besides, if you use real devices, pumps and fans, in place of the LEDs, you will see the devices turn on and off, then on and off etc. You need at some hysteresis so you compare if value is above threshold1 to decide whether to turn on and compare if value is below threshold2, not 1 again to decide whether to turn off.

I count 1 pump and 4 valves.

(1) Do you want the pump to turn on when any of the four moisture sensors are dry?
(2) Do you want the pump to turn off when any of the four moisture sensors are wet?

It looks to me like your code is doing both (1) and (2).

Cheers,
John

its still flickering.....yes i run one pump and four valves , the pump and valve are suppose to turn on when the the sensor is dry..i didnt put equal in cause i thought i wouldnt matter

const int TxPin = 6;       //lcd pin
const int buttonPin1 = 2;  //pins that are for
const int buttonPin2 = 3;  //buttons to open valves
const int buttonPin3 = 4;                       // and pumps
const int buttonPin4 = 5;    
const int pumpPin = 9;        //pin that turns on the pump    
const int valvePin1 = 13;        //pins that run valves
const int valvePin2 = 12;       
const int valvePin3 = 11;
const int valvePin4 = 10;
int buttonState1 = LOW;           //setting the button state to low
int buttonState2 = LOW;
int buttonState3 = LOW; 
int buttonState4 = LOW; 
const int PROBE1=A0, PROBE2=A1, PROBE3=A2, PROBE4=A3;
int MOISTURE_LEVEL = 250;                              //the value after the valves and pump goes ON

#include <SoftwareSerial.h>
SoftwareSerial mySerial = SoftwareSerial(255, TxPin);

void setup() {

    
   pinMode(pumpPin,OUTPUT);    // sets pumpPin to output
   pinMode(valvePin1,OUTPUT);    // sets valvePins to output
   pinMode(valvePin2,OUTPUT);
   pinMode(valvePin3,OUTPUT);
   pinMode(valvePin4,OUTPUT);
   pinMode(TxPin, OUTPUT);          //lcd pin to output
   digitalWrite(TxPin, HIGH);         
   digitalWrite(pumpPin, LOW);      
   digitalWrite  (valvePin1,LOW);
   digitalWrite(valvePin2,LOW);
   digitalWrite(valvePin3,LOW);
   digitalWrite(valvePin4,LOW);
   mySerial.begin(9600); 
   mySerial.write(22);                // turns display on
   mySerial.write(17);                // turn on lcd back light   
   mySerial.write(12);                 // Clear  LCD
   delay(5);                          //required delay after clear Lcd
  
    
                             
}
void loop(){


   mySerial.write(128);        // sets sets lcd cursor to line 0 space 0
  mySerial.print("S1-");
  
   mySerial.write(148);           // sets lcd cursor to line 1 space 0
  mySerial.print( "S2-");  

 
  mySerial.write(168);              //sets lcd cursor to line 2 space 0
  mySerial.print("S3-");
 

   mySerial.write(188);              //sets lcd cursor to line3 space 0
  mySerial.print( "S4-");  
 
  mySerial.write(132);               //sets lcd cursor to line 0 space 4
  mySerial.print (analogRead(A0)); 
   mySerial.write(152);               //sets lcd cursor to line 1 space 4
  mySerial.print (analogRead(A1));
   mySerial.write(172);                //sets lcd cursor to line 2 space 4
  mySerial.print (analogRead(A2));
    mySerial.write(192);               //sets lcd cursor to line 3 space 4
  mySerial.print (analogRead(A3)); 
    
    
   
  
  if (analogRead(A3) < MOISTURE_LEVEL)
{
    digitalWrite(pumpPin, HIGH);
    digitalWrite(valvePin1, HIGH);
}  
  else
  {
    digitalWrite(pumpPin, LOW);
    digitalWrite(valvePin4, LOW);
}
  if (analogRead(A1) < MOISTURE_LEVEL)
  {
    digitalWrite(pumpPin, HIGH);
    digitalWrite(valvePin2, HIGH);
}
  else
  {
    digitalWrite(pumpPin, LOW);
    digitalWrite(valvePin2, LOW);
}     
  if (analogRead(A2) < MOISTURE_LEVEL)
  {
    digitalWrite(pumpPin, HIGH);
    digitalWrite(valvePin3, HIGH);
}
  else
  {
    digitalWrite(pumpPin, LOW);
    digitalWrite(valvePin3, LOW);
}  
  if (analogRead(A0) < MOISTURE_LEVEL)
  {
    digitalWrite(pumpPin,HIGH );
    digitalWrite(valvePin1, HIGH);
}
  else
{
    digitalWrite(pumpPin, LOW);
    digitalWrite(valvePin1, LOW);

}
}

s1lim:
its still flickering.....yes i run one pump and four valves , the pump and valve are suppose to turn on when the the sensor is dry..

Think about if some of the four sensors are dry and others are wet...

Your code:
The dry ones are telling the pump "turn on!"
The wet ones are telling the pump "turn off!"

If I was the pump I would probably be flickering too :slight_smile:

John

ok how do i change it? and why does it only do it for one valve and non of the others?

Would that be pin1? That's because of the first if-else. You don't have anything that would turn valvePin4 HIGH, but then you have 1 in too many places. It does not look logical.

However, you can have more problems when the sensor readings change. Write it in pseudo code what you want happen, then design it further. I think what you want is that the pump would turn on when any of the valves need to be open. Then when all the valves are off, you might as well turn the pump off too. Now what happens is that if any of the valves turn off, so does the pump, and then on the second round it turns on (because of one sensor reading), and off again (because of another reading).

One tip I can give you is to use either int or bool variables for what state each element should be in, and then act on it decisively after the if-else conditions.

example please

example please

void loop()
{
   int val0 = analogRead(A0);
   int val1 = analogRead(A1);
   int val2 = analogRead(A1);
   int val3 = analogRead(A3);

   if(val0 < MOISTURE_LEVEL)
      digitalWrite(valvePin0, HIGH);
   else
       digitalWrite(valvePin0, LOW);

   // replicate for the other 3 valve pins

   if(val0 < MOISTURE_LEVEL ||
       val1< MOISTURE_LEVEL ||
       val2< MOISTURE_LEVEL ||
       val3< MOISTURE_LEVEL)
   {
      digitalWrite(pumpPin, HIGH);
   }
   else
   {
      digitalWrite(pumpPin, LOW);
   }
}

What this is doing is opening the correct valve if a sensor is dry, and then, if any sensor is dry, turning the pump on.

Notice that the action of opening a valve is separated from the action of turning the pump on, because the pump condition is dependent on any sensor, while the valves are dependent on a specific sensor.

thanku ill give this a try....

It works perfect thank u so much.....if i were to add buttons would i do them the same ?

again thank you....this is what i've come up with so for all of it works....

const int TxPin = 6;       //lcd pin
const int relayPin1 = 4;  //pins that are for
const int relayPin2 = 3;  //buttons to open valves
const int relayPin3 = 2;                       // and pumps
const int relayPin4 = 5; 
const int relayPin5 = 7; 
const int pumpPin = 9;        //pin that turns on the pump    
const int valvePin1 = 13;        //pins that run valves
const int valvePin2 = 12;       
const int valvePin3 = 11;
const int valvePin4 = 10;
const int PROBE1=A0, PROBE2=A1, PROBE3=A2, PROBE4=A3;
int MOISTURE_LEVEL = 250;                              //the value after the valves and pump goes ON


#include <SoftwareSerial.h>
SoftwareSerial mySerial = SoftwareSerial(255, TxPin);



void setup() {

   pinMode(relayPin5, OUTPUT);  
   pinMode(relayPin4, OUTPUT);   
   pinMode(relayPin1, OUTPUT);   
   pinMode(relayPin2, OUTPUT);   
   pinMode(relayPin3, OUTPUT);   
   pinMode(pumpPin,OUTPUT);    // sets pumpPin to output
   pinMode(valvePin1,OUTPUT);    // sets valvePins to output
   pinMode(valvePin2,OUTPUT);
   pinMode(valvePin3,OUTPUT);
   pinMode(valvePin4,OUTPUT);
   pinMode(TxPin, OUTPUT);          //lcd pin to output
   digitalWrite(TxPin, HIGH);         
   digitalWrite(pumpPin, LOW);      
   digitalWrite  (valvePin1,LOW);
   digitalWrite(valvePin2,LOW);
   digitalWrite(valvePin3,LOW);
   digitalWrite(valvePin4,LOW);
   digitalWrite(relayPin1,LOW);
   digitalWrite(relayPin2,LOW);
   digitalWrite(relayPin3,LOW);
   digitalWrite(relayPin4,LOW);
   digitalWrite(relayPin5,LOW);
   mySerial.begin(9600); 
   mySerial.write(22);                // turns display on
   mySerial.write(17);                // turn on lcd back light   
   mySerial.write(12);                 // Clear  LCD
   delay(5);                          //required delay after clear Lcd
}





void loop()
{
   int val0 = analogRead(A0);
   int val1 = analogRead(A1);
   int val2 = analogRead(A2);
   int val3 = analogRead(A3);  
   
   mySerial.write(128);
  mySerial.print("S1-");
   mySerial.write(148);  
  mySerial.print( "S2-");  
  mySerial.write(168);
  mySerial.print("S3-");
   mySerial.write(188);  
  mySerial.print( "S4-");  
   mySerial.write(132);  
  mySerial.print (analogRead(A0)); 
   mySerial.write(152);  
  mySerial.print (analogRead(A1));
   mySerial.write(172); 
  mySerial.print (analogRead(A2));
    mySerial.write(192); 
  mySerial.print (analogRead(A3)); 
   
   
   if(val0 < MOISTURE_LEVEL)
 { 
      digitalWrite(valvePin1, HIGH);
      digitalWrite(relayPin1, HIGH);
 }     
 else
 {
       digitalWrite(valvePin1, LOW);
       digitalWrite(relayPin1, LOW);
 }   
   if(val1 < MOISTURE_LEVEL)
  { 
      digitalWrite(valvePin2, HIGH);
      digitalWrite(relayPin2, HIGH);
  }
   else
   {
       digitalWrite(valvePin2, LOW);
       digitalWrite(relayPin2, LOW);
   }       
   if(val2 < MOISTURE_LEVEL)
   {
      digitalWrite(valvePin3, HIGH);
      digitalWrite(relayPin3, HIGH);
   }
   else
   {
       digitalWrite(valvePin3, LOW);
       digitalWrite(relayPin3, LOW);
   }            
   if(val3 < MOISTURE_LEVEL)
   {
      digitalWrite(valvePin4, HIGH);
      digitalWrite(relayPin4, HIGH);
   }
   else
   {
       digitalWrite(valvePin4, LOW);
        digitalWrite(relayPin4, LOW);
   }
   if(val0 < MOISTURE_LEVEL ||
       val1< MOISTURE_LEVEL ||
       val2< MOISTURE_LEVEL ||
       val3< MOISTURE_LEVEL)
   {
      digitalWrite(pumpPin, HIGH);
      digitalWrite(relayPin5, HIGH);
   }
   else
   {
      digitalWrite(pumpPin, LOW);
      digitalWrite(relayPin5, LOW);
   }
}

i would love to add buttons to control each valve..