Pneumatic cylinders with sensors with Arduino Uno I'm working on my own project with Arduino Uno. There are controlled 4 pneumatic cylinders via 4 coils. Every pneumatic cylinder has got their own coil which switch air to the pneumatic cylinder. Every pneumatic cylinder has got 2 magnetic sensors (when the pneumatic cylinder is retracted and extended).
I created a program for arduino but it doesn't work correctly. When I write there that I want to control only 2 pneumatic cylinders, it works correctly. If I write there the others, it skip the second if statement, do the third if statement and then do the previous if. I don't know why. The behaviour is random. What's wrong with my code? Thank you for help!

// Constants for pneumatic valves
   const int dvere = 2;
   const int davkovani = 3;
   const int lisovani = 4;
   const int vyhazovani = 5;
// ----------------------------------------
// Constants for sensors
   const int vyhazovaniZasunute = 6;
   const int vyhazovaniVysunute = 7;
   const int lisovaniVysunute = 8;
   const int lisovaniZasunute = 9;
   const int dvereZasunute = 10;
   const int dvereVysunute = 11;
   const int davkovaniVysunute = 12;
   const int davkovaniZasunute = 13;


void setup() {
  // Pneumatic cylinders set as output
  pinMode(dvere, OUTPUT);    
  pinMode(davkovani, OUTPUT);    
  pinMode(lisovani, OUTPUT);    
  pinMode(vyhazovani, OUTPUT);    

  // Sensors set as input
  pinMode(vyhazovaniZasunute, INPUT);   
  pinMode(vyhazovaniVysunute, INPUT);   
  pinMode(lisovaniVysunute, INPUT);   
  pinMode(lisovaniZasunute, INPUT);   
  pinMode(dvereZasunute, INPUT);   
  pinMode(dvereVysunute, INPUT);  
  pinMode(davkovaniVysunute, INPUT);  
  pinMode(davkovaniZasunute, INPUT);  

  // Set pneumatic cylinders as they are retracted
  digitalWrite(dvere, HIGH);
  digitalWrite(davkovani, HIGH);
  digitalWrite(lisovani, HIGH);
  digitalWrite(vyhazovani, HIGH);
}

void loop() {

  if(digitalRead(dvereZasunute) == HIGH)
  {
      digitalWrite(dvere, LOW);      // extend the first pneumatic cylinder when the sensor is lighted on because the pneumatic cylinder is retracted
  }

  if(digitalRead(dvereVysunute) == HIGH &amp;&amp; digitalRead(davkovaniZasunute) == HIGH
  )
  {
      digitalWrite(davkovani, LOW);      // extend the second pneumatic cylinder
      delay(4000);
      digitalWrite(davkovani, HIGH);    // retract the second pneumatic cylinder after 4 seconds, 
      // this code works when it is alone there, the next if statements not
  }

  if(digitalRead(dvereVysunute) == HIGH &amp;&amp; digitalRead(davkovaniZasunute) == HIGH &amp;&amp; digitalRead(lisovaniZasunute) == HIGH)
  {
      digitalWrite(lisovani, LOW);    // extend the third pneumatic cylinder
      delay(3000);
      digitalWrite(lisovani, HIGH);   // retract the secondthird pneumatic cylinder after 3 seconds
  }

  if(digitalRead(dvereVysunute) == HIGH &amp;&amp; digitalRead(davkovaniZasunute) == HIGH &amp;&amp; digitalRead(lisovaniZasunute) == HIGH)
  {
      digitalWrite(dvere, HIGH);      // retract the first pneumatic cylinder
  }

  if(digitalRead(dvereZasunute) == HIGH &amp;&amp; digitalRead(davkovaniZasunute) == HIGH &amp;&amp; digitalRead(lisovaniZasunute) == HIGH &amp;&amp; digitalRead(vyhazovaniZasunute) == HIGH)
  {
      digitalWrite(vyhazovani, LOW);    // extend the fourth pneumatic cylinder
  }

  if(digitalRead(dvereZasunute) == HIGH &amp;&amp; digitalRead(davkovaniZasunute) == HIGH &amp;&amp; digitalRead(lisovaniZasunute) == HIGH&amp;&amp; digitalRead(vyhazovaniVysunute) == HIGH)
  {
      digitalWrite(vyhazovani, HIGH);    // retract the fourth pneumatic cylinder
  }

  // sensors - HIGH - light on, LOW - light off,
  // pneumatic cylinders - HIGH - retracted, LOW - extended.
}
void loop() {

...

  if(digitalRead(dvereVysunute) == HIGH &amp;&amp; digitalRead(davkovaniZasunute) == HIGH
  )
  {
      digitalWrite(davkovani, LOW);      // extend the second pneumatic cylinder
      delay(4000);
      digitalWrite(davkovani, HIGH);    // retract the second pneumatic cylinder after 4 seconds, 
      // this code works when it is alone there, the next if statements not
  }

...
}


If the condition is met, then davkovani is going to be LOW 99.999% of the time. It will only briefly go HIGH, as there is no delay there. The loop will iterate and set it LOW again. So it may seem to be "not working" whereas the problem is that it "works" very briefly.