This code is for auto generator start when the power line off and stop when the power line on

this code is for auto generator start when the power line off and stop when the power line on.i wand to add pin3 as output .when the generator started (running) heating for 5 minutes //not timed out yet; is generator status showing running?
if( digitalRead( pinGeneratorStatus ) == LOW )
{
//generator has started; disable the starter
Serial.println( "Generator running" );
Serial.println( "Starter off" );
digitalWrite( pinStarter, LOW );
digitalWrite( pinIgnition, HIGH );

            Serial.println( "** STATE IS ST_GEN_RUNNING **" );
            stateGen = ST_GEN_RUNNING;
            
        }//if

    }//else

and after that connected the load .

And when the power line on wait 5 minutes befor generator off
if( (digitalRead( pinGeneratorStatus ) == HIGH) || (digitalRead( pinLineStatus ) == LOW) )
{
//generator needs to be shut-down
//turn off the ignition
digitalWrite( pinIgnition, LOW );
Serial.println( "** STATE WILL BE ST_GEN_OFF **" );
nextState = ST_GEN_OFF; //when delay is finished, go to this state
timeGen = timeNow;
timeGenDelay = K_TIME_TURNOFF_DELAY; //shut-down delay
stateGen = ST_GEN_TIMEDELAY;

    }//if
    
break;

/*
Web Server

A simple web server that shows the value of the analog input pins.
using an Arduino Wiznet Ethernet shield.

Circuit:
Ethernet shield attached to pins 10, 11, 12, 13
Analog inputs attached to pins A0 through A5 (optional)

created 18 Dec 2009
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe

*/

#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>

//generator-related constants
#define K_TIME_IGN_TO_CRANK 2000ul //mS time from ignition on to starter
#define K_TIME_CRANK_DURATION 10000ul //mS maximum engine cranking time
#define K_TIME_CRANK_COOLDN 30000ul //mS time to allow starter to cool between attempts
#define K_TIME_TURNOFF_DELAY 15000ul //mS time after running before returning to top of state machine
#define K_MAX_START_ATTEMPTS 3 //# maximum start attempts before giving up on generator

//generator state machine state names
enum eGenStates
{
ST_GEN_OFF=0,
ST_GEN_IGNITION_ON,
ST_GEN_CRANK,
ST_GEN_MONITOR_START,
ST_GEN_RUNNING,
ST_GEN_TIMEDELAY

};

String RECIEVER;
String RECIEVER2;

byte mac =
{
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};

byte gateway = { 172, 17, 91, 1 };

IPAddress ip(172, 17, 91, 177);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);

//generator-specific
const uint8_t pinIgnition = 9; //generator ignition output (high == turn on ignition)
const uint8_t pinStarter = 7; //generator starter output (high == engage starter)
const uint8_t pinGeneratorStatus = 5; //generator running input (low == generator running)
const uint8_t pinLineStatus = 8; //AC mains status (low == mains available)

void setup()
{
Serial.begin(9600);
while (!Serial); //wait for serial monitor

Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());

//gen specific
pinMode( pinGeneratorStatus, INPUT_PULLUP ); 
pinMode( pinLineStatus, INPUT_PULLUP );        
pinMode( pinIgnition, OUTPUT );
pinMode( pinStarter, OUTPUT );

}//setup

void loop()
{
GeneratorStateMachine();
DoWebClient();

}//loop

void DoWebClient( void )
{
EthernetClient client = server.available();
int S = digitalRead( pinLineStatus );

if (client) 
{
    Serial.println("new client");
    
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) 
    {
        if (client.available()) 
        {
            char c = client.read();
            RECIEVER += c;
            // if you've gotten to the end of the line (received a newline
            // character) and the line is blank, the http request has ended,
            // so you can send a reply
            if( RECIEVER.length() < 50 ) 
                RECIEVER2 += c;

            //if( RECIEVER2.indexOf( "gen=on" ) > 0 ) 
            //    bWebSrvr_GenEnable = true;
            //else if( RECIEVER2.indexOf( "gen=off" ) > 0 ) 
            //    bWebSrvr_GenEnable = false;

            if( c == '\n' && currentLineIsBlank) 
            {
                // send a standard http response header
                client.println("HTTP/1.1 200 OK");
                client.println("Content-Type: text/html");
                client.println("Connection: close");    // the connection will be closed after completion of the response
                client.println("Refresh: 5");           // refresh the page automatically every 5 sec
                client.println();
                client.println("<!DOCTYPE HTML>");
                client.println("<html>");
                client.println("</br>");
                client.println  (" <center>");
                client.println("<font size='60%' color='black'> ");
                client.println("<table border='4'   <td align='center '> GENERATOR POWER CONTROL   </td> </table>");
                client.println(" </center>");

                client.println("</font>");
                client.println("<CENTER>");
                //client.println(" <h2> SWITCH1 <a href=\"/?gen=on\"\"> <button >  ON </button> </a> ");
                //client.println(" <a href=\"/?gen=OFF\"\"> <button >  OFF  </button> </a> ");
                client.println("</CENTER>");
    
                client.println("</br>");
                client.println(" <h2>GRID ");
                client.println("<CENTER>");

                if (S==LOW)
                    client.print("  ON ");
                else                    
                    client.print("OFF ");    

                client.println("</h2>");

                //client.println(RECIEVER2);
                client.println("</html>");
                break;
                
            }//if
            
            if (c == '\n') 
            {
                // you're starting a new line
                currentLineIsBlank = true;
                
            }//if
            else if (c != '\r') 
            {
                // you've gotten a character on the current line
                currentLineIsBlank = false;
                
            }//else
            
        }//if
        
    }//while

    delay(1);
    RECIEVER = " ";
    RECIEVER2 = " ";
    
    // close the connection:
    client.stop();
    Serial.println("client disconnected");
    
}//if                      

}//DoWebClient

