How To Get the Arduino Time Library up and going

I’m working on a new arduino project at the moment and for it to work, I need the arduino to be able to tell the time. 

To make this work, I decided to use the Arduino Time Library (specifically the updated Time library). I was going to use the TimeSerial sketch. I expected this would be an easy task, and indeed it did look straight forward, with nice simple functions to call up the hours (hour()), minutes (minute()) and seconds (second()).

However, despite this, I really struggled in working out what the actual time was. And I’m not sure if it was just that it was late at night, and my brain wasn’t functioning at its fullest, but I really could not find an easy guide anywhere. After lots of trial and error I worked it out, and here, for you, is the tutorial of how to flipping get the flipping Time Library to work.

Know the software to use

I didn’t get this, but you will need to use both the Arduino IDE and Processing. For some reason I thought it was the case that you use one or the other. The Arduino IDE talks to the arduino, and Processing is responsible for getting the time.

Know the programs to run

You will need to run two programs: TimeSerial (in Arduino IDE) and SyncArduinoClock (in Processing). Get these both opened in their respective software.


Edit the Processing sketch

Now what’s going to happen, is Processing is kind of going to “jump start” the Arduino and give it the time at a certain time point. The arduino is capable of keeping time (if it has power) once it knows what the time is initially. So you need to get Processing talking on the right port. When I opened it, the line “public static final short portIndex = 0;” was set to 0, which is a bluetooth port. When you run it, it will try and talk to bluetooth, which wasn’t useful to me. But what was useful, was that in the terminal window at the bottom of Processing, it told me what was on each of the ports. Reading this I saw this line “[4] “/dev/tty.usbserial-A600bMH2″” and so changed the line of code to read “public static final short portIndex = 4;” so that it was now talking to the right port.


Start your engines (in the correct order)

This step got me for a while, you need to start your sketches running in the correct order. If you start Processing first then Arduino complains that it can’t get to the port it wants to. So, start the TimeSerial arduino sketch, in Arduino. If you open the Serial viewer, you’ll see a message that says “Waiting for sync message”. This is because it is waiting for a message from Processing.

At this point, start the SyncArduinoClock Processing sketch. A box will hopefully appear that says “Click to send time sync”. Click it.


You should now see in the Arduino serial monitor that there is a lot of weird text appearing. That is because it’s trying to count for itself, and also receiving sync messages from Processing. Go back to Processing, and stop that sketch running. And back to Arduino, and hopefully, you should be getting a nice neat print out of the date, and time every second. 

You’ll never be late for anything again.

Hope that helped someone avoid the long hours of struggle trying to understand how to get the stupid thing to work!

Tagged ,

7 thoughts on “How To Get the Arduino Time Library up and going

  1. Espen says:

    Hey man. Thanks for the tut. I too was wondering about the order of programs executing on the serial port. However, when i try to run SyncArduinoClock.pde after executing Timeserial.ino i get an error-message in processing saying “Error opening serial port COM7: Port busy”. Although the error is loud and clear, i have no solution… Any ideas? I have tried different versions of processing with no results.

  2. Matti Virta says:

    i come same proplem whit DHT!! temp/hum sensor whit processing sometime, but i tickle run button or start new processing program and working good again.i dont know why make thats but stop sketch and run again make same manytime.

  3. rjmah says:

    Maybe this is painfully obvious to Arduino coders but it took me a while to get the pde running. Up until now I’ve just used the serial monitor. I didn’t reallise Processing is a separate program:

  4. Dean Harvey says:

    I’m following the suggested startup sequence. I see the time messages in Processing, but never see any messages from Arduino indicating the time has been set.

  5. Debanjan says:

    Although the thread is quite old, but was quite helpful for me. However, I am stuck on a ending glitch.
    I tried to run processing after closing the arduino serial monitor and could see the time coming up on processing.
    However, now if I turn the arduino serial monitor on (board running ‘timeserial’), I have an error stating busy port. If I stop the processing now, I am back to square one in arduino stating ‘Waiting for a sync message’.

    Moreover, I donot see the message in the box of processing stating ‘Click to sync’

    Any help would be appreciated!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: