Arduino Programmable Clock

Hi, I am a beginner with Arduino and I need help. I am trying to learn how to make my Arduino turn on devices at a specific time of the day, but I have not found any examples where someone can set the time on the Arduino like on a normal bedroom alarm clock. Is it possible for the user to set the time of day and to set the time when the Arduino will turn on devices without inputting that data directly on a sketch through the computer(kind of like how you would set the time on a normal bedroom alarm clock)? Is it better to use the Arduino or an RTC for the timekeeping part of this project? If so how can you do it?

Thanks in advance,
spc

Lots of examples (h/w + s/w) of Arduino alarm clocks here:

For an alarm clock, definitely use an RTC.

A RTC is ideal for timekeeping but be aware that the Arduino and RTC can drift about a minute per day. Check - Data-Logger Shield for Arduino - which is a very nice shield with SD card and RTC. The site shows all the code you need. The advantage of an RTC is that the time is kept even when the arduino reboots.

The mayor trick with doing things in time is to compare your clock with a fixed time, but not checking if they match perfectly but if the fixed time has passed allready. The easiers way to do this is to convert time to a counter that represents seconds since midnight. Then it becomes quite easy, in pseudo code:

if (breakfast == false && clockInSeconds > 7*3600L) // L makes the math long so you don't get overflows.
{
breakfast = true; // this flag is needed to prevent multiple brakfasts :wink:
do alarm ;
make sandwich peanutbutter;
etc;
}

// at beginning of day reset all flags
if (clockInSeconds < 1*60)
{
breakfast = false;
lunch = false;
etc = false;
}

Get the idea?


There are many ways to set a RTC, manually or synchronizing with a computer. You can also use a software only clock, check - Arduino Playground - Time -

Finally there is the sensor clock, in which the time is determined by the length of the day. With a sensor the moments of dawn and dusk are determined and from these two timestamps the midnightmoment is calculated. During the day the millisclock keeps globally your time. A helpfull class is my stopwatch class, which you could reset every night at midnight and which gives the millis since midnight. - Arduino Playground - StopWatchClass -

Finally there are also radio clocks like the DCF77 in Europe, you need a special HW for that and a decoding algorithm (to be found on the forum)

Hopes this helps

The mayor trick with doing things in time is to compare your clock with a fixed time, but not checking if they match perfectly but if the fixed time has passed allready. The easiers way to do this is to convert time to a counter that represents seconds since midnight. Then it becomes quite easy

Things become even more complicated when you also need to sound the alarm, and either wait for the user to press the button to stop it or stop it automatically after a timeout.