How to IF statement

I am VERY new to the world of ARDUINO and I have to do a final class project. I wrote my code and realized I needed a way to check my sensor to meet a certain output before moving on to the next IF statement.

If you can't tell what my project is, I am using 2 flow-meters and 2 solenoid valves, 1 of each in series that is parallel to the other set. I put water flow through both meters. If I lose flow on one meter, I want the arduino to close the solenoid valve on the other flow-meter side.

I was thinking a DO statement, but I don't want the program to move on until there is HIGH's on both sensors on the first IF statement.

PLEASE HELP!!!!!

Brian_Prodj.ino (613 Bytes)

If you can, attach the code directly, cannot open ino files on iPad here.

const int sensor1Pin= 1; //Flowmeter 1 pin
const int sensor2Pin= 2; //Flowmeter 2 pin
const int shutoff1Pin= 3; //solanoid 1 pin
const int shutoff2Pin= 4; // solanoid 2 pin

void setup()
{
pinMode(sensor1Pin, INPUT);
pinMode(sensor2Pin, INPUT);
pinMode(shutoff1Pin, OUTPUT);
pinMode(shutoff2Pin, OUTPUT);
}

void loop()
{
int sensor1State, sensor2State;
sensor1State = digitalRead(sensor1Pin);
sensor2State = digitalRead(sensor2Pin);
if ((sensor1State==LOW)&&(sensor2State==HIGH))
digitalWrite(shutoff2Pin,HIGH);

if ((sensor1State==HIGH) && (sensor2State==LOW))
digitalWrite(shutoff1Pin,HIGH);
}

Have you heard of a State Machine to control program flow?

no, like I said before, I am VERY new to Arduino.
I need the code to, I guess, check the "state" of the meter. If it is HIGH, then go to next IF statement. If it is LOW, don't move on until it is HIGH.

or something to that effect.

I get what your saying with the 4 IF statements. But I dont think it will work like that. If i lose flow on one meter, I want the solenoid on the other meter to shut off until there is flow on the first meter. Then open back up and check the second meter. If I write it with 4 IF statements, wont it just recognize it as having no flow on both meters and shut both solenoids off?

I can draw a simple picture of my project if it will help with what i am trying to do

Yes, this is all it has to do. Unfortunately, I don't know how to write block code. I am just starting out with the very basic of code writing.

I did add ELSE statements though, but i dont know how to stop the program so shutoff2 pin can go LOW before checking the next IF statement

if ((sensor1State==LOW)&&(sensor2State==HIGH))
digitalWrite(shutoff2Pin,HIGH);
else
digitalWrite(shutoff2Pin,LOW);

if ((sensor1State==HIGH)&&(sensor2State==LOW))
digitalWrite(shutoff1Pin,HIGH);
else
digitalWrite(shutoff2Pin,LOW);
}

BSUSS:
no, like I said before, I am VERY new to Arduino.
I need the code to, I guess, check the "state" of the meter. If it is HIGH, then go to next IF statement. If it is LOW, don't move on until it is HIGH.

or something to that effect.

You actually have the "code" figured out, now just "read your statement in reverse" and arrange the code using "while" instead

while (read state == low ) {}; // stay in "while" when state is LOW
// continue process since state is now HIGH