loading

Arduino Master Wall Clock.

Time displayed on large 1" (26mm) 7 segment displays with secondary 4x20 LCD information display. The clock can be used stand alone or provides the following pulses to drive slave clocks 1 sec alternating, 30 sec, 1 min , 1 hour, 24 hr, 15 min chime of quarter hours, hourly chime of hours.

An Arduino 328 Microprocessor is used to decode and display time & date from the DCF77 "Atomic" Clock in Mainflingen near Frankfurt Germany.
The DCF77 signal is decoded using the fantastic new DCF77 library written by Udo Klein meaning the clock stays in sync and keeps perfect time even with a massive amount of noise on the received DCF77 signal. Udo Klein's DCF77 library also continually "Auto Tunes" the quartz crystal so in the rare event the signal can't be decoded the clock remains accurate within 1 sec over many days.

Secondary 4x20 I2C LCD display is used to display time & date, fast or slow seconds, summer winter correction, display brightness, sync information, signal quality, auto tune'd frequency, auto tuned quartz accuracy and summer winter time mode.
The primary and secondary displays are auto dimmed using an LDR and Pulse Width Modulation. The primary and secondary displays are shut down during daytime and are activated by Passive Infrared detection when the clock detects someone entering the room. Manually triggered automatic Summer/Winter time correction of 30 second slave clocks. Blue-Tooth link for programming, clock pulse status and PIR adjusting Auto leap second adjustment of 30 second slave and 1 second slave clocks time and date of leap second can be read via Blue-tooth on your PC or Android mobile or tablet Recording of fast or slow 1 second slave clock pulses on the LCD display as well as time and date stamping of last fast or slow pulse accessible by Bluetooth on your PC or Android mobile or tablet.

See enclosed 4K video of clock pulsing and chiming the hours at 22:00hrs.

Step 1: Design

After many years of building clocks with logic chips I decided to use microcontroller due to the reduced chip count and therefore ease of construction. My previous master clock used 31 logic ICs and 4 main boards and had far less functions see pic.

I decided to use Arduino to control my new Master due to it's ease of programming. Most of the complicated work is done by the people who design and then share the libraries. Arduino is very well supported hardware wise and many complete parts can be purchased ready built as building block for projects.

On this clock a MAX7219 drives the primary display and a 4x20 I2C LCD is used for the secondary these help keeping wiring and Arduino 328 pin use to a minimum. I kept the same type of Oak case used in my old master Clock as it fitted 6 x 1" 7 segment displays perfectly and gave me space to fit in all the other modules. I have used a PIR module for display shutdown/wakeup with it's own timer and sensitivity adjustment as this uses only 1 pin of the Arduino 328. A EZ Link Bluetooth Serial Board module enables me to program the clock and read data from it remotely from my desktop PC and Android mobile.

One of the design considerations when building this clock was to reduce the power consumption as the clock is on 24/7. See the table below most of the time the Mk2 clock will draw around 50mA compared to the Mk1's 200mA.


Power Consumption

Masterclock Mk1 200mA

Masterclock MK2 Startup 35mA

Display off during daytime with no movement detected 40mA

Display on 0 brightness 43mA

Display on 2 brightness 50mA

Display on 5 brightness 62mA

Display on 10 brightness78mA

Display on 15 (max) brightness90mA

Arduino Libraries Used
dcf77.h this Library is the heart of the clock and it decodes even a noisy DCF77 signal and auto tunes the quartz crystal.

LedControl.h to drive the LED display and LDC backlight via a MAX7219 IC.

LiquidCrystal_I2C.h to drive the LCD display

Wire.h to communicate with I2C devices

Time keeping
My old Master Clock was a very good time keeper and as long as I had a good DCF77 signal to keep it in sync it was fine. Every now and then when the DCF77 signal was lost for some time it would gain a second and when correcting it it would then make the 1 second slaves loose a second. This only happened a couple of times a year but re-syncing all my 1 second slaves was a pain.

