If I change the delay time, code not working

please help me to correct the code if i change the delay time code not working

thank you

/////M Kamran Robot Crane Hidden experiments Forbidden projects public don't care Event base Arduino program Crane assembly - YouTube

/// ///this is code for automatic crane pick and place proto type crane logic by switches and all operation with direct voltage through relay operation and AT mega try it and tell me about any findings
//with timers its working fine but when i change delay some time problem please help this model works with magnatic lifting which is energized with relay switchesthanks mail me robot78p@gmail.com

///int mode = 2; // select mode AUTO/MANUAL if HIGH=AUTO else LOW=MANUAL
///int start = 3; // select START/STOP auto mode
///int tool = 8; // tool Sw
////int modeState = 1; //modelState
////int startState = 1; //start1State
////int toolState = 1;
int sw1 = 6;
int sw2 = 7;
int sw3 = 8;
int sw4 = 9;

int relay1 = 23;
int relay2 = 25;
int relay3 = 27;
int relay4 = 29;
int relay5 = 31;
int relay6 = 33;
int relay7 = 35;
int relay8 = 37;

int sw1Status, sw2Status, sw3Status, sw4Status;
int order = 1; //default is to set relays1 on .
int counter=0; //add exp

int sw1PushCounter = 1; // counter for the number of button presses
///int sw2Status = 0; // current state of the button
int lastsw1Status = 1; // previous state of the button
int sw2PushCounter = 1; // counter for the number of button presses
///int sw2Status = 0; // current state of the button
int lastsw2Status = 1; // previous state of the button

int sw3PushCounter = 1; // counter for the number of button presses
///int sw3Status = 0; // current state of the button
int lastsw3Status = 1; // previous state of the button
int sw4PushCounter = 1; // counter for the number of button presses
///int sw4Status = 0; // current state of the button
int lastsw4Status = 1; // previous state of the button
int count = 0;
int start;
int tool;
//// ///////for counter ////////////////////////////////////////////////

