the above would set the output LOW "ON" at 21:30 but what happens if the devicearduino is powered on at 21:31.
I would only like the output to stay LOW for a couple hours and need it to turn off at lets say 05:45
I'm afraid im stuck at this point. I most concerned that the device may not be powered on exactly when the "on point" happens and miss the turn on/turn off.
It is just converting your time into seconds... then comparing the total seconds against the boundary times (also in seconds) for off and on.
So lets say you want it on at 21:30:00, and off at 05:45:00. The other way to looks at that is you want it off between 05:45:00 (time 1) and 21:30:00 (time 2).
So convert everything to seconds
unsigned long time1 = (unsigned long )(5UL * 60 * 60) + (45 * 60) + 0;
unsigned long time2 = (unsigned long )(21UL * 60 * 60) + (30 * 60) + 0;
Then in your code calculate current time (say 10:25:15) also into seconds: unsigned long current = (unsigned long )(10UL * 60 * 60) + (25 * 60) + 15;
Then
if (current > time1 && current < time 2)
// turn off
else
// turn on
EDIT: Post updated as per Oops noted in post #8 (thanks @odometer ).. just in case someone stumbles across this in future.
when my the arduino is powered on it should know somehow if it missed the turn on point and is halfway through the " on period " so go ahead and activate the output.
I need timer to come on every day at on time and off at off time. and repeat. every day. but should check if missed turn on point and handle that.
One way i found is to set a specific on time hh:mm. then set specific amount of hh:mm to run for. convert the "run hour and minutes" to a totality of seconds. then check if that many seconds has elapsed, if not then ON else OFF.
You seemed to have missed the relevance of post #12 and how the default type for arithmetic is Integer, unless you force it to be something else.
Also... your condition check needs to be aware of the fact that you are working on a 24 hour clock and therefore need to consider whether you are best to check the OFF time or the ON time, otherwise it gets complicated if you are trying to test across days.
I think the most confusing part is current < time2.
unless im not understanding something the code just simply don't work as you have presented it. The way i created in #12 is the solution to this problem.
If you can provide me with working code id be willing to try it