Summer 2017 – Digital Clock Project Part 1

I’ve learned that the best way to learn something you don’t know much about is to take on a project. I wanted to learn how to do more things with electrical circuits, so I decided to design and build a digital alarm clock with full functionality. While this project seems relatively simple, much was learned a ton during the journey of completing it.

Here is some overview information of what I used:

Clock functions:

12hr clock | stopwatch | timer | alarm (with buzzer)

Code:

github.com/fwacer/digital-clock

Parts list:

62 x  red LEDs (2.1V forward voltage)
29 x  100R 1/4W resistors
5   x  330R 1/4W resistors
4   x  SN74HC595N (Shift registers)
4   x  IC DIP sockets (16POS)
3   x  momentary push buttons
1   x  toggle switch
1   x  Piezo buzzer
1   x  Arduino Nano
1   x  Power Cable (Barrel Connector, 9V, 1A)

protoboard (double sided)
hook up wire (22 AWG)
particle board

One stipulation for this project is I wanted to use regular red LEDs – so no pre-made seven segment display modules. This was to add a little bit of complexity to what I thought would be a quick and easy project.

Roadblock 1:

Almost immediately, the first question was “How will I display [(7 segments * 2 LEDs) * (4 numbers) = 56 output LEDs (plus some)]?”  This question was not difficult to solve, as I had just been tinkering with making an external EEPROM programmer with an Arduino UNO. Ben Eater, an online electronics hobbyist,  solved this problem with shift registers, which allow 3 inputs to control 8 outputs! Each shift register can then be daisy-chained to have an unlimited amount of outputs (in multiples of 8).

Here is my schematic for what I came up with. I daisy-chained 4 shift registers for my project, so 4 of what is shown below.

Seven Segment Display:

7-segment-display

Roadblock 2:

For maximum efficiency, LEDs tend to prefer 20mA. Since my red LEDs have a normal forward voltage of 2.1V, wouldn’t 47R resistors be better than the 100R resistors that are shown in the schematic? [ (5V – (2.1V*2) = 0.8V ; 0.8/0.02 => 40R) ]

Normally, yes. In this instance, I had to change to 100R resistors (after I already ordered the 47R ones) because the shift register that I used (SN74HC595N) can only source 70mA total. Thankfully, I can’t seem to notice a difference when lighting up the two LEDs in series with each 100R and 47R resistors, so there is no visible loss of brightness.

Roadblock 2.5:

This was not the end of my current draw woes. Upon further research, I found that the Arduino Nano can only source 400mA on USB power from its 5V pin (which was also solved by changing to the 100R resistors). I decided to directly supply the 5V pin with a wall plug (5V, 1.5A), which should be more than enough for this project. But, by not allowing the voltage to pass through the Arduino’s voltage regulator, I am introducing an element of risk (could fry the board).

Roadblock 3:

Tracking time was not something I thought would be difficult, as I figured there would be some function that could mostly do it for me within the Arduino sketch. After researching how different people did their own digital clock projects, I realized there was a lot more to it than I previously thought. Oscillators with capacitors and 555 timers… with a backup battery so that it can keep accurate time when it loses power. I decided that for this project, RTC (Real-Time Clock) was out of scope (I really did not want to have to buy lots of watch batteries). Perhaps I will add it later!

I turned to timers within the Arduino codebase. It turns out that there are three of them, Timer0, Timer1, and Timer2. I wanted to have access to the “delay()” function, so that killed access to Timer0 (which delay() relies upon). Another function I wanted to use was “tone()” for having an alarm that uses a musical piezo buzzer, which uses Timer2. The only timer left was Timer1. Setting it up for use (I wanted to run an interrupt that ran every second) was quite difficult, and I ended up using code that someone else wrote. Perhaps in the future I will write my own version!

 

 

Roadblock 4 (with many more that are not listed):

After solving all these frustrating issues, it was time to finish up the code and start testing how the display worked.  Except, when I loaded the shift registers with the data to output, nothing worked! After much debugging (which forced me to clean up messy code and comment everything properly), I still could not find what was wrong. The shift registers just would not output anything! The correct pins were being set, and I thought that maybe the chips had been fried.

It turned out that in my initialization I forgot to initialize one of the pins as an output… d’oh! This problem took forever to find, yet was such a simple fix.

Schematic:

Eventually, through these setbacks, I completed a schematic and knew how I wanted all the pieces to fit together. The last component was the physical casing.

Digital-Clock-Project (2)

I started with the face plate, figuring out how I wanted the LEDs to be spaced and mounted. I decided to design it with a pressure fit for the LEDs, then some silicon or other binder once all the soldering was done.

Below is a slideshow of pictures showing the process of making the face plate:

 

This slideshow requires JavaScript.

To do:

This project is almost finished, just some soldering and final setting in the box, mostly aesthetic things. Unfortunately, I’m not quite done yet, so I am releasing what I have finished. Stay tuned for more!

4 thoughts on “Summer 2017 – Digital Clock Project Part 1

  1. Nice project for a Nano. I would not power anything from the Nano’s 5v regulator that draws more than a few tens of mA, they blow up easily. If you don’t want to use a realtime clock breakout (eg Adafruit) the on board timer may gain or lose time… have you evaluated its accuracy?

    Here’s an alternative which I’ve been meaning to prototype… attach a GPS breakout and decode satellite time and date (UTC) and display that. Will never be wrong! And no need to set it, ever!

    Like

    1. Thanks Paul! The nano seemed like a good choice for a little project like this.
      I’ve been running into some problems finishing it up (calculated the current draw wrong so had the wrong resistors, and now have a short of some kind, or perhaps one of the shift registers is fried), but the nano’s 5V reg might be why I’m having problems.
      I had done some research on what the nano is capable of outputting from the 5V pin, but it might just be worth it to get an external regulator and only use the nano for the digital logic.

      Since this was my first “fit it in a box” project, I decided to simplify the project by using the lossy on-board timer. Once I get it finished up, I can add other things (sensors, RTC) fairly easily since I have many free IO pins.

      Thanks again!

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s