Program Failing at one Line

So for my program I have a switch and when I switch it on I want it to start the first portion and wait when done with that till the switch turns off then run the second part, and starts at the top again. So the issue I am having is where I put the “//FAIL” tags is where the program fails, by freezing or skipping them. Also it will some times just not even run the delay commands? I have asked around at work and know one knows whats wrong. Any Help Please?

int pinButton = 8; //the pin where we connect the button
int LED = 13;               // variable to hold the last button state
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(13,OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(pinButton, INPUT); //set the button pin as INPUT
  pinMode(LED, OUTPUT); //set the LED pin as OUTPUT
}

// the loop function runs over and over again forever
void loop() 
{
    digitalWrite(12, HIGH);  //flame dector 2 on
     
    
    int stateButton = digitalRead(pinButton); //read the state of the button
  if(stateButton == 1) { 
       digitalWrite(13, HIGH); 
      digitalWrite(9, HIGH); //heat request on 
      delay(5000);          //FAILS
       digitalWrite(13, LOW);    //FAILS
      digitalWrite(10, HIGH); //air pressure switch on
      delay(15000);                       
      digitalWrite(11, HIGH);  // flame dector 1 on
      //light on
      delay(8000);
      digitalWrite(12,LOW); //flame dector 2 off
      
       while(digitalRead(pinButton) == 1 ) {}
       
          digitalWrite(13, LOW);
          digitalWrite(9,LOW);  //heat request off
          delay(2000);
          digitalWrite(12,HIGH);  //flame dector 2 on
          delay(1000);
          digitalWrite(11,LOW); //flame dector 1 off
          delay(1000);
          digitalWrite(10, LOW); // air pressure switch 
     
       
     }
 
  
  
}

It seems to fail after issuing the "heat request on", so it is likely a power issue.

Are you (unwisely) trying to power something, or switching on a relay with the Arduino? Post a hand-drawn pencil sketch (not Fritzing) of your wiring diagram.

Hint: using "delay" is usually a bad idea. Take a look at the built in example "blink without delay" to learn how to avoid that.

Try this:

  pinMode(pinButton, INPUT_PULLUP); //set the button pin as INPUT

Pete

https://drive.google.com/open?id=0BxeTYhis47nmTUp6dTJRZ2pUa3Rrbkx3UnFkdXlad2RQVC04

We need specs on your relay board.
Can you give us a link?
It might be that the board requires more current than the 5v pin can provide.

The INPUT_PULLUP should fix one problem but as @vinceherman says, we need more info about that relay board.
The Arduino probably can't supply enough current to all those relays from its 5V 200mA output.

Pete

For trigging the relays yes the current can be the problem, but I believe just turning the LED on for each of the relays it should be able to do. My problem I believe lies in the Arduino cause the Arduino is skipping the lines of code for what ever reason. But why would it skip the delay functions ?

stevof12:
My problem I believe lies in the Arduino cause the Arduino is skipping the lines of code for what ever reason. But why would it skip the delay functions ?

No, it is not "skipping" anything. You are looking in the wrong place altogether. The one thing MCUs do VERY reliably is execute the code they are given. ALWAYS.
Regards,
Ray L.

stevof12:
For trigging the relays yes the current can be the problem, but I believe just turning the LED on for each of the relays it should be able to do.

If there is a power supply issue then all bets are off.
Your circuit diagram is incomplete since it doesn't show the power supply to the Arduino.

How are you powering the Arduino?
Does the relay board have a separate power supply?
As previously asked for by vinceherman and el_supremo, what is the exact relay board you are using?