Setting the Time on the Real Time Clock


Subscribe to my Feed!

This page will show you how to set the time on the Sun Harvester Shield’s built in Real Time Clock (RTC). This method also works with other RTCs, so you may be able to use it even if you don’t have the Sun Harvester Shield.

In addition to having to set the RTC’s time when you first get it, you will also have to set it again after a period of several months because the time on all RTCs slowly drifts. The rate of that drift will differ between even identical RTCs, so it is difficult to predict how often you will have to re-set their time. Suffice it to say though that you can’t just set it and forget about it. You should probably update it at least once a year or more, but it really depends on the accuracy that you require from your sun tracker or heliostat.

If you can visually see that your sun tracker isn’t quite pointing directly at the sun anymore or that your heliostat isn’t reflecting the light quite where it used to, then it is possibly due to the time on your RTC drifting.

Downloading the Set RTC Time Program

The first thing you will need for setting the time on your RTC is a short Arduino program (cleverly named “Set_RTC_Time”) that I put together specifically for this task. Here is the download link. Set_RTC_Time.zip

Setting the Time and Date when Using the Sun Harvester Shield

Once you have downloaded the above program and opened it in the Arduino IDE, you should see the following code located near the top. Note: I will refer to these as the “Set_xx” variables throughout this documentation.

To set the time, replace the values shown in the above image (timezone, Set_Second, Set_Minute, etc) to the current time and date making note of the tips given below.

  1. Make sure the “SetTime” variable is set to zero.
  2. Here is a link where you can find your timezone if you don’t know it off hand. http://www.worldtimezone.com/daylight.html This value is only used to help you double check the time against Greenwich Mean Time, and is not stored on the RTC.
  3. I find that it is easiest to leave the Set_Second value at zero, so go ahead and skip it.
  4. When you set the Set_Minute value, add 1 minute to the current time (you’ll see why later).
  5. It is very important that you use the 24hr clock when setting the Set_Hour variable. For example, 2:00pm is instead 14:00 on the 24hr clock. Also, do not use daylight saving time.
  6. Make sure you only use the last two digits of the current year. For example, you would only put 12 for the year 2012.
  7. The Set_DayOfWeek variable isn’t typically used, but you might as well set it anyway. So set it to 1 if it’s Sunday, 2 if it’s Monday, 3 if it’s Tuesday, etc.

After you have the current time set (with one minute added), upload the program to the Arduino.

Once the upload is finished, open the Serial Monitor. You will see the RTC’s time displayed, but it will most likely be incorrect at this point.

Watch the current time on your computer closely. Remember that you added one minute. This was to give you time to upload the program and open the Serial Monitor. As soon as the current time matches the values you set in the program , push the “Next” button on the Sun Harvester Shield. This will synchronize the RTC’s date and time to the values you set in the program.

If you see the displayed time change to the values you set, then you have successfully set the time on your RTC! Don’t leave quite yet though. Make sure you read through the “Double Checking to See if the Time is Set Correctly” section near the bottom of this page first.

Setting the Time and Date without the Sun Harvester Shield

If you don’t have a Sun Harvester Shield, you can still use the method described above by doing one of two things. Your first option is to wire a button or switch to pin 12 on the Arduino to act as the “Next” button available on the Sun Harvester Shield. If you do this then you can follow the above instructions exactly.

The next option is to have the time set itself automatically (without a button) when the program is uploaded. To do so, first set the “SetTime” variable to “1”.

Next, set the “Set_xx” variables using the same tips that were given in the previous section. (You may need to use the “Set_Second” variable for this method to better compensate for how long it takes the program to upload.)

Once the variables are set, upload the program to the Arduino.

As soon as the upload is finished, set the “SetTime” variable back to “0” and upload the program again. (This is done because the time will set itself back to the “Set_xx” values every time the Arduino is reset if you leave “SetTime” set to “1”.)

When you open up the Serial Monitor in the Arduino IDE, you should see that the time has now been set. It is difficult to get the RTC time perfectly synchronized using this method, and it may take a few tries to get the upload timing right by experimenting with the “Set_xx” values. Unless you require high precision from your sun tracker or heliostat, getting the time exactly perfect isn’t absolutely necessary. Within 30 seconds should typically be fine.

Double Checking to See if the RTC Time is Set Correctly

Since it is very easy to set the time on your RTC incorrectly, it is vital that you double check it. Your sun tracker or heliostat simply will not work correctly if the time is off by a significant amount.

With the Serial Monitor still open in the Arduino IDE, you will see both your time and Greenwich Mean Time (GMT) displayed.

The link below gives the current time at Greenwich. http://wwp.greenwichmeantime.com/

Make sure you use the time in the “GMT (Standard Time)” box. Also make sure to use the “Switch to 24hr Display” option*. If GMT on your RTC matches the time given at the link, then you have set the RTC’s time correctly. If they don’t match though, then you will have to modify the “Set_xx” variables explained above and try again. The most common error is to forget to subtract one hour during daylight saving time.

*Warning! I have noticed a bug at the above link which will cause the “Switch to 24hr Display” option to revert back to the “12hr Display” option when you switch to another tab in your web browser and then come back to the page. If you see “a.m.” or “p.m.” displayed after the time, then you are viewing the time in the incorrect format. Try pressing the “Switch to…” button a few times to fix it.

Subscribe to my Feed!