void GeneratorStateMachine( void )
{
uint32_t
timeNow = millis();
static uint32_t
timeGen,
timeGenDelay;
static uint8_t
startAttempts,
nextState,
stateGen = ST_GEN_OFF;

switch( stateGen )
{
    case    ST_GEN_OFF:
        if( digitalRead( pinLineStatus ) == HIGH )
        {
            if( digitalRead( pinGeneratorStatus ) == LOW )
            {
                //if generator is already running, go to that state
                Serial.println( "** STATE IS ST_GEN_RUNNING **" );
                stateGen = ST_GEN_RUNNING;
                
            }
            else
            {    
                //proceed to start the generator
                Serial.println( "** STATE IS ST_GEN_IGNITION_ON **" );
                stateGen = ST_GEN_IGNITION_ON;
                startAttempts = 0;
                
            }//else
            
        }//if
        
    break;

    case    ST_GEN_IGNITION_ON:   
        startAttempts++;
                 
        //turn on the ignition and wait the ign-to-crank delay
        digitalWrite( pinIgnition, HIGH );
        nextState = ST_GEN_CRANK;
        timeGen = timeNow;
        timeGenDelay = K_TIME_IGN_TO_CRANK;
        stateGen = ST_GEN_TIMEDELAY;           
        
    break;

    case    ST_GEN_CRANK:
        //activate the starter motor
        Serial.println( "** STATE IS ST_GEN_CRANK **" );
        digitalWrite( pinStarter, HIGH );
        timeGen = timeNow;
        timeGenDelay = K_TIME_CRANK_DURATION;   //set max starter run time
        Serial.println( "** STATE IS ST_GEN_CRANK **" );
        stateGen = ST_GEN_MONITOR_START;            
        
    break;

    case    ST_GEN_MONITOR_START:        
        //has crank time exceeded the limit?
        if( (timeNow - timeGen) >= timeGenDelay )
        {
            //crank duration exceeded; msg for operator
            Serial.print( "Generator start unsuccessful on attempt # " ); Serial.println( startAttempts );                
            //shut off the starter and ignition                
            digitalWrite( pinStarter, LOW );
            
            if( startAttempts >= K_MAX_START_ATTEMPTS )
            {
                //generator has failed to start after max # of tries
                Serial.println( "**ERROR**: Generator failed to start!" );
                Serial.println( "Please check generator!" );                    

                //after 3rd-attempt failure, wait 30-seconds before going back to off state
                digitalWrite( pinIgnition, LOW );
                Serial.println( "** STATE WILL BE ST_GEN_OFF **" );
                nextState = ST_GEN_OFF;     //when delay is finished, go to this state
                timeGen = timeNow;
                timeGenDelay = K_TIME_CRANK_COOLDN; //cool down time delay
                stateGen = ST_GEN_TIMEDELAY;           
                                    
            }//if
            else
            {
                //allow the starter to cool and then go back for another attempt
                Serial.println( "** STATE WILL BE ST_GEN_IGNITION_ON **" );
                nextState = ST_GEN_IGNITION_ON;     //when delay is finished, go to this state
                timeGen = timeNow;
                timeGenDelay = K_TIME_CRANK_COOLDN; //cool down time delay
                stateGen = ST_GEN_TIMEDELAY;           
                
            }//else
            
        }//if
        else
        {
            //not timed out yet; is generator status showing running?
            if( digitalRead( pinGeneratorStatus ) == LOW )
            {
                //generator has started; disable the starter
                Serial.println( "Generator running" );
                Serial.println( "Starter off" );
                digitalWrite( pinStarter, LOW );

                Serial.println( "** STATE IS ST_GEN_RUNNING **" );
                stateGen = ST_GEN_RUNNING;
                
            }//if

        }//else
        
    break;

    case    ST_GEN_RUNNING:
        //look for:
        //  - generator not running (e.g. out of fuel), OR 
        //  - mains power is available
        //
        // If any case true, turn off the generator
        if( (digitalRead( pinGeneratorStatus ) == HIGH) || (digitalRead( pinLineStatus ) == LOW) )
        {
            //generator needs to be shut-down
            //turn off the ignition    
            digitalWrite( pinIgnition, LOW );
            Serial.println( "** STATE WILL BE ST_GEN_OFF **" );
            nextState = ST_GEN_OFF;         //when delay is finished, go to this state
            timeGen = timeNow;
            timeGenDelay = K_TIME_TURNOFF_DELAY; //shut-down delay
            stateGen = ST_GEN_TIMEDELAY;           
                                
        }//if
        
    break;

    case    ST_GEN_TIMEDELAY:
        if( (timeNow - timeGen) >= timeGenDelay )
            stateGen = nextState;
    break;
    
}//switch

}//GeneratorStateMachinePreformatted text

