How would I code this?

I have an Obstacle Sensor. If that sensor is LOW for given amount of time (let's say 5 seconds), it will light up a LED until that sensor senses HIGH. Really need some help with this one.

unsigned long timeElapsed = 0;
unsigned long lastTime = 0;

void loop()
{
   ...
   if (sensorValue == LOW) {
      timeElapsed += millis() - lastTime;
   } else {
      timeElapsed = 0;
   }

   if (timeElapsed >= 5000) {
      //the sensor has been low for 5s
      //do work here
      timeElapsed = 0;
   }
   lastTime = millis();
}

I'll try this. Thank you. :relaxed:

grIMAG3:
I have an Obstacle Sensor. If that sensor is LOW for given amount of time (let's say 5 seconds), it will light up a LED until that sensor senses HIGH. Really need some help with this one.

I find it is easier to implement the opposite:
When the sensor reads HIGH, turn off the LED and record the time.
If the current time is five seconds or more later than the last recorded time, turn on the LED.

    static unsigned long lastRecordedTime = 0;
    if (digitalRead(sensor) == HIGH)
    {
        digitalWrite(LEDPin, LOW); // Turn off the LED
        lastRecordedTime = millis();
    }

    if (millis() - lastRecordedTime > 5000)
        digitalWrite(LEDPin, HIGH); // Turn on the LED