void setup() {
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
pinMode(relay4, OUTPUT);
pinMode(relay5, OUTPUT);
pinMode(relay6, OUTPUT);
pinMode(relay7, OUTPUT);
pinMode(relay8, OUTPUT);

// input pull-up, so default state of buttons is HIGH.
pinMode(sw1, INPUT_PULLUP);
pinMode(sw2, INPUT_PULLUP);
pinMode(sw3, INPUT_PULLUP);
pinMode(sw4, INPUT_PULLUP);

///pinMode(mode, INPUT_PULLUP);
///pinMode(start, INPUT_PULLUP);
///pinMode(tool, INPUT_PULLUP);
Serial.begin(9600);
}
void loop() {
// read the buttons status
sw1Status = digitalRead(sw1);
sw2Status = digitalRead(sw2);
sw3Status = digitalRead(sw3);
sw4Status = digitalRead(sw4);
///////////////////////////////////////////////////////////////////////////////////////////
///modeState = digitalRead(mode);
///startState = digitalRead(start);
///toolState = digitalRead(tool);
/////if (sw1Status == LOW && sw2Status == HIGH && sw3Status == LOW && sw4Status == LOW && toolState == HIGH) {
//////////////////////////////////////////////////////////////////////////////////////////////
if (sw1Status == LOW && sw2Status == HIGH && sw3Status == LOW && sw4Status == LOW) {order = 2;
Serial.println("order2 sw2 & rly 2 on");}
///////////////////////////////////////////////////////////////// RIGHT Working
if (sw1Status == LOW && sw2Status == HIGH && sw3Status == HIGH && sw4Status == LOW){order = 3;
Serial.println(" order3 right side move down rly 1/7/8");
if (sw2Status != lastsw2Status){if (sw2Status == HIGH){sw2PushCounter++; if (sw2PushCounter > 0){order = 4;
{sw2PushCounter=0;
Serial.println("order4 repeat move right"); }}}}}
delay(500); //added delay
//////////////////////////////////////////////////////////////// LEFT not working
if (sw1Status == LOW && sw2Status == HIGH && sw3Status == LOW && sw4Status == HIGH){order = 3;
Serial.println("order3 left side sw2/4 move down rly1/7/8");
delay(800);
if (sw2Status != lastsw2Status){if (sw2Status == HIGH){sw2PushCounter++; if (sw2PushCounter > 0){order = 2;
{sw2PushCounter=0; sw1PushCounter=0;
Serial.println("order2 repeat move left rly 2"); } }}}}
////////////////////////////////////////////////////////////////////////////
if (sw1Status == HIGH && sw2Status == LOW && sw3Status == LOW && sw4Status == HIGH) {order = 5; //
Serial.println("orde7 left side move up "); }
delay(1200);
if (sw1Status == HIGH && sw2Status == LOW && sw3Status == HIGH && sw4Status == LOW) {order = 5; // changed 1
Serial.println("orde1 right side move up "); }
///////////////////////////////////////////////////////////////
if (sw1Status == LOW
&& sw2Status == LOW && sw3Status == HIGH && sw4Status == LOW) {order = 1;
Serial.println("orde6 sw3 H right side move up "); }

if (sw1Status == HIGH && sw2Status == LOW && sw3Status == LOW && sw4Status == LOW) {order = 1;
Serial.println("orde6 sw1 H fault position "); }

if (sw1Status == LOW && sw2Status == LOW && sw3Status == LOW && sw4Status == LOW) {if (order != 4) {
Serial.println("all switch off follow order 5");
order = 1;
} else { order = 1; }}
////////////////////////////////////////////////////////////////
lastsw1Status = sw1Status;
lastsw2Status = sw2Status;
lastsw3Status = sw3Status;
lastsw4Status = sw4Status;

switch (order) {
case 1: // if order equals 1
delay(500);
digitalWrite(relay1, LOW); //up
digitalWrite(relay2, HIGH);
digitalWrite(relay3, LOW); //magnet on
digitalWrite(relay4, LOW); //magnet on
digitalWrite(relay5, HIGH);
digitalWrite(relay6, HIGH);
digitalWrite(relay7, HIGH);
digitalWrite(relay8, HIGH);
Serial.println("default start up magnet on ");
break;
case 2: // if order equals 2
delay(500);
digitalWrite(relay1, HIGH);
digitalWrite(relay2, LOW); //right
digitalWrite(relay3, LOW); //magnet on
digitalWrite(relay4, LOW); //magnet on
digitalWrite(relay5, HIGH);
digitalWrite(relay6, HIGH);
digitalWrite(relay7, HIGH);
digitalWrite(relay8, HIGH);
Serial.println("move right magnet on case 2");
break;
case 3: // if order equals 3
delay(500);
digitalWrite(relay1, LOW); //power to rly 7,8
digitalWrite(relay2, HIGH);
digitalWrite(relay3, LOW); //magnet on
digitalWrite(relay4, LOW); //magnet on
digitalWrite(relay5, HIGH);
digitalWrite(relay6, HIGH);
digitalWrite(relay7, LOW); //down
digitalWrite(relay8, LOW); //down
Serial.println("move down magnet on case 3");
break;
case 4: // if order equals 4
delay(700);
digitalWrite(relay1, LOW); //up
digitalWrite(relay2, LOW); //power to rly 5,6
digitalWrite(relay3, LOW); //magnet on
digitalWrite(relay4, LOW); //magnet on
digitalWrite(relay5, LOW); //left
digitalWrite(relay6, LOW); //left
digitalWrite(relay7, HIGH);
digitalWrite(relay8, HIGH);
Serial.println("move right to left magnet on case 4");
break;
case 5: // if order equals 5
delay(300);
digitalWrite(relay1, LOW); // up magnet off
digitalWrite(relay2, HIGH);
digitalWrite(relay3, HIGH);
digitalWrite(relay4, HIGH);
digitalWrite(relay5, HIGH);
digitalWrite(relay6, HIGH);
digitalWrite(relay7, HIGH);
digitalWrite(relay8, HIGH);
Serial.println("move up fail safe case 5");
break;
delay(300);
default: // if none of above cases is valid go to case 1
order = 1;
break;}

}

You hijacked someone else's thread. Why didn't you start your own topic? Please put your code in code tags as the forum guidelines ask, and request that a moderator split your topic into your own thread.

We are in code tag inception!! :joy:

Please don't hijack threads @kamran78p. I have split your post out to its own topic.

Hijacking is against the Arduino forum rules. The reason is that it may sidetrack the discussion, even preventing the creator of the topic from getting the assistance they need.

This is basic forum etiquette, as explained in the "How to get the best out of this forum" guide. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

switch case logic with relay magnet limit switch and motors
facing problem to correct the code
/////M Kamran Robot Crane Hidden experiments Forbidden projects public don't care Event base Arduino program Crane assembly - YouTube

