Problem with delay

Hello, i'm working a simple project using sensor Ping to control two relays that connected to heater and UV light.

so if we put hand in front of sensor, blower and UV light will turning ON at the same time, otherwise will off.

i want to modify the sketch

there must be a delay 4 seconds between UV and blower, so first UV will on, wait 4 second, and blower will on.

but there is a problem. when no longer hand in front of the sensor, UV and blower also turning off in 4 seconds delay.

i want to make the UV and blower turn on with delay, but i want to make them off at the same time.

here is the sketch

//------------ultrasonic----------
int trigPin = 7;                
int echoPin = 8;                
//-----------motor---------------
int uv = 11;  
int led1 = 12;
int motor  = 13;       

void setup() {   
  Serial.begin (9600);
 //-----------ultraxonic---------------
  pinMode(trigPin, OUTPUT);   
  pinMode(echoPin, INPUT);    
  //-------------motor-------------------
  pinMode(uv, OUTPUT); 
  pinMode(led1, OUTPUT);  
  pinMode(motor, OUTPUT);   
}

void loop() {   
  //----------------ultasonic---------------
  long duration, distance;    
  digitalWrite(trigPin, LOW);  
  delayMicroseconds(4); 
  digitalWrite(trigPin, HIGH);  
  delayMicroseconds(50); 
  delayMicroseconds(4); 
  digitalWrite(trigPin, LOW);   
  duration = pulseIn(echoPin, HIGH);  
  distance = (duration/2) / 29;  
  if (distance >= 2 && distance <= 20){  
//   Serial.println("Out of range");
//-------------motor----------------
    digitalWrite(uv,HIGH);
    delay(4000);
    digitalWrite(motor,HIGH);   
  }
  
  else { 
    digitalWrite(motor,LOW);   
    digitalWrite(uv,LOW);    
       
  }   
}

The first thing to do is to stop using delay() because it freezes the Arduino for the period of the delay(). Instead use millis() for timing so that the program can run freely whilst doing things at a specified time.

The simplest example of this is shown in the BlinkWithoutDelay example in the IDE with extended examples in Several things at the same time.

Basically, save the millis() value at the time that the start action happens. Then, each time through loop(), check whether the required wait period has elapsed by subtracting the start time from the millis() value now. If the period has elapsed then act accordingly and maybe save the start time for the next activity. If not, then go round loop() again, perhaps taking other actions and/or reading inputs, but don't block the free running of loop()