code problem

can someone tell me why my if statements at the end do not work when the statements are true? I have tested my serial monitor to see if the “var1” = true and it does, as well as the limit switches = true, that are both the commands to be able to send a voltage to my motors. The code that isn’t seeming to work is at the end.

#include <LiquidCrystal.h>

#include <boarddefs.h>
#include <IRremote.h>
#include <IRremoteInt.h>
#include <ir_Lego_PF_BitStreamEncoder.h>

//Valve Control by Nick 


const int RECV_PIN = 6;
IRrecv irrecv(RECV_PIN);
decode_results results;
const int WaterSensor1 = A0;
const int WaterSensor2 = A1;
int LimitValveO1 = 9;
int LimitValveO2 = 4;
int LimitValveC1 = 8;
int LimitValveC2 = 5;
int value1;
int value2;
int value3;
int var1 = 0;
int var2 = 0;
int var3 = 0;
int var4 = 0;
int go = 0;
const int rs = A2, en = A3, d4 = A5, d5 = A4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
//int OpenPushButton = 7;
//int ClosePushButton = 6; //dont need buttons anymore
int flag1;
int flag2;
int OpenWValve1 = 10;
int CloseWValve1 = 11;
int OpenWValve2 = 12;
int CloseWValve2 = 13;
//int IRO = 16720605
//int IRC = 16761405
//int PP = 16712445


void setup() {
  Serial.begin(9600);
  irrecv.enableIRIn(); // enable receiver module
  irrecv.blink13(true);
  lcd.begin(16, 2);               //set up lcd colums and rows:
  lcd.print("why"); //print a message to the lcd
//  pinMode(OpenPushButton, INPUT);
  //pinMode(ClosePushButton, INPUT);
  pinMode(LimitValveO1, INPUT);
  pinMode(LimitValveC1, INPUT);
  pinMode(LimitValveO2, INPUT);
  pinMode(LimitValveC2, INPUT);
  pinMode(OpenWValve1, OUTPUT);
  pinMode(OpenWValve2, OUTPUT);
  pinMode(CloseWValve1, OUTPUT);
  pinMode(CloseWValve2, OUTPUT);
  pinMode(WaterSensor1, INPUT);
  pinMode(WaterSensor2, INPUT); 

}

void loop() {
  value1 = analogRead(WaterSensor1);
  value2 = analogRead(WaterSensor2);
  Serial.println(digitalRead(LimitValveO1));
  // Serial.println(flag1);
  //Serial.println(var1);
  //Serial.println(results.value);
  //Serial.println(value1);
  //Serial.println(value2);
  //Serial.print(lcd.);
  //Serial.println(digitalRead(OpenWValve1));


  if (value1 >= 10 & value2 >= 10) {
    lcd.setCursor(0,0);
    lcd.write("1 Wet 2 Wet");       // both wet

  }
  if (value1 >= 10 & value2 <= 10) { //1 wet 2 dry
    lcd.setCursor(0,0);
    lcd.write("1 Wet 2 Dry");
    
  }
    if(value1<=10 & value2>=10){      //1 dry 2 we//t
     lcd.setCursor(0,0);
     lcd.write("1 Dry 2 Wet");
     
   }
   if (value1<=10 & value2<=10){        //both dry
     lcd.setCursor(0,0);
     lcd.write("1 Dry 2 Dry");
     
   }



  if (irrecv.decode(&results)) {

    irrecv.resume();

    switch (results.value) {
      case 16720605:
        var1 = 1;  //open
        var2 = 1;
        var3 = 0;
        var4 = 0;
        break;
      case 16761405:
        var3 = 1;   //close
        var4 = 1;
        var1 = 0;
        var2 = 0;
        break;
      case 16712445:
        go = 1;
        break;
      case 16753245:
        var1 = 0;
        var2 = 0;
        var3 = 0;
        var4 = 0;
        go = 0;
        break;
    }
  }




  if (var1 == 1) {
    if (digitalRead(LimitValveO1 != 1)) {
      digitalWrite(OpenWValve1, HIGH);
    }
    if (digitalRead(LimitValveO1 == 1)) {
      digitalWrite(OpenWValve1, LOW);
    }
  }
   if (var2 == 1) {
    if (digitalRead(LimitValveO2 != 1)) {
      digitalWrite(OpenWValve2, HIGH);
    }
    if (digitalRead(LimitValveO2 == 1)) {
      digitalWrite(OpenWValve2, LOW);
    }
  }
    if ((var1 ==0) or (digitalRead(LimitValveO1 == 1))) {
      digitalWrite(OpenWValve1, LOW);
    }
   if ((var2 ==0) or (digitalRead(LimitValveO2 == 1))) {
      digitalWrite(OpenWValve2, LOW);
    }
if (digitalRead(LimitValveO1 != 1)) {

Look closely at what the digitalRead is reading. You want to read a pin but that line is reading the result of the comparison which will be 0 or 1 with the parenthesis where they are.

if (digitalRead(LimitValveO1) != 1) {

Here I change the parenthesis to read the LimitValveO1 pin state and compare that to !=1 (0).
The same mistake is repeated many times.

And the last 2 if statements have an extra ). In the IDE if you place the cursor to the right of a
(, ), { or } the matching (, ), { or } will be highlighted.

See the digitalRead() reference.

if ((var1 ==0) or (digitalRead(LimitValveO1 == 1)))

Solution:

if ((var1 ==0) || (digitalRead(LimitValveO1) == 1))

Explanation:

digitalRead() is a function call, you need to compare the result of that call, if you would separate the statement it would look like this

result = digitalRead(LimitValveO1)

if ((var1 ==0) || (result == 1))

In this piece of code (from the Original Post)

if (var1 == 1) {
    if (digitalRead(LimitValveO1 != 1)) {
      digitalWrite(OpenWValve1, HIGH);
    }
    if (digitalRead(LimitValveO1 == 1)) {
      digitalWrite(OpenWValve1, LOW);
    }
  }

it would be perfectly possible for both IF statements to be true because they use two separate digitalRead()s and the value might change between them. Much better to read once and save the value to a variable and use the variable in the tests - just like how it is done earlier in the program using analogRead()

...R