Code Help.

Hello I just recently got started with Arduino, so my experience is limited.
I want to replace a burned out board with an Arduino one at work. The project seems simple. I need to run a diesel space heater. There are 3 basic parts, a fan, igniter and a fuel pump. All components are 120v and I have 3 relays to carry the current, all are triggered by 5V, 5mA. The problem I’m having with the code is I don’t know how to begin the start sequence and not restart it every loop. How do I prevent the signal wire from starting the sequence over again if the switch is on? Hope I explained this right I’ll post what I have form my code bellow. Thanks in advance!

//Work space heater

int fanRelay = ; //declaring pin x as fanRelay
int ignRelay = ; // declaring pin x as ignRelay
int fuelRelay= ; // declaring pinx as fuelRelay
int trigger= ; // declaring pin x as trigger
int startD = (1000); //declaring startD as delay time
int stopD= (40000) //declaring 40000(40 seconds) as cool down/stop delay time

void setup() {

pinMode(fanRelay, OUTPUT); //set fanRelay as OUTPUT
pinMode(ignRelay, OUTPUT); //set ignRelay as OUTPUT
pinMode(fuelRelay, OUTPUT); //set fuelRelay as OUTPUT
pinMode(trigger, INPUT) //set trigger as INPUT
Serial.begin(9600)

}

void loop() {
if (trigger, HIGH){ //if trigger wire from on switch is high begin start procedure.
digitalWrite(ignRelay, HIGH); //Start IGN relay
delay(startD); //delay
digitalWrite(fanRelay, HIGH); //turn on Fan relay
delay(startD); //delay
digitalWrite(fuelRelay, HIGH); //start fuel pump
}

else (trigger, LOW){ //if signal wire is low(switch is off) begin shutdown sequence.
digitalWrite(fuelRelay, LOW); //turn fuel relay off
delay(startD); //delay
digitalWrite(ignRelay, LOW) //turn off ign
delay(stopD) // begin cool down delay, continue to run FAN to cool unit off
digitalWrite(fanRelay, LOW) // turn fan off
}

if (trigger, HIGH){
digitalWrite(ignRelay, HIGH)
digitalWrite(fanRelay, HIGH)
digitalWrite(fuelRelay,HIGH)

}
else (trigger, LOW)

digitalWrite(ignRelay, LOW)
digitalWrite(fanRelay, LOW)
digitalWrite(fuelRelay,LOW)

}

First You need to really know the sequencies needed in various situations.

  1. How to properly start up from a stand still.
  2. How to controll the unit during running.
  3. How to detect abnormalities and act upon them.

Diesel heaters are not harmless! They are commonly used in buses, and buses catch fire and burns down...

As I read Your code You have no sensors connected to monitor the heater. You only have an On/Off button as input.
In my opinion this is a steering system, not a control system. Please, more informatiion.

int fanRelay = ; //declaring pin x as fanRelay
These lines need a pin number.

int stopD= (40000)

  1. int can only hold -32,768 to 32,767
  2. no closing semicolon, and there are more semicolons missing in your code.
  3. no need to use brackets here.

There is a Help>Reference page in the IDE.

The "how to post" sticky explains how to post code inline, with code tags.
Leo..

You really need what's called a "state machine" for controlling the sequencing of things. For example:

//Work space heater

const byte pinFanRelay = 2;         // declaring pin 2 as fanRelay
const byte pinIgnRelay = 3;         // declaring pin 3 as ignRelay
const byte pinFuelRelay = 4;        // declaring pin 4 as fuelRelay
const byte pinTrigger = 5;          // declaring pin 5 as trigger


#define KT_START_DLY        1000ul  //mS    delay used in start and stop logic    
#define KT_MIN_RUN_DLY      2500ul  //mS    minimum run time after start sequence before moving to running state
#define KT_STOP_DLY         40000ul //mS    fan run-time after shutdown for cooling

#define HEATER_OFF          0       //heater is off
#define HEATER_START        1       //control is in start sequencer
#define HEATER_RUNNING      2       //heater is on
#define HEATER_SHUTDOWN     3       //heater is in shut-down sequence
#define HEATER_HOLD         4       //logic waits for trigger to show low before moving to OFF state
//
#define ST_IGNITER          0       //start sequence: turn on the igniter
#define ST_FAN              1       //start sequence: turn on the fan
#define ST_FUEL             2       //start sequence: turn on the fuel
#define ST_STABILIZE        3       //start sequence: turn on the allow heater to stablize and unburnt fuel/fumes to burn off
//
#define SH_FUEL             0       //shutdown sequence: turn off fuel
#define SH_IGN              1       //shutdown sequence: turn off ignition
#define SH_FAN              2       //shutdown sequence: turn off turn off fan

