Solved: code for automatic dust extraction system

I am building small workshop in my basement. This workshop will need a dust extraction system and i want to make a semi automatic system. I first designed one system with relays, but it became very large with the functions i want. I realized that i could reduce the hardware complexity by using arduino and i have sketched up a system.

The only thing stopping me from doing this is my complete lack of programming skills and knowledge.
I can copy and modify programs from the internet to a degree but this is way above my skill.

This is what i have so far:

P&ID Dust Collection

Schematic Dust extraction

Layout for control panel

I have tested the connections and everything seems to work (i use LEDs instead of relays for the test) and the inductive sensor seems to fit the gate, and work fine on 5V even though it is rated for 10-32V

I have written a function description of what i want

S1 Momentary switch NO
S2 Momentary switch NO
B1..5 Inductive sensor NO
H1 Lamp
H2 Lamp
K1 Relay
K2 Relay

Manual Override (yellow button)

S1 is pressed and starts manual override, dust extracting starts and lamp H1 lights up (D05, D07, D08 = High) S1 is pressed again and stops manual override, dust extract stops and lamp H1 is turned off (D05, D07, D08 = low) Under Manual Driving, the system may not be set to Auto

Auto Mode (white button)

S2 is pressed to start auto mode, lamp H2 lights up to indicate auto mode is active (D06 = High). The signal from the inductive sensor is high when all dust ports are closed and the system is in standby (DO4 = High)

Manual override overrides Auto Run, if auto mode is selected, lamp H2 will turn off (D06 = low) during manual override; the system will return to auto mode when manual override ends if the system was in auto before manual driving started.

In auto mode the dust extraction starts when signal from external inductive meter goes low (D04 = low) When running the dust extraction in auto mode lamps H1 and H2 both are lit (D05, D06, D07, D08 = High)

Power-up booting all modes off, so the dust extraction dont start in case of power loss.

Where should i begin? How is a program like this written in an elegant matter? what kind of functions is most suitabe to define the states? this is so far beyond copying a Led blink program and changing the in and output pins i dont even know where to start.

You need to capture programming skills. Forum is not like a shop where You can pick things from the shelf.
Professional people can help You at a cost of some hundred dollars per hour, summing up to thousands.

Railroader:
You need to capture programming skills. Forum is not like a shop where You can pick things from the shelf.
Professional people can help You at a cost of some hundred dollars per hour, summing up to thousands.

Is the sub forum "project guidance" not a place to ask for guidance in a project?

Guidance calls for some knowledge. Show what Yoy know so we know from what level we can start assisting You.

I got it working, minus one feature. If manual override is pressed when auto mode is active, the system does not return to auto mode when manual override is turned off. I can live with that.

int S1 = 2;         // Manual Override Pushbutton
int S2 = 3;         // Automatic Mode Pushbutton
int BB1 = 4;        // Inductive sensor
int H1 = 5;         // Manual Override and run Lamp
int H2 = 6;         // Automatic Mode Lamp
int K1 = 7;         // Motor Relay 1
int K2 = 8;         // Motor Relay 2

int MANstate = LOW;       // the current state of the Manual Override
int MANreading;           // the current reading from the Manual Override
int MANprevious = HIGH;   // the previous reading from the Manual Override

int AUTstate = LOW;       // the current state of the Auto mode
int AUTreading;           // the current reading from the Auto mode
int AUTprevious = HIGH;   // the previous reading from the Auto mode

int INDsensor;

int RUN = LOW; // Run state

// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.

long time = 0;         // the last time the output pin was toggled
long debounce = 200;   // the debounce time, increase if the output flickers

void setup()
{
  pinMode(S1, INPUT);
  pinMode(S2, INPUT);
  pinMode(BB1, INPUT);
  pinMode(H1, OUTPUT);
  pinMode(H2, OUTPUT);
  pinMode(K1, OUTPUT);
  pinMode(K2, OUTPUT); 
}

void loop()
{
  MANreading = digitalRead(S1); //Setting Manual mode with latch function

  if (MANreading == HIGH && MANprevious == LOW && millis() - time > debounce) {
    if (MANstate == HIGH)
      MANstate = LOW;
    else
      MANstate = HIGH;
      AUTstate = LOW;  //Aut mode is turned off with manual mode

    time = millis();    
  }
 
  MANprevious = MANreading;


  AUTreading = digitalRead(S2); // Setting Aut mode with latch function
  INDsensor = digitalRead(BB1); // Setting signal from inductive sensor


  if (AUTreading == HIGH && AUTprevious == LOW && MANstate == LOW && millis() - time > debounce) { //Aut mode can not be enabeled with Manual mode running
    if (AUTstate == HIGH)
      AUTstate = LOW;
    else
      AUTstate = HIGH;

    time = millis();    
  }

  AUTprevious = AUTreading;
 

   
  if (AUTstate == HIGH && INDsensor == HIGH || MANstate == HIGH) {
    
      RUN = HIGH;
  } 

    else if (AUTstate == HIGH && INDsensor == LOW || MANstate == LOW) {
    
      RUN = LOW;
  }

 
  digitalWrite(H1, MANstate);
  digitalWrite(H2, AUTstate);
  digitalWrite(K1, RUN);
  digitalWrite(K2, RUN);
  
}
int S1 = 2;         // Manual Override Pushbutton

int S2 = 3;        // Automatic Mode Pushbutton

Give the pins proper names. Names are free. Long names do not take up any more space on the Arduino. A week or a month from now you will forget which is which and you need to keep flipping back to the to to find out what K1 is.

Here is the problem...

    else

MANstate = HIGH;
      AUTstate = LOW;  //Aut mode is turned off with manual mode

Try this...

    else {
      MANstate = HIGH;
      AUTstate = LOW;  //Aut mode is turned off with manual mode
    }