I have decided to keep using the DCF77 signal from the Atomic Clock in Germany. I could have used the MSF signal from the UK but reception is not good in Surrey as the transmitter has move further North. The DCF77 signal is also better supported as it is used across Europe not just the UK.

I will be using the Arduino DCF77 decoder library written by Udo Klein . Udo has been developing this code over the last few years to make it synchronize and lock onto a signal even when there is a massive amount of noise and interference on the signal. While prototyping my new clock I consistently manage to synchronize and maintain a lock even though the DCF77 signal receiver LED that should show a steady 1 second pulse from Germany is flashing multiple times a second. Udo's DCF77 library code is very very complex but in very basic terms it locks onto the DCF77 frequency using a phased-locked loop and once locked it will actually predict what the DCF77 code should contain and then look for snippets of this code in a very noisy signal. As things like the date do not change that often his code can look for this data in the signal to help it stay locked on! Once in sync with the DCF77 signal it uses it to "auto tune" the backup quartz crystal ensuring if the DCF77 signal is lost the clock still stays in sync. You can read full details of the development of this library and much more on Udo's site/blog here Blinkenlight.

The only small down side to this library is that it needs an accurate time base on the Arduino to lock into the DCF77 frequency. Modern Arduino boards don't use a quartz crystal ( the one you see on the board is for the serial port) but an inferior 16MHz ceramic resonator. Udo has written a test program to check if your Arduino boards resonator/crystal are up to the job of running his library and can be found here DCF77 Scope . If your board is not up to the job it is very easy to remove the resonator and replace it with a quartz crystal and a couple of capacitors. I have modified my Arduino UNO and it works perfectly with the library.

See pictures and schematics of UNO before and after modification.

Main clock display
I used 1" (26mm) 7 segment display to display time as these have worked perfectly well on my old Master Clock and are legible from a good distance at night and also in daylight. These are driven by a MAX7219 display driver as it can talk directly to the Arduino using a couple of wires and it's multiplexed display simplifies wiring.

Secondary Clock Display

The secondary display as well as showing the time and date will give information on the running of the clock in particular the DCF77 decoding performance. I have used an I2C 4x 20 LCD display for this. Again these displays talk directly to the Arduino over a 3 wire interface and are very good at displaying lots of information close up. See display animation in this section.

Pulse Monitor

Pulse monitoring uses simple LEDs as they provide a quick visual indication of what pulses are being transmitted by the clock.

Step 2: Summer/Winter Correction of 30 Second Slave Clocks

Manually Triggered Automatic Summer/Winter time correction of 30 second Slave Clocks

The Master Clock itself auto corrects for summer wintertime changes at 02:00hrs but due to the loud clunk of the 30 second clocks being advanced during summer changes I have added a switch to initialise automatic Summer advance and Winter retard.

