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

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

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

void loop() {   
  long duration, distance;    
  digitalWrite(trigPin, LOW);  
  digitalWrite(trigPin, HIGH);  
  digitalWrite(trigPin, LOW);   
  duration = pulseIn(echoPin, HIGH);  
  distance = (duration/2) / 29;  
  if (distance >= 2 && distance <= 20){  
//   Serial.println("Out of range");
  else { 

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()