doesn't go throw the whole condition

i have if condition it read data and data2 from analogRead when one of them is higher than voltage then it will change the digital pin from high to low, but i steams doesn't go throw for loop inside if condition and it just stop whenever data is higher than voltage.
also, is there a way that i can just print to lcd temp and humidity without going throw the if condition, because i have more than one if statement, here it wait for for loop and delay 10 sec to get updated to lcd.

 if (data < voltage && data2 < voltage){
    digitalWrite(pump, HIGH);
    digitalWrite(valve, HIGH);
    digitalWrite(valve2, HIGH);
      for(int i=0; i<10; i++){
        lcd.setCursor(0,3);
        lcd.print("Temp:");
        lcd.print((long)temperature, DEC);
        lcd.setCursor(8,3);
        lcd.print(" Humidity:");
        lcd.print((long)humidity, DEC);
        lcd.setCursor(0, 2);
        lcd.print("S_1:");
        if (data > 260 && data < 295)
        lcd.print("MID");
        else if (data < 260)
        lcd.print("LOW");
        else 
        lcd.print("HIGH");
        lcd.setCursor(7,0);
        lcd.print("Pump:ON");
        lcd.setCursor(0,1);
        lcd.print("V1:ON");
        lcd.setCursor(9, 2);
        lcd.print("S_2:");
        if (data2 > 260 && data2 < 295)
        lcd.print("MID");
        else if (data2 < 260)
        lcd.print("LOW");
        else 
        lcd.print("HIGH");
        lcd.setCursor(7,1);
        lcd.print("V2:ON");
        lcd.setCursor(14,1);
        lcd.print("V3:OFF");
       sum += data;
       sum2+= data2;
       delay(1000);
     }
     average = sum/10;
     average2 = sum2/10;
     if(average > voltage || average2 > voltage){
    digitalWrite(pump, LOW);
    digitalWrite(valve, LOW);
    digitalWrite(valve2, LOW);
    }
    sum = 0;
    sum2 = 0;
    lcd.clear();
  }

i have attached the full codes.

finally.pde (10.4 KB)

Please post your whole code, as I can only say that you should print those values outside your if statement now.

You have posted raw code. No comments to communicate the intent.

So when I read it - the result is that I pretty much agree with the complier. Where as you clearly are not agreeing with the compiler.

To fix this, please add comments to the code that explain what you mean to achieve.
Since you are having problems with the if/else clauses, comment the intent of these, and also comment the code that you want to always run.

This will help others review your code, and from my experience, will help you (the author) clarify what you expect the code to do, perhaps leading you to find your own problem..

here is the file

finally.pde (10.4 KB)

lcd.print("Starting.");
  delay(1300);
  lcd.setCursor(9,1);
  lcd.print(".");
  delay(1300);
  lcd.setCursor(10,1);
  lcd.print(".");
  delay(1300);
  lcd.setCursor(11,1);
  lcd.print(".");
  delay(1300);
  lcd.setCursor(12,1);
  lcd.print(".");
  delay(1300);
  lcd.setCursor(13,1);
  lcd.print(".");
  delay(1300);
  lcd.setCursor(14,1);
  lcd.print(".");
  delay(1300);
  lcd.setCursor(15,1);
  lcd.print(".");
  delay(1300);

You really need to get introduced to the 'for' loop.

The IDE includes a useful tool that auto-formats your code for you.
It is really useful for code visualisation.

AWOL:

lcd.print("Starting.");

delay(1300);
 lcd.setCursor(9,1);
 lcd.print(".");
 delay(1300);
 lcd.setCursor(10,1);
 lcd.print(".");
 delay(1300);
 lcd.setCursor(11,1);
 lcd.print(".");
 delay(1300);
 lcd.setCursor(12,1);
 lcd.print(".");
 delay(1300);
 lcd.setCursor(13,1);
 lcd.print(".");
 delay(1300);
 lcd.setCursor(14,1);
 lcd.print(".");
 delay(1300);
 lcd.setCursor(15,1);
 lcd.print(".");
 delay(1300);



You *really* need to get introduced to the 'for' loop.

The IDE includes a useful tool that auto-formats your code for you.
It is really useful for code visualisation.

i totally forgot about it! just fixed it.

It's usually a dodgy proposition to try and guess what someone else's intent was with code that doesn't function, but it appears to me in your original post, that you're measuring sensor data, comparing it to a desired value, seeing that the sensor data is low and then turning on some systems intended to improve the situation, presumably by adding water and providing heat. They run for 10 iterations, about 10 seconds, then you're looking to see if the average reading has improved and if it has, the systems you turned on can be turned off.

However, you read data and data2 only once, so your loop is always going to calculate the average as unchanged, the systems you want to turn off won't be.

wildbill:
However, you read data and data2 only once, so your loop is always going to calculate the average as unchanged, the systems you want to turn off won't be.

that's my problem! i tried to fix it but without any positive results.

I'm guessing again, but I assume you tried this?

       sum += data;
       sum2+= data2;
       delay(1000);
       data = analogRead(sensorOne);      // read sensorOne value.
       data2 = analogRead(sensorTwo);     // read sensorTwo value.
      }

That might have improved matters, but there is still a possible flaw: If the readings are still too low, you won't turn anything off and things will continue to get moister and hotter. There are some delays in your loop at the top. If one of the data values rises above voltage before the next iteration, there is no code path that will ever turn things off.

wildbill:
I'm guessing again, but I assume you tried this?

       sum += data;

sum2+= data2;
      delay(1000);
      data = analogRead(sensorOne);      // read sensorOne value.
      data2 = analogRead(sensorTwo);    // read sensorTwo value.
      }




That might have improved matters, but there is still a possible flaw: If the readings are still too low, you won't turn anything off and things will continue to get moister and hotter. There are some delays in your loop at the top. If one of the data values rises above voltage before the next iteration, there is no code path that will ever turn things off.

you might have not downloaded the file i posted for the full codes