Best way to make a Arduino Clock

So i am trying to make my first project for the arduino.

I am currently stuck trying to figure out what is the best way to make a clock. I want something that can be independent from using a computer to sync the time. i also want it to be able to change the current time with buttons on the side. Maybe a alarm.

I have no need for Day, month or year stuff (but i don't mind having it)

For most accuracy, you will need an RTC (real-time clock) chip; it is possible to do everything on the Arduino, but it will lose/gain over time as the accuracy isn’t great (and forget about anything very useful if you use the internal R/C clock).

Now - you could forgo the RTC (in theory), if you used something like a GPS receiver module to get an external time, or an ethernet/wifi shield (and coding) to pick the time off an external time server; though I am not sure if either of these “violates” your rule about not being connected to a computer to sync the time. Without using a real-time clock chip, you are going to need time syncing every now and then (at least once every day or two) to maintain the accuracy.

:slight_smile:

cool cool

Thanks... i got a ChronoDot... but till they become available at Macetech i will probably be playing with the Arduino clock even if it is imprecise

I was just checking around, and apparently there is a software RTC library for the Arduino; I think it still needs to be periodically synched with an external source, but it would at least keep you from having to reinvent the wheel:

http://www.arduino.cc/playground/Code/Time

Actually, it has a few setups for different sources; take a look - very interesting…

:slight_smile:

I would recommend you take a look at http://www.timewitharduino.blogspot.com

Lots of arduino based clocks on there :slight_smile:

Mowcius

The 16mhz crystal on my arduino is way better at keeping time than my laptop is.

void loop()
{
while(millis()%1000) { }
timestamp +=1;
ntp_display();
[snip]
}

I watched a bunch of videos on youtube and my favorite way that i saw people setting them was to have an up and a down button. Thats due to 1) I usually overshoot and 2) I am afflicted by DST

What about those clocks that automatically set their time off a satellite signal? I'm going to do some googling, those "atomic clocks" that automatically sync up with some kind of wireless signal aren't that expensive anymore. I'm assuming it's just some kind of chip inside the clock that's already programmed to get the signal, decode it, and output it to the clock. This might make things easier if it turns out to just be a simple little circuit based around a chip, there might even be breakouts already made.

I'm gonna hit google, I just figured I'd mention these in case anyone reading this already knows how to use this system.

getting time off of a Satellite usually means having an antenna outside, you might mean the low frequency time signals
http://tf.nist.gov/stations/wwv.html

Horray for lists:

