Servos dont rotate at the same time

I'm doing a project in which i need to rotate servos at same time but with my code they rotate one after the other i would be thankful if you guys helped me here's the code:
//Добавя се библиотеката на серво моторите


//Даваме индентифиционен номер/име на серво моторите

Servo servo1;

Servo servo2;

Servo servo3;

Servo servo4;

Servo servo5;

Servo servo6;

int val;

//Позиция на сервотата в градуси

int down = 0;

int up = 90;

void setup()

{

Serial.begin(9600); // Serial comm begin at 9600bps

//Казваме къде са включени сервотата (3-5-6-9-10-11)

servo1.attach (3);

servo2.attach (5);

servo3.attach (6);

servo4.attach (9);

servo5.attach (10);

servo6.attach (11);

}

void loop() {

servo1.write(down);

servo2.write(down);

servo3.write(down);

servo4.write(down);

servo5.write(down);

servo6.write(down);

if (Serial.available()) // if serial value is available

{

val = Serial.read();// then read the serial value

}

if(val == 'a' or val== 'b' or val == 'c' or val == 'd' or val == 'e' or val == 'f' or val == 'g' or val == 'h' or val == 'k' or val == 'l' or val == 'm' or val == 'n' or val == 'o' or val == 'p' or val == 'q' or val == 'r' or val == 'u' or val == 'v' or val == 'x' or val == 'y' or val == 'z')

{

servo1.write(up);

delay(15);

}

delay(5000);

servo1.write(down);

delay(15);

if(val == 'b' or val== 'f' or val== 'g' or val== 'h' or val== 'i' or val== 'j' or val== 'l' or val== 'p' or val== 'q' or val== 'r' or val== 's' or val== 't' or val== 'v' or val== 'w')

{

servo2.write(up);

delay(15);

}

delay(5000);

servo2.write(down);

delay(15);

if(val == 'k' or val == 'l' or val== 'm' or val== 'n' or val== 'o' or val== 'p' or val== 'q' or val== 'r' or val== 's' or val== 't' or val== 'u' or val== 'v' or val== 'x' or val== 'y' or val== 'z')

{

servo3.write(up);

delay(15);

}

delay(5000);

servo3.write(down);

delay(15);

if(val == 'c' or val == 'd' or val == 'f' or val == 'g' or val == 'i' or val == 'j' or val == 'm' or val == 'n' or val == 'p' or val == 'q' or val == 's' or val == 't' or val == 'w' or val == 'x' or val == 'y')

{

servo4.write(up);

delay(15);

}

delay(5000);

servo4.write(down);

delay(15);

if(val == 'd' or val == 'e' or val == 'g' or val == 'h' or val == 'j' or val == 'n' or val == 'o' or val == 'q' or val == 'r' or val == 't' or val == 'w' or val == 'y' or val == 'z')

{

servo5.write(up);

delay(15);

}

delay(5000);

servo5.write(down);

delay(15);

if(val == 'u' or val == 'v' or val == 'w' or val == 'x' or val == 'y' or val == 'z')

{

servo6.write(up);

delay(15);

}

delay(5000);

servo6.write(down);

delay(15);

}

Welcome to the forum

Your topic was MOVED to its current forum category which is more appropriate than the original as it has nothing to do with Installation and Troubleshooting of the IDE

What does "Servos don't rotate at the same time" means?

Which section of your sketch is this happening in ?

I note your frequent use of delay() in your code

I'm not really sure i think its in the void loop

Yes the 5000 delay is needed

You are using or but perhaps you meant to use the logical or instead ||?

See also: https://www.arduino.cc/reference/en/language/structure/boolean-operators/logicalor/

You are moving one servo, delaying 5000mS, moving the next servo, delaying another 5000mS, etc.

Rearrange the if statements so that you move all the servos, then delay the 5000mS, then move all the servos back to the down position together at the end. Get rid of the 15mS delay inside the if statements, and just add that to the 5000mS delay.

