Can I jump the delay in loop? #include &lt;Servo.h&gt;
    
Servo myservo;
int pos = 0;
int servo_pin = 3;
int led_pin = 4;

void setup() {
  myservo.attach(servo_pin);
  Serial.begin(9600);
  pinMode(led_pin,OUTPUT);
}
    
void loop() {
  if (Serial.available()) {
    char serial = Serial.read();
    if (serial == '2') {
      servo();
    }
    if (serial == '1') {
      digitalWrite(led_pin,HIGH);
    } else if (serial == '0') {
      digitalWrite(led_pin,LOW);
    }       
  }
  delay(100);
}
    
void servo() {
  for (pos = 0; pos &lt;= 180; pos += 1) { 
    myservo.write(pos);             
    delay(5);                       
  }
  delay(5000);  // problem is here
  for (pos = 180; pos &gt;= 0; pos -= 1) 
    myservo.write(pos);             
  delay(5);                       
}

When I run this code, and send 2 servo functions start but there is an delay function. Now I want to send 2 then send 1. When I do this, the first servo starts but the LED starts after the servo function. I want to start this too at the same time.
Make little task using millis function.
// GLOBAL VARIABLE
uint32_t taskMillis = 0;

....

// IN LOOP
if (taskMillis &amp;&amp; millis() - taskMillis &gt;= 5000)
{ /* SWITCHES DIRECTION */ }

With that code you can make two tasks(one to switch direction, second to move Servo by X deg).
Here is video about this topic.
https://www.youtube.com/watch?v=v5SpPXMmHJE
I hope this anwser will help you.