/// ///this is code for automatic crane pick and place proto type crane logic by switches and all operation with direct voltage through relay operation and AT mega try it and tell me about any findings
//with timers its working fine but when i change delay some time problem please help this model works with magnatic lifting which is energized with relay switchesthanks mail me robot78p@gmail.com

///int mode = 2; // select mode AUTO/MANUAL if HIGH=AUTO else LOW=MANUAL
///int start = 3; // select START/STOP auto mode
///int tool = 8; // tool Sw
////int modeState = 1; //modelState
////int startState = 1; //start1State
////int toolState = 1;
int sw1 = 6;
int sw2 = 7;
int sw3 = 8;
int sw4 = 9;

int relay1 = 23;
int relay2 = 25;
int relay3 = 27;
int relay4 = 29;
int relay5 = 31;
int relay6 = 33;
int relay7 = 35;
int relay8 = 37;

int sw1Status, sw2Status, sw3Status, sw4Status;
int order = 1; //default is to set relays1 on .
int counter=0; //add exp

int sw1PushCounter = 1; // counter for the number of button presses
///int sw2Status = 0; // current state of the button
int lastsw1Status = 1; // previous state of the button
int sw2PushCounter = 1; // counter for the number of button presses
///int sw2Status = 0; // current state of the button
int lastsw2Status = 1; // previous state of the button

int sw3PushCounter = 1; // counter for the number of button presses
///int sw3Status = 0; // current state of the button
int lastsw3Status = 1; // previous state of the button
int sw4PushCounter = 1; // counter for the number of button presses
///int sw4Status = 0; // current state of the button
int lastsw4Status = 1; // previous state of the button
int count = 0;
int start;
int tool;
//// ///////for counter ////////////////////////////////////////////////