The device is called CMMR-6P (datasheet here: http://www.c-max-time.com/downloads/getFile.php?id=542).
It is not satellite, it is AM radio.
It is also not very cheap (at around US$10) nor easy to use it reliably for various reasons (see this post: http://duinolab.blogspot.com/2009/06/arduino-cmmr-6p-60-almost-accurate.html).

Well I did have a GPS running a clock (before I thought of anything better to do with it and before I broke my GPS. That updated at 1Hz with the GPS. Now that was a satellite clock.
It also told me my position but that wasn't much use as the clock never moved!

Mowcius

For the clocks I've made, I handle DST in SW. With that, and a battery B/U RTC, it is seldom necessary to set the time.
When it is necessary, I just run a time set sketch. That way no time set buttons are needed.

For the clocks I've made, I handle DST in SW. With that, and a battery B/U RTC, it is seldom necessary to set the time.

Hi, BroHogan,
could you help me with this SW DST, get me some code to implement in my project?
Would be very thankfull

Now why wait as i can build some code myself. SOFTWARE DAYLIGHT SAVING DST FOR NETHERLANDS
Anyone to test this and maybe make it better. This is my first try and it seems to work OK.

#include <DS1307.h>
Loop()
{
// ++++++++++ Daylight saving cycle for Netherlands for next ten years ++++++++++ // START  2010 october
// In netherlands DST only changes at the last weekend on Sunday 02:00 in MARCH and OCTOBER,
// so days between 25 and 31 is covered by this code (it is tested and seems OK)
if (dows == 6 && mnths == 3 || mnths == 10 && hrs <1 && hrs >4)                   // DST schedule for next ten years to october 2019 condition start in march or october
 {
   DST = EEPROM.read(1060);                                                       // read Previous DST status,
    if (dows == 6 && mnths == 3 && dts >= 25 && dts <=31 && hrs == 2 && DST==0)   // time forward from 02:00 to 03:00 in march if DSt status ==0 else don't change time!
      {
        RTC.set(DS1307_HR,3);       //set the  hours to 03:00                     // when status was ZERO (0) then change time from 02:00 to 03:00 hr
        EEPROM.write(1060, 1);      // daylight saving flag                       // Write DST statusflag to ONE(1) to prevent multiple changes in hours, only for once in March
      }
    if (dows == 6 && mnths == 10 && dts >= 25 && dts <=31 && hrs == 3 && DST==1)  // time backwards from 3:00 to 02:00 in october if DSt status ==1 else don't change time!
      {
        RTC.set(DS1307_HR,2);       //set the  hours to 03:00                  
        EEPROM.write(1060, 0);      // daylight saving flag                       // Write DST statusflag to ZERO to prevent multiple changes in hours, only for once in October
      }
 }
}
// ++++++++++ Daylight saving cycle for Netherlands for next ten years ++++++++++ // END  2019 october

Since i use the DS3231 RTC, i cannot store the DST flag into the RTC. So i use the ATMEGA arduino EEPROM at location 1060!
DOWS= day of week in my case 6 is sunday, change to your DOW!
MNTHS= mounth this is only in march or october to be changed!
DTS=date, the limitation of >=25 and >=31 means there is only one case in every mounth of 31 days (march/october) where the sundays will be. and that’s the last sunday when time is changed in the netherlands!
HRS=hours, between >1 and <4 means 02:00 or 03:00 hr.

I hope it can be helpfull to change for other countries, so far i have tested it was ok for me (NETHERLANDS). Suggestions are welcome
Small comment; the DS3231 is very accurate and since last december 2009 i have 10 seconds difference with actual time. So this is a very good TRC.

#include <DS1307.h>
Loop()
{
// ++++++++++ Daylight saving cycle for Netherlands for next ten years ++++++++++ // START  2010 october
// In netherlands DST only changes at the last weekend on Sunday 02:00 in MARCH and OCTOBER,
// so days between 25 and 31 is covered by this code (it is tested and seems OK)
if (dows == 6 && mnths == 3 || mnths == 10 && hrs >1 && hrs <4)                   // DST schedule for next ten years to october 2019 condition start in march or october
 {
   DST = EEPROM.read(1060);                                                       // read Previous DST status,
    if (dows == 6 && mnths == 3 && dts >= 25 && dts <=31 && hrs == 2 && DST==0)   // time forward from 02:00 to 03:00 in march if DSt status ==0 else don't change time!
      {
        RTC.set(DS1307_HR,3);       //set the  hours to 03:00                     // when status was ZERO (0) then change time from 02:00 to 03:00 hr
        EEPROM.write(1060, 1);      // daylight saving flag                       // Write DST statusflag to ONE(1) to prevent multiple changes in hours, only for once in March
      }
    if (dows == 6 && mnths == 10 && dts >= 25 && dts <=31 && hrs == 3 && DST==1)  // time backwards from 3:00 to 02:00 in october if DSt status ==1 else don't change time!
      {
        RTC.set(DS1307_HR,2);       //set the  hours to 03:00                  
        EEPROM.write(1060, 0);      // daylight saving flag                       // Write DST statusflag to ZERO to prevent multiple changes in hours, only for once in October
      }
 }
}
// ++++++++++ Daylight saving cycle for Netherlands for next ten years ++++++++++ // END  2019 october

A small change in the code.

if (dows == 6 && mnths == 3 || mnths == 10 && hrs <1 && hrs >4)                   // DST schedule for next ten years to october 2019 condition start in march or october

Start of cycle in check DST should have been

if (dows == 6 && mnths == 3 || mnths == 10 && hrs >1 && hrs <4)                   // DST schedule for next ten years to october 2019 condition start in march or october

The code works now.

There are at least 4 questions here. I would suggest starting a thread for the one you most need help with, get the answer to that, and then move to the others when ready... again in separate threads. Note that "b" requires careful thinking, careful planning... what functions do you want in your clock?

a) How do I know what time it is?

b) How do I tell the Arduino that, and what other things do I want to tell it?

c) How do I get the Arduino to keep the time, once it has been given a start time?

d) How do I display what the Arduino thinks the time is?

===
For "c", I would recommend a real time clock (RTC) chip. There's a good one... functional, cheap, and the Arduino "wheels" have been invented....

That's in the nuelectronics datalogging shield. For about $16, you gte the RTC and a lot more.

You could go for a binary clock using a Lilypad Arduino:

a) How do I know what time it is?

b) How do I tell the Arduino that, and what other things do I want to tell it?

c) How do I get the Arduino to keep the time, once it has been given a start time?

d) How do I display what the Arduino thinks the time is?

Hi,
i forgot to mention that a DS3231 RTC is used, a very good clock, but with no memory.

A-So Time is checked with use the ds3231 library Here i got it from, and very usefull
[Here it is sold but it is also really, very easy to build your own.

B-Some variables are used to keep time in arduino, such as "hrs", keeps hour value, "dts" as day values, "mnths" as mounth value, and finally "dows" as day of week value.

C-when RTC is attached, I2C is used to get the values in the arduino.

D- to display the values, i use a lcd, which can be downloaded from the Arduino Playground - HomePage

Of course you can buy a DCF clock, what you might find usefull.
I am happy with this one, and it works great. Keep in mind that this clock is very, very accurate.

I also used the ds1307 library, this was the first clock i used, and did not change anything in the code to use the DS3231.

The link to the DS3231 code explains all, about how to get the values in arduino and keep time in arduino.

only downside is that they keep promising a break-out board, but nothing yet....

Check this out: breakout board with Atmega328 on-board :slight_smile:

Check this out: breakout board with Atmega328 on-board
Wise time with Arduino: Introducing Wiseduino+

Haha bit of advertising but I think someone was refering to the DS3231 chip rather than the DS1307 used on your wiseduino…
Not really a breakout board either :stuck_out_tongue:

someone was refering to the DS3231 chip rather than the DS1307 used on your wiseduino

It is DS3231. This is a new board.