Your post was MOVED to it's current location as it is more suitable.

Could you also take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

i'm not sure what the question/problem is?

since the code wasn't posted properly using </>, i ran scripts to hopefully make the format readable.

when i tried compiling it, both mac and gateway were not defined as arrays and generated errors. so i assume there may be other errors (it couldn't have been tested if it didn't compile).

i compiled it with the ethernet code ifdef'd out since i don't have the Ethernet library.

i was partially able to simulate it using buttons for pinGenerator Status and pinLineStatus, and LEDs for pinIgnition and pinStarter.

the problem with using HIGH/LOW is it never obvious which is the active state. having enums for LineStateON and GenOn (! GenOn) would help.

i was able to partially simulate it's behavior. looks like i stumbled to the unsuccessful attempt, but saw no 2nd attempt and am not sure if there is a problem or not. (yes, there's a lot of testing that can be done on the couch before control machinery)

** STATE IS ST_GEN_IGNITION_ON **
** STATE IS ST_GEN_CRANK **
** STATE IS ST_GEN_CRANK **
Generator running
Starter off
** STATE IS ST_GEN_RUNNING **
** STATE WILL BE ST_GEN_OFF **
** STATE IS ST_GEN_IGNITION_ON **
** STATE IS ST_GEN_CRANK **
** STATE IS ST_GEN_CRANK **
Generator start unsuccessful on attempt # 1
** STATE WILL BE ST_GEN_IGNITION_ON **
** STATE IS ST_GEN_CRANK **
** STATE IS ST_GEN_CRANK **
Generator running
Starter off
** STATE IS ST_GEN_RUNNING **
** STATE WILL BE ST_GEN_OFF **
** STATE IS ST_GEN_IGNITION_ON **
** STATE IS ST_GEN_CRANK **
** STATE IS ST_GEN_CRANK **
Generator running
Starter off
** STATE IS ST_GEN_RUNNING **
** STATE WILL BE ST_GEN_OFF **

it's interesting how the ST_GEN_TIMEDELAY is generic, changing to nextState when expired (perhaps an example of clever - "clever is not good"). a single sub-function call with the parameters for the TIMEDELAY state would reduce the size of the code and make it more readable

distinct transition states would be clearer.

but i gave up trying to follow the sub-state processing (the if conditions within a state). i think GEN_MONITOR_START should be 3 separate states, not sure how many events it processes

having sub-functions for each state would make it easier to read. and i wonder if a table driven state machine with maybe 5 stimuli: pinGenerator Status, pinLineStatus (both up/down) and a timer would make this easier to implement and review (less time to develop). the tables make it clear what events are expected and what action taken

typedef enum { S0, S1, S2 } State_t;
typedef Status(*Action_t)(void*) ;

State_t smTransitionTbl [N_STATE] [N_STIM] = {
    {   S1, S2, },
    {   S0, S2, },
    {   S2, S1, },
};

Action_t smActionTbl [N_STATE] [N_STIM] = {
     {  a,  b },
     {  c, __ },
     { __,  a },
};

I USED
1-arduino uno
2-Ethernet shield

3- THE WEB PAGE IS FOR 1-TO reading state of generator on or off
and 2-to reading power line state where is on or off.
and one button for on off lamp from the web page.
4-the generator only have 1 phase 220v .
5-1 relay 5v for generator output to controlling the load.for heating and cooling the generator .and this what i want to help me to add code for this relay to heat generator 5minutes and after that digitalWrite( pinCOLANDHEAT , HIGH );
( connect the load).

And when the power line comeback(ON) digitalWrite(pinCOLANDHEAT , LOW );
and wait 5minutes
digitalWrite( pinIgnition, LOW );

6-1relay 5v for igintion.
7-1relay 5v for starter.
8-3v dc input to detection the state of power line.

Topic closed as @128asdfghj has posted this more than once both as a new topic and as a hijack. @128asdfghj will be taking a short rest from the forum to take time to consider the forum rules.