This is a single non-locking key and the Master Clock will advance or retard the 30 second slaves depending on the current time of year. If it is summertime the clock is advanced 1 hour and winter time the clocks are retarded 1 hour (pulsing stopped for 1 hour as slaves can't go backwards). In summer time correction mode 120 extra pulses are sent to the 30 sec slave clocks. The LCD display will show "Summer Advance" and will count the 120 extra pulses. When the time is at 00 or 30 seconds the extra pulses are stopped and the 30 sec clocks pulses are sent out as normal. This means whenever the 120 pulses are started the 30 sec slave clocks are only advanced exactly 1 hour. See video 1 above

In winter time correction mode the clock waits for the next 30 sec pulse before pausing for 120 30 sec pulses. The LCD display will show "Winter Retard" to show 30 sec clocks are being retarded and show the number of missed pulses. See video 2 above

Step 3: Construction- Case/mounting Assembled Boards

My old master Clock had to be completely wired by hand and this took around 4 weeks to complete all the boards. As I can't produce my own PCBs I have used modular construction on my new clock to keep the wiring/vero board construction to a minimum . This also helps with maintenance as I can just swap out a module if it goes faulty.

Photo 1

The Master Clock case is made of solid Oak. I have stripped back the old dark varnish from this recycled box and re varnished in clear lacquer. The case is identical to my old master clock but is now a lighter Oak colour.

Photo 2

Display vero board has been spray painted green and comprises 2 parts (7 segment board and LCD/LED board) bolted together and mounted in the case on threaded M5 studding. In the finished clock the threaded bolts will be covered over with brass tube.

Photo 3

The LED displays are mounted on SIL headers.

Photo 4

The LCD Display mounted into a hole cut in the veroboard.

Photo 5 & 6

Lid removed to show display board and main board mounting.
All 7 segment displays, LCD and LEDs mounted. LDR is on the right of the LCD. PIR detector is now mounted outside of case as it will not work through the case glass. Case needs 2nd pane of glass added so displays can be labelled with white Letraset. Once the 2nd glass panel is in place brass tubing can be cut to length to cover the studding.

Photo 7

Wiring of main board to display board, switch panel, main fuse and EZ link Bluetooth board.

Photo 8 & 9

Master Clock construction almost completed. Oak Bezel added to LCD display, brass pillars added over display board studding and 2nd layer of glass added held in place by brass clips ready for letroset labelling.

Photo 10

Completed Master Clock with letroset labelling applied to the 2nd inner piece of glass.
The two glass layers are separated by a 1mm rubber gasket.

Step 4: Construction- Displays, Controls and Sensors

Displays

The 7 segment display board is mounted above the main board. The MAX2719 7 segment driver is mounted on it's own board attached to the back of the 7 segment LED board to keep the wiring as short as possible.

The LCD 4x20 display is mounted on the front board below the 7 segment board. The MAX2719 DP driver is connected to a transistor to control the LCD backlight.

The pulse monitor LEDs are mounted on the same board to the left,right and below the LCD display.

Controls

Control switches are mounted on the back board at the bottom of the clock and are in three sections.

30 Second Clocks
On - turns On/Off the pulses to the 30 seconds clocks

Advance/Retard - Depending on the clock showing summer or winter time when held down for 1 second steps the 30 second clocks forward 1 hour or retards the clocks 1 hour. Only works when the Arm switch is set to the Arm position and On/Off switch is On.

Master Clock

Reset- resets the Arduino so the clock will re-sync

Bluetoth

On - Turns Bluetooth On & Off

Pair - Pairs the clock to a new device

Pyroelectric IR Infrared PIR Motion Sensor Detector Module
I have added an infrared motion detector to the clock. I want to keep the running costs down to a minimum especially as the clock will be running 24/7. I need the clock on at night so have fitted auto dimming of the 7 segment displays now to 16 levels. I have also connected the decimal point output from the Max7219 to a transistor and the LCD backlight. The transistor then controls the LCD backlight as the 7 segment display is dimmed by the Max7219. The displays (7 segment and LCD backlight) are now turned off from 08:00hrs to 22:00hrs. The infrared detector will turn them on if motion is detected i.e. you step in front of the clock and they will then turn off after a preset time.

The pyroelectric sensor is modified as the sensor will not work behind the display glass. The sensor is removed along with the diffuser and these are mounted on their own vero board outside of the clock. See photos 8 to 11 above.

LDR dimming

The LDR is mounted on the display board to the right of the LCD display.

Step 5: Construction- Circuit Boards

Circuit board are all made from veroboard.

The top display board is two boards joined together with brass strips.

Pic 1 Main circuit board.

Pic 2 Main circuit board completed

Pic 3 Main circuit board rear view

Pic 4 Display circuit board completed

Pic 5 Display circuit board rear view completed with MAX2719 board

Pic 6 Max 2719 board

Pic 7 Max 2719 board rear view

Pic 8 Seven segment display board

Step 6: EZ Link Bluetooth Board

Programming and serial comms is via a EZ Link Bluetooth Serial Board.

My clock can now be programmed remotely by my PC (will not work with MACs use USB cable & CP2102 module instead) and also monitored remotely by my Android Phone/Tablet.

The pair switch mounted on the main switch panel is connected across the Pair switch on the Bluetooth Board (soldered to the 2 resistors see pic above).

Android Bluetooth serial monitor (pic 3) showing Slow and Fast 1 second clock pulses with date and time of error pulse ( in this case it shows Slow seconds is start-up time) and fast seconds which show in this case a leap second from 30/06/15 (shown as 01/07/15 as British Summer Time is on), PIR detection.


The EZ link Bluetooth Serial Board is mounted on the base of the clock (pic4). The 3 LEDs Connection (Or), Receive (Bl) & Transmit (Bl) can be seen through the display vero board holes.

Step 7: Leap Second Detection and Correction

The clock detects leap seconds. This is built into the library and the LCD and 7 segment displays auto adjust.

The problem was how to auto correct the 1 seconds clocks. The leap second is added at the end of a minute so instead of the seconds counting to 59 then starting again from 0 the seconds count to 60 and then resets to 0.

The clock looks for the seconds counting to 60 then waits 1 second before starting to pulse the 1 second clock pulse again. This can be seen on the serial display on my mobile via the EZ-Link Bluetooth board in my clock. I used a test program written by Udo Klein to send dummy leap year data to my clock.

The phone display above shows 0 slow seconds and 1 fast second. The 1st slow second is always there on startup and indicates when the clock was first sync'd up in this case 23:51:44 on the 31/12/14. These are day totals and are reset at 06:00 am. The fast second (the seconds are fast compared to DCF77 time) shows the date and time the fast seconds were detected in this case 0:0:0 01/01/15. This is when the leap second was added and the seconds pulsing was stopped for 1 second to keep in sync with DCF77 time. This was tested using Udo Klein's DCF77 radio code generator for the Arduino. The code makes an Arduino into a low powered DCF77 transmitter so you can send any date and time to any DCF77 clock for testing.

Pic 2 above shows the actual output from my clock from the real leap second on the 30/06/15.
The clock displays the fast second as received at 00:59:60 on the 01/07/15 as British Summertime in in operation. After "Slow Seconds" and "Fast Seconds" on the serial display is the error count per day. On the image below they show zero as the day count is reset to zero at 06:10hrs every day. The time and date of the last fast or slow pulse is then recorded on the LCD display. I have removed the current time and date from the serial out on the latest version of the code.

Video

Short video above showing the Master Clock detecting a leap second and stopping the 1 second clock to enable it to stay in sync.
The leap second when detected is time stamped and stored and can be read from the serial port of your PC or Android phone. It can be seen as "Fast Seconds" (above on my Android mobile) as the 1 second clock had to be paused to stay in sync.

Step 8: Testing Slave Outputs

Once the clock was completed I built a test rig (pic 1) to check the clock slave functions.

The rig has the master clock, 1 second slave and a 30 second slave attached.

The 30 second slave movement (pic 2) has a 5 volt coil that is activated every 30 seconds. It takes 120 impulses to step a whole hour. There are various manufacturers of these movement and they were common in telephone exchanges, factories and schools in the UK. Many countries have a similar electro-mechanical movement to this using different voltages and or pulse frequencies.

The 1 second movement (pic 3) is driven by a Lavet type stepping motor. The motor is sourced from a quartz clock movement with the quartz control board cut out. The motor requires very low current to drive it and can be driven direct from the Arduino output via a trimmer resistor. It just requires a polarity change on the motor to step it by 1 second.

The first test is just to check that the slave outputs are working ie the 30 second clock is stepping every 30 seconds and the 1 second clock is stepping every second.

The next 3 tests winter summer, summer winter and leap second correction require a spare Arduino and a test program. As the clock automatically synchronizes to the DCF77 Atomic clock there is no manual control to set the clock. All testing is done by transmitting dummy radio time and date code in the DCF77 format to the clock. Luckily Udo Klein the designer of the DCF77 library used to decode the DCF77 signal in this clock has also designed a DCF77 radio code generator for the Arduino.

To use the generator download Udo's code and program the Uno via the serial port. Once the board is programmed connect a 1K resistor to pin 3 and a small loop of wire to the Gnd pin (pic 4). Loop the wire once around the DCF77 aerial of the device you are testing. Load up a terminal program or just open the serial monitor from the Arduino interface. Set the baud rate to 115200 and hit enter. You should see the following on the serial monitor

running
output on pin D3

The test code is preprogrammed with winter summer, summer winter and leap seconds so all you do is set the clock to a time and date 15 mins before the event. This gives the Master Clock time to sync into the dummy signal. Once the dummy signal is being synchronized and the Master is displaying the dummy time and date set the slaves on the test rig to show this time as well.

Video 1 shows the clock automatically correcting the 30 second slave for Summertime.

British Summer Time starts on the last Sunday in March at 01:00 GMT. The DCF77 signal is set to CET so when the DCF77 radio code generator is programmed set it an hour ahead as the hour will be removed by the code in the master Clock. If you are in a CET zone just set it to the time you require.

The Master Clock will automatically jump from 00:59:59 to 02:00:00 but the 30 second slave will show 1 oclock. The 30 second slave clocks will not auto correct until the "Arm" switch is operated and then "Advance/Retard" key is operated for 1 second. Traditionally in the buildings where I worked this was done on early Monday morning after the clocks had changed. You could change the code to make this automatic but then you would need to be around at 01:00hrs to watch it.

Once triggered by the "Advance/Retard" key the 30 second clock will start to advance every second. "Summer Advance" will be displayed on the LCD screen along with the number of advance pulses. 120 extra pulses are required to advance the slave clocks by 1 hour.

The 120 extra pulses will take 2 minutes to send and during this period a number of normal 30 second pulses would be missed (the number depending on when the advance was started). To get over this problem the advance pulse count stops on zero seconds and 30 seconds.

Once the pulse count reaches 120 the Slave clock will show the same time as the Master Clock and the LCD display will revert to normal.

Video 2 shows the clock automatically correcting the 30 second slave for Wintertime.

30 second clocks can't move backwards so they are retarded by stopping pulses for 1 hour (120 pulses)
On operating the Advance Retard switch the missed pulses are counted from the next 30 second pulse.

British WinterTime starts on the last Sunday in March at 02:00 GMT+1. The master Clock display will jump from 01:59:59 to 01:00:00 and GMT+1 will change to GMT+0. As above the slave clocks are not corrected until the "Advance/Retard" key is operated for a second.

Once triggered the Master waits for the next 30 second pulse and the LCD Display "Winter Retard" along with the number of missed pulses. The number of missed pulses is advanced for every 30 second pulse missed and once it reaches 120 the slave will show the same time as the Master Clock and LCD display will revert to normal.

Video 3 shows the 1 second clock correcting for a leap second.

The DCF77 radio code generator has leap seconds built in. Just look for past leap seconds and set the generator to this date and time.

Here is an example of how to set the generator to trigger a leap second.

To trigger a leap second for GMT (for CET take an hour off)
Send

x15.01.01 00:45:00 1 0001

Outputs

running
output on pin D3
current time setup (YY.MM.DD hh:mm.ss w sbtl)
w = weekday, s = summertime, b = backup antenna, t = timzone change scheduled, l = leap second scheduled
15.01.01 00:45:00 1 232001

To set target time use one of the following formats

simple mode: sYY.MM.DD hh:mm.ss

extended mode: x:YY.MM.DD hh:mm.ss w sbtl

current time setup (YY.MM.DD hh:mm.ss w sbtl) w = weekday, s = summertime, b = backup antenna, t = timzone change scheduled, l = leap second scheduled 15.01.01 00:45:00 1 232001

This actually set my clock (set to GMT) once decoded to 23:45 31st December 2015 plus a few minutes for decoding time.

When the leap second is injected the 1 second clock slaves are stopped for 1 second. The master will display 23:59:59 then 23:59:60. The 1 second and 30 second slaves are not stepped until the master shows 00:00:00. The leap second will be detected as a fast pulse and will be recorded on the 1 second display along with the date and time it occurred.

<p>hi I'm from the Philippines, can this work in our area?</p><p>thanks</p>
You will have to use a receiver and library for your area. The code will need to be modified to suit the library.
<p>hi, im from the philippine, can this work in our area?</p><p>thanks</p>
<p>love it mate. great Instructable</p>
<p>Another great Instructable! You've inspired me to develop something similar but using GPS. Out of interest, what method do you use for transmitting your pulses to slave clocks? Do you find transmission lag to be an issue? Keep up the good work. </p>
<p>Thanks DK84. I just use 2 wire or sometimes Cat 5 cables with bunched pairs. I have no problems with transmission lag, there is probably more variance between electromechanical clock motors than the time it takes for a drive pulse to reach them from my Master Clock. I did have an issue with noise on the 24 hour pulse to my old slave calendar clock but this was solved with an R/C filter at the slave end.</p>
Thanks for that.<br>I've been looking for a way to get the radio code for a while now and have just found your instructable.<br><br>So i think i will use parts of your instructable to build an auto update circuit for a Nixie clock i am currently designing.<br>The other option was to use a gps unit, but i don't know how well they work inside. My sat nav units certainly don't.<br><br>Jason.
<p>Hi Jason my clock picks up the DCF77 signal very well from just south of London and has been decoding without fail for over a year now.</p>
I'm in Manchester, so I'll look into how well ( or not ) the German signal is received here.<br>I might be better with the Rugby signal. So have to get a unit on that radio frequency. 60hz iirc?<br><br>Jason.
<p>I think the Rigby signal has moved to Cumbria now?. I have checked and the DCF77 signal should be OK for the whole of the UK. Coverage map here <a href="https://en.wikipedia.org/wiki/DCF77#/media/File:Dcf_weite.jpg" rel="nofollow">https://en.wikipedia.org/wiki/DCF77#/media/File:Dc...</a> </p><p>If you use the MSF signal from the UK as well as a different receiver you will need a different library and will have to modify my code.</p>
Yes, the uk signal is on a different frequency. So needs a different module and software.<br>I'll get a dcf77 unit ordered and see how it works.<br><br>Thank you for all your help.<br><br>Jason.
<p>I love it !!</p>
<p>ynneb</p>
<p>Thanks ynneb</p>
<p>I just LOVE all your clocks. Beautiful builds. </p>
<p>Thanks Eric.</p>
<p>How cool, what a project ! ! ! </p><p>What kind of changes are required for those of us in the USA that would use WWV or WWVH (Hawaii)??</p>
<p>Thanks dmhoke.</p><p>You would need to locate your local time transmitter and get a receiver module for that transmitter. In England we have a choice of 2. MSF from the North of England or DCF77 in Germany. I use the DCF77 signal from Germany as the signal is stronger and there are more libraries for it.</p><p>My code is designed around the DCF77 library by Udo Klein so you would also need the library for decoding you local time transmitter. Have a search on Google. My code would need to be changed to get the time and date from the new library but the main code would stay the same.</p>
<p>Thanks, I thought it would be something along those lines.</p>
<p>i really like it. thanks for sharing</p>
<p>Hi e-Brain Battulga. Thanks for the comment.</p>
really nice instructable, i'm considering making one. i would suggest putting the code in a file and attaching that to make the instructable a bit more friendly . i don't know exactly how to do it, but i have seen it been done. appart from this excellent instructable
<p>Hi I will prod delete the pasted code as I am not sure it has pasted in correctly.</p><p>If you code to the code step there is already a link to download the code as a zip file.</p>

About This Instructable

25,021views

288favorites

License:

More by oliverb:IOT Pet Feeder Using the Blynk Mobile App & an ESP8266 Module Arduino Background Radiation Monitor With 7 Segment Display Arduino controlled DCF77 Synchronized Astronomical Regulator Master Clock 
Add instructable to: