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:
12hr clock | stopwatch | timer | alarm (with buzzer)
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)
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.
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:
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.
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).
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.
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.
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 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!