Hi everyone, just want to ask how am I suppose to make two if statements to operate at the same time?
I mean in this setup,
there are two level sensors that act as input,
if they are triggered, they will trigger their corresponding pumps.
however, the result is this;
the if statement #2 does not operate while the if statement 1 is satisfied/triggered.
how can I make these two statements independent from each other?
I mean in this setup,
there are two level sensors that act as input,
if they are triggered, they will trigger their corresponding pumps.
however, the result is this;
the if statement #2 does not operate while the if statement 1 is satisfied/triggered.
how can I make these two statements independent from each other?
Code:
const int level1 = 2;
const int level2 = 3;
const int pump1 = 4;
const int pump2 = 5;
void setup()
{
pinMode(level1, INPUT_PULLUP);
pinMode(level2, INPUT_PULLUP);
pinMode(pump1, OUTPUT);
pinMode(pump2, OUTPUT);
}
void loop()
{
int state1 = digitalRead(level1);
int state2 = digitalRead(level2);
if(state1==0)
{
digitalWrite(pump1, HIGH);
}
else
{
digitalWrite(pump1, LOW);
if(state2==0)
{
digitalWrite(pump2, HIGH);
}
else
{
digitalWrite(pump2, LOW);
}
}
}