How to Assemble the RTC module for Your Arduino Clock Project

Assembling the RTC module for the Arduino Clock Project is fairly simple, if you have some experience soldering. If not, it’s a good opportunity to practice your skills. After the kit is assembled, you add the battery and connect it to your Arduino. Then, you set the time on the clock IC with an Arduino sketch just for this purpose.

Nine parts are in the kit:

  • Real–time clock PCB

  • Dallas Semiconductor Real Time Clock Chip (DS1307)

  • Crystal (32.768 KHz)

  • Two resistors (2.2k ohm)

  • Capacitor (100 nF)

  • Header (male 5 pin)

  • Battery (CR1220)

  • Battery holder

The RTC module has excellent assembly documentation and photographs online, and you can solder it fairly quickly. The printed circuit board (PCB) of the kit is labeled with the locations where all the components should be placed. Solder them in the following order:

  1. Solder a little bead of solder onto the battery solder pad, so that there is be good contact between the button cell and the pad on the PCB.

  2. Solder the resistors (R1 and R2) in place.

    The orientation of the leads does not matter.

  3. Add the capacitor (C1) and the crystal (Q1).

    Again, the orientation of the leads does not matter.

  4. Add the DS1307 Integrated Circuit (IC).

Make sure that the little notch in the IC is pointing downward, and matches the printed outline on the PCB. If you solder it on the wrong way, it won’t work at all, and it is a big pain to remove it!

  1. Solder the chrome battery holder in position.

  2. Insert the male header pins into a breadboard and place the RTC module on top of them to make it easier to solder them in place.

    The header pins should be on the underside of the board, so that the short ends of the pins are just sticking up through the printed side of the PCB.

Now that you have completed soldering, you can insert the battery, with the positive side facing up. Make sure you have a battery in the RTC or it won’t work correctly and you won’t be able to program it.

With the battery inserted, it’s time to wire up the RTC to your Arduino so that you can program it with the correct time. Make the following connections:

  1. Create a ground rail and a power rail on your breadboard by connecting your Arduino’s +5V and GND pins to the long columns of pins on the sides of the breadboard.

  2. Connect the ground pin (GND) to your ground rail.

  3. Connect the 5v pin on your RTC to +5V power rail.

  4. Connect the pin labeled SDA to Analog Pin 4.

  5. Connect the pin labeled SCL to Analog Pin 5.

The last pin is labeled SQW and can be used to get a square wave from the RTC chip. It’s not used on the clock, so you can ignore it.

image0.jpg

After the module is connected, it’s time to program it with the correct time. This is done with an Arduino library called RTClib, provided by Adafruit Industries, for the kit. You can download the library from the Adafruit Industries’ website.

Arduino libraries are bundles of code that contain related procedures. After you have installed the RTC library, notice that there is a new item called RTClib in your Examples menu. Load the one called Examples→RTClib→ ds1307. This sketch conveniently sets the time on your RTC module.

The important part of this code is in setup():

 RTC.adjust(DateTime(__DATE__, __TIME__));

In this line, the RTC.adjust() function requests the system time from your computer at the time the program is compiled, just before it is sent to your Arduino. This is what sets the time on your RTC module.

If you ever want to change the time of your RTC module (say for example, after Daylight Saving Time, or if the module drifts a bit too much), you need to remove the battery for three seconds, replace it, and then rerun this sketch.

If you haven’t already done so, upload this code to your Arduino and click the Serial Monitor button in your Arduino IDE. Make sure your serial monitor is set to 57600 baud in the lower-right corner. Otherwise, you’ll just see gibberish!

image1.jpg

You can also arbitrarily set the time of the RTC module. This is a little trickier, because the time is set to UNIX system time, which is simply the number of seconds since midnight on January 1, 1970. For example, the following code sets the time to February 27, 2012, at 8:50 p.m.:

 RTC.adjust(DateTime(1330375800));

There’s a convenient website for looking up UNIX time, should you need it: www.onlineconversion.com/unix_time.htm.

After you’ve set the RTC with your system time, you are ready to get the display wired up and fired up.

  • Add a Comment
  • Print
  • Share
blog comments powered by Disqus
Advertisement

Inside Dummies.com

Dummies.com Sweepstakes

Win $500. Easy.