The if statements are very lengthy, shorter to do something like this:


  //if (val == 'a' or val == 'b' or val == 'c' or val == 'd' or val == 'e' or val == 'f' or val == 'g' or val == 'h' or val == 'k' or val == 'l' or val == 'm' or val == 'n' or val == 'o' or val == 'p' or val == 'q' or val == 'r' or val == 'u' or val == 'v' or val == 'x' or val == 'y' or val == 'z')
  if (strchr("abcdefghklmnopqruvxyz", val) != NULL) //checks to see if val is somewhere within the quoted text

Let's try asking the question a different way. Which movements of which servos should be at the same time ?

Im making braille alphabet with the servos for example if im pressing b 1 and 2 should pop up

By removing almost all the delays, it does work a little.

// For: https://forum.arduino.cc/t/servos-dont-rotate-at-the-same-time/1057090

// Добавя се библиотеката на серво моторите
#include <Servo.h>

// Даваме индентифиционен номер/име на серво моторите
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
Servo servo5;
Servo servo6;

int val;

//Позиция на сервотата в градуси
int down = 0;
int up = 90;

void setup()
{
  Serial.begin(9600); // Serial comm begin at 9600bps

  //Казваме къде са включени сервотата (3-5-6-9-10-11)
  servo1.attach (3);
  servo2.attach (5);
  servo3.attach (6);
  servo4.attach (9);
  servo5.attach (10);
  servo6.attach (11);

  servo1.write(down);
  servo2.write(down);
  servo3.write(down);
  servo4.write(down);
  servo5.write(down);
  servo6.write(down);
}

void loop() {
  if (Serial.available())     // if serial value is available
  {
    val = Serial.read();     // then read the serial value

    if (val == 'a' or val == 'b' or val == 'c' or val == 'd' or val == 'e' or val == 'f' or val == 'g' or val == 'h' or val == 'k' or val == 'l' or val == 'm' or val == 'n' or val == 'o' or val == 'p' or val == 'q' or val == 'r' or val == 'u' or val == 'v' or val == 'x' or val == 'y' or val == 'z')
    {
      servo1.write(up);
    }

    if (val == 'b' or val == 'f' or val == 'g' or val == 'h' or val == 'i' or val == 'j' or val == 'l' or val == 'p' or val == 'q' or val == 'r' or val == 's' or val == 't' or val == 'v' or val == 'w')
    {
      servo2.write(up);
    }

    if (val == 'k' or val == 'l' or val == 'm' or val == 'n' or val == 'o' or val == 'p' or val == 'q' or val == 'r' or val == 's' or val == 't' or val == 'u' or val == 'v' or val == 'x' or val == 'y' or val == 'z')
    {
      servo3.write(up);
    }

    if (val == 'c' or val == 'd' or val == 'f' or val == 'g' or val == 'i' or val == 'j' or val == 'm' or val == 'n' or val == 'p' or val == 'q' or val == 's' or val == 't' or val == 'w' or val == 'x' or val == 'y')
    {
      servo4.write(up);
    }

    if (val == 'd' or val == 'e' or val == 'g' or val == 'h' or val == 'j' or val == 'n' or val == 'o' or val == 'q' or val == 'r' or val == 't' or val == 'w' or val == 'y' or val == 'z')
    {
      servo5.write(up);
    }

    if (val == 'u' or val == 'v' or val == 'w' or val == 'x' or val == 'y' or val == 'z')
    {
      servo6.write(up);
    }


    delay(5000);
    servo1.write(down);
    servo2.write(down);
    servo3.write(down);
    servo4.write(down);
    servo5.write(down);
    servo6.write(down);
  }
}

The sketch in Wokwi simulation:

When you press 'b' only servo1 will move up, then there will be a 5 second delay before servo2 moves up. Follow the code through and you will see what I mean

You need a way if decoding which servos should move for each letter. This could be done with 26 if statements but would be clumsy at best, so don't do it

A suggestion. Declare a 2 dimensional array of bytes with one row for each letter of the alphabet numbered 0 to 25. In each row there will be 6 columns, one for each servo numbered 0 to 5. Put a 1 in any columns where the servo is required to move for the corresponding row letter and a zero where the servo should not move

Note that array indices start at 0 not 1 so the rows are numbered 0 to 25 and the columns are numbered 0 to 5

Define the array and post it here and I will take you through the next stage

omg bro you saved me thanks