analog fan control converting to digital -coding alternation

Hello
I need some help with coding to convert an old analog knob switch for industrial fan into digital. I am new to forum. I create coding for 4 relays to control 4 function of old fan controller .I used tutorials and other resources to write code for the functions .
I can control 4x relays individually, but I need them work in certain way :
As I mention earlier fan have 3 speeds , and one more function controlling plates :in/out

I want it done this way :
When relay1 is High only than rest of the function works :relay2,3,4,
also I need when relay1 works relay 2,3 does not ,only one at the time as relays will be switching main power form 200V ,208V to 250V and they can not be on at the same time

I am including basic coding I have wrote using forum and little understanding of examples of your :

// constant wont change
// pin set
int pinButton1 =2;//address of the first push button
int pinButton2 =3;
int pinButton3 =4;
int pinButton4 =5;

int RELAY1 = 8; // address of relay coresponding to button one
int RELAY2 = 9;
int RELAY3 =10;
int RELAY4 =11;

int stateRELAY1 =HIGH;
int stateButton1;
int stateRELAY2 =HIGH;
int stateButton2;
int stateRELAY3 =HIGH;
int stateButton3;
int stateRELAY4 =HIGH;
int stateButton4;

long time=0;
long debounce=200;
int previous =LOW;

void setup(){
pinMode (pinButton1,INPUT);
pinMode(RELAY1,OUTPUT);
pinMode (pinButton1,INPUT);
pinMode(RELAY2,OUTPUT);
pinMode (pinButton1,INPUT);
pinMode(RELAY1,OUTPUT);
pinMode (pinButton1,INPUT);
pinMode(RELAY1,OUTPUT);

}
void loop(){

stateButton1= digitalRead(pinButton1);
if(stateButton1==HIGH&& previous==LOW&& millis()-time>debounce){
if(stateRELAY1==HIGH){
stateRELAY1=LOW;
}else{
stateRELAY1=HIGH;
}
time=millis();

}
digitalWrite(RELAY1,stateRELAY1);
previous==stateButton1;

stateButton2= digitalRead(pinButton2);
if(stateButton2==HIGH&& previous==LOW&& millis()-time>debounce){
if(stateRELAY2==HIGH){
stateRELAY2=LOW;
}else{
stateRELAY2=HIGH;
}

time=millis();
}
digitalWrite(RELAY2,stateRELAY2);
previous==stateButton2;

stateButton3= digitalRead(pinButton3);
if(stateButton3==HIGH&& previous==LOW&& millis()-time>debounce){
if(stateRELAY3==HIGH){
stateRELAY3=LOW;
}else{
stateRELAY3=HIGH;
}
time=millis();

}
digitalWrite(RELAY3,stateRELAY3);
previous==stateButton3;

stateButton4= digitalRead(pinButton4);
if(stateButton4==HIGH&& previous==LOW&& millis()-time>debounce){
if(stateRELAY4==HIGH){
stateRELAY4=LOW;
}else{
stateRELAY4=HIGH;
}
time=millis();

}
digitalWrite(RELAY4,stateRELAY4);
previous==stateButton4;
}

for any help I will be grateful!!

I hope you are not thinking of using the cheap Chinese relays you can buy from the internet. The relays will only work for a short time. But the real problem is the circuit board traces and connections are not at all suitable for AC voltage you are using.

Paul

Hi ,Thank you for the answer .Yes I am using set of 4xrelays which I have bought on Amazon .I can upgrade them no problem ,connection cabling I can select adequate to current carried (MAX2.5A) not taking into account inrush current .
At current moment I have no load connected , I struggle with coding .Any help will be appreciate :confused:

Artur0215:
Hi ,Thank you for the answer .Yes I am using set of 4xrelays which I have bought on Amazon .I can upgrade them no problem ,connection cabling I can select adequate to current carried (MAX2.5A) not taking into account inrush current .
At current moment I have no load connected , I struggle with coding .Any help will be appreciate :confused:

I am referring to the traces on the printed circuit board no being suitable for more than about 24 VAC.

Paul