Code doesn't work in loop

So I have a system with two pressure tanks, 1 compressor, 2 solenoid valves, 2 pressure drop valves and a pressure sensor.

I want my compressor to run until the pressure reach a desired value and then change to the other pressure tank and then run until the pressure again reach a desired value and then stops.
My code works fine when I run it in the setup function, but when I try to run the code in the loop function, it runs once, but the second time, the while loops doesn’t work?

My code is:

digitalWrite(10,HIGH);   // Turn the compressor on
digitalWrite(11,HIGH);   // Open solenoid valve 1

//Solenoid valve 2 and 3 are default closed (LOW = closed)

  while(pressure < 47 ){    //Since the pressure is an integer, multiply by 10.
           pressure = (analogRead(A0)*(5.0/1023.0)*10.0);
           // The while loop will continue until the condition is false.
          }

digitalWrite(11,LOW);  // When desired pressure reach, close the solenoid valve for pressure tank 1.
digitalWrite(12,HIGH); // Open the solenoid valve for pressure tank 2.
delay(3000); // Wait 3 seconds.. (This line is probably not necessary in the final system.
  while(pressure1 < 47 ){    //Since the pressure is an integer, multiply by 10.
           pressure1 = (analogRead(A0)*(5.0/1023.0)*10.0);
           // The while loop will continue until the condition is false.
          }
// When desired pressure reach, turn the compressor of and close the solenoid valve.
digitalWrite(12,LOW);  // Close the solenoid valve for pressure tank 2.

Is your posted code complete? I do not see a setup or a loop anywhere.

My guess is that your pressure variables are initialized to zero, go past 47 and are never reset, since the calls to analogRead() is inside the loops. Try changing the code to read the pressure outside the loop first:

  pressure = (analogRead(A0)*(5.0/1023.0)*10.0);
  while(pressure < 47 ){    //Since the pressure is an integer, multiply by 10.
           pressure = (analogRead(A0)*(5.0/1023.0)*10.0);
           // The while loop will continue until the condition is false.
          }
pressure = (analogRead(A0)*(5.0/1023.0)*10.0);
  while(pressure < 47 ){    //Since the pressure is an integer, multiply by 10.

Divide by 1023 isn’t right. And because you do the right thing and make pressure an int, don’t do float math

pressure = analogRead(A0) * 50U  1024;
  while(pressure < 47 ){    //Since the pressure is an integer, multiply by 10.

Thanks guys!
I'm not sure I understand why dividing by 2013 isn't correct? Is the correct thing to do: *50/1024?

There are 1024 steps, not 1023.

Let's make it simple, if you have 10 people, 0 to 9. And you need to divide something equal over everybody, do you divide by 9? :wink: