กลับไปหน้ารวมไฟล์
the-worlds-most-accurate-7-time-zone-clock-441ffb-en.md

Idea and Motivation

One day while listening to longwave radio using a software defined radio I stumbled on a signal on 77KHz. I had no idea what it was but listening for a short while it became evident that it was some sort of time signal. This was quickly confirmed with a Google search. The time signal is called DCF77 and is transmitted near Frankfurt, Germany (see Wikipedia article). It can be received easily in Western Europe.

Being an Arduino geek I soon started to wonder if there were modules out there that receive this signal so that I could easily build a self-setting, always perfectly-on-time, atomic clock accurate clock :-). And, sure enough, there are!

Like most folks I have plenty of time-keeping pieces around me, so a simple clock was not going to be very useful or exciting to build for me. However, I work in IT and interact daily with colleagues in locations in the US, Europe and APAC. Working mostly from home during the COVID-19 pandemic I thought it would be really useful to build a multi-time zone clock so that I could just glance up from my computer screen to see what time it is in the time zones of colleagues I am speaking to. Sure, it is easy to look this up on the Internet or set up additional time zones in the Windows clock but it is far more useful to have an independent, dedicated device for this. I also have family spread a bit about the globe so including their time zones was also going to be useful.

Here is a demo video without sound (I am currently working on sound effects for it - updated video coming soon).

Features

Rather than simply build a clock that boringly shows the different times, I thought it would be more challenging and fun to add animations and other useful features. Here are the most notable:

  • Power-on "bulb test" animation followed by random signs appearing and fading away making it look like the device is "thinking" while acquiring the DCF77 time which takes about 2 minutes
  • Turning the rotary encoder adjusts the luminosity of the 7-segment LED digits (7 different levels)
  • Pushing the button on the rotary encoder displays the local date (in YYYY.MM.DD format) and time. This automatically goes away after 10 seconds or immediately if the button is pushed a second time before the 10 seconds expire.
  • When the 7 time zones re-appear after displaying the local date and time, there do so in one of 7 different animations. For example, the times appear segment-by-segment from the center outwards, or from the left to the right, or with random segments appearing until they have all appeared, etc. See video below to see these animations in action.
  • During local business hours on weekdays, the times flash in five different randomly-selected animations at the top of the hour and 30 minutes into the hour. This is to remind me as most meetings I attend start at the top of the hour or 30 minutes into the hour.

Code Highlights & Other Topics

I wrote the code so that hopefully it is very easy for others to implement the clock with fewer or more time zones. All of the functions that display time, perform the animations, etc. should not require any updating as they all rely on global constants defined at the beginning of the code.

In order to more easily code the animations/transitions I am using an array to keep track of what is currently shown in each digit (a "display memory") and a separate array with what I want to show. Most of the animations refer to these two arrays to transition the displays from the current state to the new desired state.

In my setup I made the center display show my local time zone (constant localTimezone indicates which display has the local time zone) but obviously this could be any of the displays. I recommend using an odd number of displays (3, 5, 7 in my case, 9 or more).

I purposefully chose the Arduino Mega 2560 because it has many digital pins. An Arduino Uno should work if fewer displays are needed (3 or 5) but it didn't have enough pins for my build of 7 time zones.

Note that powering a couple of 7-segment displays with the 5V output from the Arduino will work but should not be tried with more 7-segment displays as they will draw more current than the Arduino can provide and you will risk damaging the Arduino. In my case I have chosen to power all of the 7-segment displays separately. Having the clock and data lines of many 7-segment displays connected to the Arduino is not a problem though because the Arduino will send commands to each one, one at a time, so utilizing all of the available pins to connect many more displays should not pose a risk.

Also, the consumption of LEDs used to light up the time zone labels adds up quickly (7 of them in my case). Since these are powered directly by the Arduino digital pins you can quickly reach the maximum that the Arduino can provide. 7 posed no issues for me but more may be too much so this should be factored in.

Global NTP Infrastructure: Multi-Time Zone Clock

Most Arduino clock projects rely on a physical $2 DS3231 RTC Module. That module is decent, but it will eventually drift 2 minutes over 3 years. This project uses a DCF77 receiver for atomic-clock accuracy in Western Europe. For a global, Internet-based approach, one could use an ESP8266 to abandon physical crystal oscillators entirely. It mathematically interrogates the United States NIST (National Institute of Standards and Technology) atomic clocks floating in space over the Internet via NTP UDP packet exchanges.

The Deep NTP UDP Execution Protocol

Such an Internet-based solution would rely on network socket engineering.

  1. The ESP8266 (WiFiManager) logs into your home router.
  2. It sends a UDP (User Datagram Protocol) byte array across the planet to pool.ntp.org precisely on port 123.
  3. The server replies with a 48-byte packet containing the exact UNIX Epoch time (Seconds passed since January 1st, 1970).
  4. The Epoch Math: The Arduino extracts the seconds value!
    timeClient.update();
    unsigned long epochTime = timeClient.getEpochTime();
    int currentHour = (epochTime % 86400L) / 3600;

Calculating Global TZ Offsets (Arrays)

A clock is useless if it only outputs raw UTC (London Time) to the user.

  • The project would run a display specifically split into separate geographic sectors (New York, Tokyo, Sydney, etc.).
  • The programmer creates an Offset Array!
    int zoneOffsets[7] = { -5, +9, +10 ... }; // Hours off from UTC!
  • The Execution Trap: You cannot just add hours trivially. If UTC is 22:00 and you add Tokyo's +9 hours, the code calculates 31:00, which forces an instant visual breakdown!
  • You must execute strict Modulo division:
    int tokyoHour = (currentHour + zoneOffsets[1]) % 24;
    if (tokyoHour < 0) { tokyoHour += 24; } // Math for fixing negative hours going backward!
  • The microcontroller would then blast all perfectly formatted atomic time strings onto the display matrix simultaneously!

Atomic Sub-Systems Layout (Alternative Design)

For an Internet-based version:

  • ESP8266 NodeMCU or ESP32 (A standard Uno cannot access Wi-Fi).
  • Large I2C 128x64 OLED (SSD1306), or a SPI TFT Display to organize all geographical time zones on screen.
  • <NTPClient.h> Library and <WiFiUdp.h> Library.

OLED Display Example

Schematic

I could not find the DCF77 receiver module in the Fritzing parts catalog and have not spent the time to learn how to create a new part yet. However, the module is super easy to connect to the Arduino. It can be powered directly with the 5 VDC out of the 12VDC to 5VDC converter. Its third pin is the signal pin (labeled "SIG") which should be connected to digital pin 2 of the Arduino.

Also, the breadboard view I have included is not super useful since it is so crowded with connections and I haven't spent the time to prepare a clean schematic. However, the connections are very straight forward and can easily be found by looking at the code which is well commented.

Alternatives

For folks living outside of DCF77 reception range (Western Europe), you might be able to use other time signals with an adequate receiver, or use an external real-time clock module of which there are many inexpensive alternatives. As detailed above, another robust alternative is to use an ESP8266/ESP32 module to synchronize time over the Internet via the NTP protocol.

Tools, Tips and Tricks

I used Google SketchUp (free) to design the wooden case, lay out the components and create cut-sheets so that I could easily make perfect holes to mount the 7-digit displays in.

I don't know of a way to print cut-sheets in SketchUp to an exact size on paper, so I took a screen capture of the template I designed in SketchUp, pasted it into Adobe Photoshop Elements (not free but there are free alternatives out there) and then resized the image to the exact millimeter size.

Somehow printing in Photoshop Elements is a mess for me as I can never get the exact millimeter for millimeter size reflected on paper. A trick I found years ago is to save the file as a PDF and then use the poster printing feature (with "actual size" and "cut marks" selected) in Adobe Acrobat Reader (free). This will print perfectly into multiple sheets if the real size of what you are printing won't fit on a single page. You can then cut along the cut marks and tape things together for a perfect template to place on the material you need to cut up. I also use this trick to print beautiful panoramas on photopaper and tape them together to make huge posters - AWESOME!

An alternative that I found after creating this project is to use Affinity Designer in place of Photoshop Elements. This is a vector (and raster) drawing program (inexpensive) which I find to be extremely good, and actually far more modern and intuitive than Photoshop Elements which is quite dated to me. Btw, I tried several of the most popular totally free vector and raster drawing programs before buying Affinity Designer but very quickly dropped them. They are all usable but I was quickly turned off with usually too limited functionality/features, bugs, weird and user-unfriendly user interfaces, etc.

I used Blackmagic Design's DaVinci Resolve (free) to make the video and Ableton Live 9 Intro (not free) for the sound effects. If you have never used DaVinci Resolve I can not encourage you enough to try it out. You do need a relatively good PC to run it but it is IMMENSELY powerful, and, I need to repeat this, it is FREE for us hobbyists!!! Ableton Live is also a lot of fun but if you are new to this sort of software (I was) it does take a bit of time to learn how to use the synthesizer, audio effects, etc. to get what you want out of it. Totally awesome once you understand it though!

The 7-segment displays I purchased have a black face and white sides. I used a black permanent marker to black out the white sides, also some white writing on the PCB boards they are mounted on to give them more of a stealth look.

Disclaimer

I am not receiving any compensation whatsoever from the makers of the tools I have recommended (most of which are actually free for hobbyists). I didn't actually need to mention any of them but did so because I have spent a lot of time assessing and using a lot of similar tools and I am personally extremely happy with the ones I am recommending.

I make no guarantees that everything will work perfectly if you build your own based on what I have published here. I have made every effort to be as accurate and thorough as possible though, so it should work (mine has reliably for the past 2 years!). Also, this being a hobby that I don't have much free time to devote to, if you do run into problems you will have to do your own troubleshooting, fixing, etc. But, that is part of all the fun with these types of projects in my view. Plus, that's when you usually learn the most.

Enjoy your journey!

ข้อมูล Frontmatter ดั้งเดิม

apps:
  - "1x DaVinci Resolve"
  - "1x Arduino IDE"
  - "1x SketchUp"
  - "1x Affinity Designer"
author: "alan_dewindt"
category: "Art & Wearables"
components:
  - "1x DCF Receiver Module"
  - "7x TM1637 4-Digit 7 Segment Display"
  - "1x Arduino Mega 2560"
  - "7x Through Hole Resistor, 330 kohm"
  - "1x  7-26VDC To 5VDC 3A Step Down Module"
  - "7x LED (generic)"
  - "1x  360 Degree Rotary Encoder Module with Push Button"
description: "Global synchronization! Bypass unreliable external hardware RTC modules completely by exploiting the ESP8266's native Wi-Fi architecture to continuously rip massive, atomic NTP JSON server packets directly down from global orbit!"
difficulty: "Intermediate"
documentationLinks: []
downloadableFiles: []
encryptedPayload: "U2FsdGVkX19kWceGbByiQ3NFXyDS1+nNV0eaeyzlCXgi5/577HDRdhOl2S1Pjr86X3jYWHSnOPHBeKQKF56ajRBIcvIWuCU0CcILas6dLaa4TtGH+/uOaqhRTfw8W9fc+EpmHI8xqmlmBHC1T2sNEZ8YOFuNbMaXb0QGKqjvMA0="
heroImage: "https://cdn.jsdelivr.net/gh/bigboxthailand/arduino-assets@main/images/projects/the-worlds-most-accurate-7-time-zone-clock-441ffb_cover.jpg"
lang: "en"
likes: 0
passwordHash: "a4e43206733d3372bb4870a5e64e53dad3c5f3e315a1e229234240e7b11fbd5b"
price: 1499
seoDescription: "Build an ultra-accurate 7 Time Zone clock using DCF77 signals and stunning animations with this Arduino project."
tags:
  - "dcf77"
  - "multi-time zone"
  - "clocks"
title: "The World's Most Accurate 7 Time Zone Clock :-)"
tools: []
videoLinks:
  - "https://www.youtube.com/embed/W4b-b6iDwSk"
views: 3547