Power servo's and relay at the same time

Hi,

I would like to power a relay and start a servo routine on a PIR signal. The problem is that the relay stays on until the servo routine is finished. While the relay should only be powered as long as the PIR signal is high (2 seconds). I figured it has something to do with the delay code.

#include <Servo.h>
Servo servo1; // Define our Servo
Servo servo2; // Define our Servo
Servo servo3; // Define our Servo


int pos = 0;
int pirPin = 12;
int relayPin = 4;

void setup()
{  pinMode(pirPin, INPUT);
   servo1.attach(9); // servo on digital pin 9  
   servo2.attach(10); // servo on digital pin 10
   servo3.attach(6); // servo on digital pin 6
   pinMode(relayPin, OUTPUT);
  }
     
  
void loop(){
  
  if (digitalRead(pirPin) == HIGH)
{
digitalWrite(relayPin, HIGH);
}
else {digitalWrite(relayPin, LOW);}
     

  if(digitalRead(pirPin) == HIGH){
    
    for(pos = 40; pos>= 35; pos-=1)  
    {                                                
      servo1.write(pos);                   //tells servo to go to position in variable "pos"
      delay(10);                                   //waits for the servo to reach the position
    }
      delay(5000);
   
    for(pos = 40; pos < 130; pos += 1)    
    {                               
      servo1.write(pos);                 
      delay(10);                                 
    }
    delay(2000);   
    
   for(pos = 130; pos>=40; pos-=1)  
    {                                                 
      servo1.write(pos);                   
      delay(10);                                   
    }
      delay(2000);
    for(pos = 40; pos < 130; pos += 1)    
    {                               
      servo2.write(pos);                  
      delay(10);                                  
    }
    delay(2000);
    for(pos = 130; pos>=40; pos-=1) 
    {                                                
      servo3.write(pos);                   
      delay(10);                                  
    }
      
}
}

Is there an easy way to solve this? It shouldn't be a problem if there is a delay between the PIR signal and the start of the servo routine, but there can't be any delay between PIR signal and relay powering.

Thanks.