Post comments on this article and find any associated files and/or downloads at
using the Arduino by itself or
with external timekeeping
devices such as the DS1307 RTC.
You can write code to get the
time and date as second, minute,
hour, day, month, and year, plus
it lets us keep time in the earlier
mentioned Unix time seconds
which is more convenient to
handle and store than traditional
date and time notations. Also, it
lets us set up alarms.
Rather than repeating all the
functions here, please refer to
.cc/Code/Time. Don’t worry if
this seems a bit much. We will
only be using a subset of what
is available, and we will keep it
as simple as possible to fulfill
our meager requirements. We
will, however, use a brand new
program (to us, anyway) that will
let us set the time on the
Arduino very accurately. This program is called Processing,
and as we will see in a moment, it looks kind of familiar.
The Processing IDE (integrated development
environment) is shown in Figure 1. Look familiar? It should
because the Arduino IDE is built from a version of
Processing. You will want to visit processing.org and take
a look at all the marvelous things Processing is used for. It
was developed initially to provide a simple set of tools so
that artists could use some of
the visual effects that were
becoming available in Java.
Fortunately, since Processing is
artist-simple to use and the
Arduino IDE is based on it, we
won’t have to learn much new
stuff. In Lab todo, we will use a
Processing module provided by
the folks that wrote the Time
library that lets us use the PC to
set the time on the Arduino.
Lab 1: Using the
Arduino Time Library
The Time library is not part
of the standard Arduino
package, so you’ll have to
download it and set it up
yourself. After downloading the
library, we will write code to let
us set the date and time.
1 Computer with Internet connection
Estimated time for this lab: 20 minutes
Check off when complete:
; You can get the Time.zip file at http://playground.
arduino.cc/Code/Time. Download this file and unzip it.
This will provide a Time directory.
; Next, find your Arduino directory (usually on drive C: —
for instance, I have Arduino 1.0.5 located at
; Copy the Time directory to the Arduino libraries
directory. Figure 2 shows my Windows Explorer with
the file copied to the correct directory. It must be in the
libraries directory for the Arduino IDE to find it.
; Next, you want to verify that the Arduino IDE can find
the Time library. Open the Arduino IDE and then click
on the Sketch/Import Library menu item. You should
see the Time library as shown in Figure 3. This verifies
that you have successfully added the library to the
; Click on ‘Time’ and it will add #include <Time.h> to
your source code as shown in Figure 4. You are now
ready to write code that will use the Time library.
; Open the File/Examples/Time/Examples/TimeSerial as
shown in Figure 5.
; In the Setup() function, change the baud rate from 9600
68 October 2014
; FIGURE 2:
Put Time in
; FIGURE 1: