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);
}