Controlling LED via relay with timer millis()

Hello!

I have done so far a little introduction with Arduino and at this point I have learn something about this pretty cool microcontroller using internet and this forum. I have learned, how connect some sensors, take read from them and control outputs. But now I have stucked with one thing- I try to use photosensor to "see" light level and control relay channel with it to turn the LED on or off. Problem is that, I need to figure out, how to use timer in this situation.
The right path must be like that:
When there is enough of light in the morning, then LED goes for 12 hours on. In the future to avoid a useless burning lights I add one more photosensor to control LED relay during ON-time but now I'm tryig to figure out, how to set up this so called "trigger sensor".
I understand, that in this case I need use millis, because I need to run other functions at the same time.
Could anybody find some time to help me? I have searched for this kind of examples on internet, but doesn't find anything useful for me. I found some similar things with buttons and tried to fit them to my project, but they doesn't worked for me.

Just to clarify your requirement:

The led comes ON in the morning if light > some threshold on an ldr
The led should then stay on for 12 hours
..... unless the light changes (according to some other threshold on another lde) in which case led goes off?

And your problem is that, since the led is on and you probably used delay(), you can't test the other sensor?

Do I understand correctly?

Exactly! Photosenros activates LED in the morning and this should stay ON no matter what light is doing outside during this time. And timer starts discounting 12 hours. After 12 hours the LED goes off. Later I add one more sensor to control the need of extra light. It should be like that:
with the morning light activates the LED channel for 12 hours. If there is not enough light (during morning or evening or very cloudy day) then other lightsensor turns the LED on.
I used first time delay() and understand that this is not an option because the other sensors and functions are also delayed. I tried to use millis(), but I can't write the right code for that.

I'm trying to build an mini greenhouse on my terrace . So there is automated watering of plants, ventilation and additional heating. It's all working. But now I'm trying to build a LED lights system for better growing of plants. Also it has a cool effect, when greenhouse is illuminated in the evening. 12 or 16 hours are good lightcycles for plants.

I'm confused there a bit, but it doesn't really matter for my understanding. Sounds like there must be a second LED to supplement the first which is already on... but never mind, the problem is to do with blocking delay()s.

The easiest way I've found to use the BlinkWithOutDelay approach, is to use the elapsedMillis library. You just create a timer (they call theirs timeElapsed in the example), set it to 0 when the sensor turns the led on and decide on the interval (they call theirs interval). If the elapsed time exceeds the interval, then do something: in your case that would be, switch the LED off.

But because the library uses a non-blocking method, you can do other stuff like read the other sensor and do what you want all the time.

There is one relay for LED lights, which is controlled via 2 photosensors. First photosensor activates possibility to turn on lights when its needed for 12 or 16 hours in the morning. So it's used for understand which time of day it is- day or night. When it's daytime, then it stays 12 or 16 hours in ON-time. The second photosensor is controlling the LED relay during this ON-time (if there is a morning light then Arduino allows to turn the lights on (first photosensor) if it's needed (second photosensor) during the day until its nighttime and plants are going to sleep. ) Its important to count down only day time, because beginning of day is shifting every morning a little bit.

But thanks for tip. I try to use this example in my project.

Unfortunately this example doesn't work for me, because ON and OFF time is exactly the same. But I need to hold ON time longer then OFF time.

So use two other variables, say onTime and offTime. When you turn it on, set interval=onTime and when you turn it off again, set interval=offTime.

But I need to shift a ONtime according to morninglight. In that case Arduino can "learn" again after electricity breaks or temporary diconnections when is daytime and when it's not. For example in 11 AM before lunch happens a break in electricity. After that Arduino starts on and photosensor is seeing, that its a daytime. It starts to count 16 hours. In 4 AM are 16 hours run out and lights goes OFF (normally they should be go off earlier, but its a learning cycle after power disconection and Arduino adobting to day and night). In 5 AM starts morning sunshine and photosensor activates. This means, that new 16 hours cycle are starting again ON and day and night cycles are normalized on next day.