How can I run a part of the code when I give another input?

I am trying to use Arduino Uno to control a solenoid valve that feeds water to a pressurized chamber. The solenoid valve should close if the chamber pressure or the water delivery pressure reduces below a certain value. I would like to execute the "if" condition only after setting both the pressures to the desired value. Is there any way to do it?

The following is my code:

int value1 = 0;
int value2 = 0;
int pin = 13; // sets the pin
float pr_chk_chmbr = 1.98; // sets the value of pressure to be maintained in chamber
float pr_chk_del = 2.98; // sets the value of pressure to be maintained in delivery
float volt_chmbr; // voltage output of chamber pressure sensor
float volt_del; // voltage output of water delivery sensor
float pr_act_chmbr; // actual pressure in chamber
float pr_act_del; // actual pressure in delivery

void setup(){
  Serial.begin(9600);
  pinMode(pin, OUTPUT);    // sets the digital pin as output
}

void loop(){
  value1 = analogRead(A0); //Sensor connection from chamber
  value2 = analogRead(A1); //Sensor connection from delivery
  volt_chmbr = value1 * 5.0/1023 - 0.5;
  volt_del = value2 * 5.0/1023 - 0.5;
  pr_act_chmbr = volt_chmbr * 3;
  pr_act_del = volt_del * 3;
  Serial.print("Chamber Pressure= ");
  Serial.println(pr_act_chmbr);
  Serial.print("Delivery Pressure= ");
  Serial.println(pr_act_del);
  if (pr_act_chmbr < pr_chk_chmbr || pr_act_del < pr_chk_del) digitalWrite(pin, HIGH);
  delay(50);
}

Which values?- do you mean the pr_chk_chmbr and _ del values, which are currently hard-coded? Do you need to change those target values on the fly?

Will you ever do a:

digitalWrite(pin, LOW);

Thanks for replying.

I meant the pr_act_chmbr and _del, which will be the actual pressure inside the chamber and the delivery pressure.

Once they have been set, then the "if" condition should come into play.

As of now the moment I execute this code, the solenoid valve will close in the beginning itself.

No, I won't be doing it.

On doing the second set of experiments, I am just planning to change the pr_chk_ values.

Show the circuit... output pins default as low, and maybe low is closed?

(side note, hope you're not powering the solenoid's coil from a digital pin which shouldn't be asked to provide more than 20mA)

What pressures are displayed on Serial Monitor?

Is the Chamber Pressure less than 1.98 (pr_chk_chmbr) or is Delivery Pressure less than 2.98 (pr_chk_del)?