Help: relay on schedule


I'd like to know how to control a relay on a schedule, at some specific time, for example: starts at 7:55:00 and ends at 7:59:23.
I'm using Arduino Yun and process is used to get the date online.

Any help is welcome.

Thanks in advance.

Set a flag to tell you whether your relay was set on or off.
Run a loop. Test for time and if it is greater than start time && less than stop time and relay is off, turn it on and set the flag to on. If it is after start time, and the less than finish time && the relay is on you don't need to do anything.

If it is after finish time && the relay is on, turn it off, and set the flag to off.

You set the relay on or off by writing to a digital pin. The flag in effect stores the value you wrote to the pin.

Thank you!!

I understand, but I need an example, please.

Thanks again.

Look at the many things at once example at the top of the programming forum.

Check this one

However, DS1307 can be replaced by DS3231 for higher accuracy. However, this example doesn't uses yun. But you can get the concept :slight_smile:

Thanks a lot!