Having valve open until condition is met


I have a solenoid valve i want to keep open until my pressure sensor reads the desired pressure.

Lets say the sensor reads 1 bar, but i want it to be 2 bar. I have the sensors hooked up to analog input, and signal for the solenoid valve connected via a 12v relay.

I have 8 of these solenoid vales i need to operate. But how do i make it keep sending the signal until it reaches 2 bars, before moving on to the next Solenoid?

Thank you for anything you can do to help

if(analogRead(A1) < 2) { //under pressure 2
    digitalWrite(1, HIGH); //write digital pin 1 high
  else {
    digitalWrite(1, LOW); //If pressure is 2

Output pins don't change by themselves, if you call digitalWrite() that forces the output to the
wanted state and it stays there until you change it again.

Is that what you are asking?

Ahh i see. I am kinda new to this, so i am learning as i go. But that makes sense, i should have known that. But what could i do then? I have to send a signal to the solenoid to stay open until certain value is met. I have googled and googles, maybe i have overlooked something

It looks to me as though the code you provided would do the job if you put it in the loop function. I expect that you would need to change the value you expect from the analogRead to match what the sensor actually returns at 2 bar.