void setup() {
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
pinMode(relay4, OUTPUT);
pinMode(relay5, OUTPUT);
pinMode(relay6, OUTPUT);
pinMode(relay7, OUTPUT);
pinMode(relay8, OUTPUT);

// input pull-up, so default state of buttons is HIGH.
pinMode(sw1, INPUT_PULLUP);
pinMode(sw2, INPUT_PULLUP);
pinMode(sw3, INPUT_PULLUP);
pinMode(sw4, INPUT_PULLUP);

///pinMode(mode, INPUT_PULLUP);
///pinMode(start, INPUT_PULLUP);
///pinMode(tool, INPUT_PULLUP);
Serial.begin(9600);
}
void loop() {
// read the buttons status
sw1Status = digitalRead(sw1);
sw2Status = digitalRead(sw2);
sw3Status = digitalRead(sw3);
sw4Status = digitalRead(sw4);
///////////////////////////////////////////////////////////////////////////////////////////
///modeState = digitalRead(mode);
///startState = digitalRead(start);
///toolState = digitalRead(tool);
/////if (sw1Status == LOW && sw2Status == HIGH && sw3Status == LOW && sw4Status == LOW && toolState == HIGH) {
//////////////////////////////////////////////////////////////////////////////////////////////
if (sw1Status == LOW && sw2Status == HIGH && sw3Status == LOW && sw4Status == LOW) {order = 2;
Serial.println("order2 sw2 & rly 2 on");}
///////////////////////////////////////////////////////////////// RIGHT Working
if (sw1Status == LOW && sw2Status == HIGH && sw3Status == HIGH && sw4Status == LOW){order = 3;
Serial.println(" order3 right side move down rly 1/7/8");
if (sw2Status != lastsw2Status){if (sw2Status == HIGH){sw2PushCounter++; if (sw2PushCounter > 0){order = 4;
{sw2PushCounter=0;
Serial.println("order4 repeat move right"); }}}}}
delay(500); //added delay
//////////////////////////////////////////////////////////////// LEFT not working
if (sw1Status == LOW && sw2Status == HIGH && sw3Status == LOW && sw4Status == HIGH){order = 3;
Serial.println("order3 left side sw2/4 move down rly1/7/8");
delay(800);
if (sw2Status != lastsw2Status){if (sw2Status == HIGH){sw2PushCounter++; if (sw2PushCounter > 0){order = 2;
{sw2PushCounter=0; sw1PushCounter=0;
Serial.println("order2 repeat move left rly 2"); } }}}}
////////////////////////////////////////////////////////////////////////////
if (sw1Status == HIGH && sw2Status == LOW && sw3Status == LOW && sw4Status == HIGH) {order = 5; //
Serial.println("orde7 left side move up "); }
delay(1200);
if (sw1Status == HIGH && sw2Status == LOW && sw3Status == HIGH && sw4Status == LOW) {order = 5; // changed 1
Serial.println("orde1 right side move up "); }
///////////////////////////////////////////////////////////////
if (sw1Status == LOW
&& sw2Status == LOW && sw3Status == HIGH && sw4Status == LOW) {order = 1;
Serial.println("orde6 sw3 H right side move up "); }

if (sw1Status == HIGH && sw2Status == LOW && sw3Status == LOW && sw4Status == LOW) {order = 1;
Serial.println("orde6 sw1 H fault position "); }

if (sw1Status == LOW && sw2Status == LOW && sw3Status == LOW && sw4Status == LOW) {if (order != 4) {
Serial.println("all switch off follow order 5");
order = 1;
} else { order = 1; }}
////////////////////////////////////////////////////////////////
lastsw1Status = sw1Status;
lastsw2Status = sw2Status;
lastsw3Status = sw3Status;
lastsw4Status = sw4Status;

switch (order) {
case 1: // if order equals 1
delay(500);
digitalWrite(relay1, LOW); //up
digitalWrite(relay2, HIGH);
digitalWrite(relay3, LOW); //magnet on
digitalWrite(relay4, LOW); //magnet on
digitalWrite(relay5, HIGH);
digitalWrite(relay6, HIGH);
digitalWrite(relay7, HIGH);
digitalWrite(relay8, HIGH);
Serial.println("default start up magnet on ");
break;
case 2: // if order equals 2
delay(500);
digitalWrite(relay1, HIGH);
digitalWrite(relay2, LOW); //right
digitalWrite(relay3, LOW); //magnet on
digitalWrite(relay4, LOW); //magnet on
digitalWrite(relay5, HIGH);
digitalWrite(relay6, HIGH);
digitalWrite(relay7, HIGH);
digitalWrite(relay8, HIGH);
Serial.println("move right magnet on case 2");
break;
case 3: // if order equals 3
delay(500);
digitalWrite(relay1, LOW); //power to rly 7,8
digitalWrite(relay2, HIGH);
digitalWrite(relay3, LOW); //magnet on
digitalWrite(relay4, LOW); //magnet on
digitalWrite(relay5, HIGH);
digitalWrite(relay6, HIGH);
digitalWrite(relay7, LOW); //down
digitalWrite(relay8, LOW); //down
Serial.println("move down magnet on case 3");
break;
case 4: // if order equals 4
delay(700);
digitalWrite(relay1, LOW); //up
digitalWrite(relay2, LOW); //power to rly 5,6
digitalWrite(relay3, LOW); //magnet on
digitalWrite(relay4, LOW); //magnet on
digitalWrite(relay5, LOW); //left
digitalWrite(relay6, LOW); //left
digitalWrite(relay7, HIGH);
digitalWrite(relay8, HIGH);
Serial.println("move right to left magnet on case 4");
break;
case 5: // if order equals 5
delay(300);
digitalWrite(relay1, LOW); // up magnet off
digitalWrite(relay2, HIGH);
digitalWrite(relay3, HIGH);
digitalWrite(relay4, HIGH);
digitalWrite(relay5, HIGH);
digitalWrite(relay6, HIGH);
digitalWrite(relay7, HIGH);
digitalWrite(relay8, HIGH);
Serial.println("move up fail safe case 5");
break;
delay(300);
default: // if none of above cases is valid go to case 1
order = 1;
break;}

}

1st, figure out how to use code tags.

2nd figure out how to properly describe what the code is supposed to do and write that down in a post.

3rd Add to the post what the thing does instead.

There is a pencil down below :point_down: that allows you to edit your post to include code tags

Hello
tell us the story behind the sketch.

I have merged your cross-posts @kamran78p.

Cross-posting is against the Arduino forum rules. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting can result in a suspension from the forum.

In the future, please take some time to pick the forum category that best suits the subject of your question (it should have been obvious that the "Portenta" category was not appropriate) and then only post once to that forum category. This is basic forum etiquette, as explained in the "How to get the best out of this forum" guide. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

This delay() will never be executed because it is after the 'break();' for that case.

ok thank you i will change and check again

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.