LDR Timer Problem

So I want to use an LDR so that when its input is less than a constant for a certain amount of time, a light gets switched on. But how do I code this?

But how do I code this?

You need to determine that a state change has occurred. It is light enough now but was not last time, or it is dark enough now but wasn't last time.

You need to record WHEN the change happened.

Independently, you need to determine how long it has been since the last change of interest happened. If that was long enough ago, do something. That something might involve clearing the last event time variable, or not.

Your requirements are a long way from being well-defined.

eescashguys: So I want to use an LDR so that when its input is less than a constant for a certain amount of time, a light gets switched on. But how do I code this?

Yes, that is a common stumbling block. To code it easily, you have to rephrase it in a somewhat non-intuitive way. "less than a constant for a certain amount of time" can be understood as "not more than a constant for a certain amount of time". Thus, if you continually measure and if more than a constant, you simply record the time at which this occurred. Now, a separate task, you just see whether the difference between now and the recorded time exceeds the desired time interval.

The usual code for that, doesn't really differ from this description.

To check if something has been in a desired condition for a certain length of time you need to reset the timer every time it is NOT in that desired condition - which may seem counter-intuitive. Like this pseudo code

if (condition is wrong) {
   lastWrongMillis = millis();
}

if (millis() - lastWrongMillis >= desiredInterval) {
   condition has been correct throughout the interval
}

...R