I want to make a code. but I can't know how I can do it.

The code what I want to make is this situation.
"When the distance is in from 100cm to 50cm for 5 seconds. I want to make a 'LOW' sign at motors."
this is my code

#include <NewPing.h>

#define MAX_DISTANCE 150 

int motor_1m1 = 7;  
int motor_2m1 = 8;  
int motor_3m1 = 9; 
 
int motor_1m2 = 11;   
int motor_2m2 = 12; 
int motor_3m2 = 13;  

NewPing sonar1(3,4, MAX_DISTANCE);  
NewPing sonar2(5,6, MAX_DISTANCE);  

void setup() {
  Serial.begin(115200); 
  pinMode(motor_1m1, OUTPUT); 
  pinMode(motor_2m1, OUTPUT);
  pinMode(motor_3m1, OUTPUT);  

  pinMode(motor_1m2, OUTPUT);  
  pinMode(motor_2m2, OUTPUT);
  pinMode(motor_3m2, OUTPUT); 
  
}

void loop() {
  unsigned int uS1 = sonar1.ping_median(); 
  int value1 = uS1 / US_ROUNDTRIP_CM;
  unsigned int uS2 = sonar2.ping_median(); .
  int value2 = uS2 / US_ROUNDTRIP_CM; 

if(value1 >= 100){  
   digitalWrite(motor_1m1, LOW);
   digitalWrite(motor_2m1, LOW);
   digitalWrite(motor_3m1, LOW);
   
  } 

    else if(value1 >=50 && value1 < 100) {
   digitalWrite(motor_1m1, LOW);
   digitalWrite(motor_2m1, LOW);
   digitalWrite(motor_3m1, HIGH);
  
  }
  else if(value1 >=30 && value1 < 50) 
 {
   digitalWrite(motor_1m1, LOW);
   digitalWrite(motor_2m1, HIGH);
   digitalWrite(motor_3m1, HIGH);
   
  }
  else if(value1 >=1 && value1 < 30) 
 {
   digitalWrite(motor_1m1, HIGH);
   digitalWrite(motor_2m1, HIGH);
   digitalWrite(motor_3m1, HIGH);
 
  }

  if(value2 >= 100)  
 {
   digitalWrite(motor_1m2, LOW);
   digitalWrite(motor_2m2, LOW);
   digitalWrite(motor_3m2, LOW);
   
  } 
   else if(value2 >=50 && value2 <100) 
 {
   digitalWrite(motor_1m2, LOW);
   digitalWrite(motor_2m2, LOW);
   digitalWrite(motor_3m2, HIGH);
   
  }
  else if(value2 >=30 && value2 < 50) 
 {
   digitalWrite(motor_1m2, LOW);
   digitalWrite(motor_2m2, HIGH);
   digitalWrite(motor_3m2, HIGH);
   
  }
  else if(value2 >=1 && value2 < 30) 
 {
   digitalWrite(motor_1m2, HIGH);
   digitalWrite(motor_2m2, HIGH);
   digitalWrite(motor_3m2, HIGH);
  
  }

 {
  Serial.print("value1: ");
  Serial.print(uS1 / US_ROUNDTRIP_CM); 
  Serial.println("cm"); 
  delay(500); 
  Serial.print("value2: "); 
  Serial.print(uS2 / US_ROUNDTRIP_CM); 
  delay(500);
 }

You need to use the function millis() to measure the time (5 seconds).

oh! I'll try it tomorrow and I'll reply. Thank you luisilva.

You need to record when the value first becomes in the range. You need to clear that time when the value goes out of range. You need to determine, on each pass through loop(), whether there is a value in range, and how long it has been since that value became in range (that is now - then, where then is the time that the value went into the range). If sufficient time has passed (now - then >= threshold), do whatever needs doing.