void setup() 
{
    pinMode( pinFanRelay, OUTPUT );             //set fanRelay as OUTPUT
    pinMode( pinIgnRelay, OUTPUT );             //set ignRelay as OUTPUT
    pinMode( pinFuelRelay, OUTPUT );            //set fuelRelay as OUTPUT
    pinMode( pinTrigger, INPUT_PULLUP );        //set trigger as INPUT
    
    Serial.begin(9600);
                
}//setup

void loop() 
{
    //just call the heater control state machine
    HeaterControl();
    
}//loop

void HeaterControl( void )
{
    unsigned long
        tNow;
    static unsigned long
        tHeater;
    static byte
        Seq,
        stateHeater = HEATER_OFF;
        
    switch( stateHeater )
    {
        case    HEATER_OFF:
            //heater is off now; is trigger active?
            if( digitalRead( pinTrigger ) == HIGH )
            {
                //yes; prep start sequencer and move to start state
                Seq = 0;
                stateHeater = HEATER_START;
                
            }//if
            
        break;

        case    HEATER_START:
            //get the time now
            tNow = millis();
            switch( Seq )
            {
                case    ST_IGNITER:
                    //turn on the ignition relay
                    digitalWrite( pinIgnRelay, HIGH );
                    //set a timer and move to the next step in the start sequence
                    tHeater = tNow;
                    Seq++;
                    
                break;

                case    ST_FAN:
                    //when the appropriate delay has elapsed...
                    if( tNow - tHeater >= KT_START_DLY )
                    {
                        //turn on the fan
                        digitalWrite( pinFanRelay, HIGH );
                        //set a time and move to next step
                        tHeater = tNow;
                        Seq++;
                        
                    }//if
                        
                case    ST_FUEL:
                    //when the appropriate delay has elapsed again...
                    if( tNow - tHeater >= KT_START_DLY )
                    {
                        //turn on the fuel and move to stabilize state
                        digitalWrite( pinFuelRelay, HIGH );
                        tHeater = tNow;
                        Seq++;
                        
                    }//if
                                        
                break;

                case    ST_STABILIZE:
                    //allow the heater to run for a minimum time
                    if( tNow - tHeater >= KT_MIN_RUN_DLY )
                    {
                        //before moving to running state
                        stateHeater = HEATER_RUNNING;
                        
                    }//if
                
                break;
                
            }//switch
            
        break;

        case    HEATER_RUNNING:
            //heater is on now; is trigger low indicating shut-down?
            if( digitalRead( pinTrigger ) == LOW )
            {
                //set up to sequence shut-down and move to that state
                Seq = 0;
                stateHeater = HEATER_SHUTDOWN;
                
            }//if
            
        break;

        case    HEATER_SHUTDOWN:
            //similar to start sequencing, we sequence the shut down
            tNow = millis();
            switch( Seq )
            {
                case    SH_FUEL:
                    //first shut off the fuel
                    digitalWrite( pinFuelRelay, LOW );
                    tHeater = tNow;
                    Seq++;
                
                break;

                case    SH_IGN:
                    //then turn off the igniter
                    if( tNow - tHeater >= KT_START_DLY )
                    {
                        digitalWrite( pinFanRelay, LOW );
                        tHeater = tNow;
                        Seq++;
                        
                    }//if
                break;
                
                case    SH_FAN:
                    //and finally the fan
                    if( tNow - tHeater >= KT_STOP_DLY )
                    {
                        //fan runs for an extended time after shutdown
                        digitalWrite( pinFanRelay, LOW );
                        stateHeater = HEATER_HOLD;
                        
                    }//if

                break;
                
            }//switch
            
        break;

        case    HEATER_HOLD:
            //ensure trigger shows "off" before moving to OFF state again
            if( digitalRead( pinTrigger ) == LOW )
                stateHeater = HEATER_OFF;
                
        break;
        
    }//switch
    
}//HeaterControl

This does no safety stuff and follows what I think your logic was. Compiles, not tested, safety first, YMMV etc...

You also need to know any regulations relating to the heater, such as approvals , and whether it is legal in your area to change parts which may relate to safety .

Thanks Guys the state machine function was what I was looking for.