Digital Alarm Clocks

It seems that time is always slipping away from us at an ever quickening pace. This seems more apparent when we’re doing the things we enjoy, hence the saying, “time flies when you’re having fun”. When I was younger I always had a watch so I knew when it was time to go home, go to bed, etc. As I got a little older and ventured out on my own I cared less about time and stopped wearing a watch altogether as the late nights and early mornings seemed to blend in together. These days time is more important than ever with a family, job, appointments and meetings. I find that I don’t have enough devices that tell time; watch, phone, PC, iPod, etc.

One of my custom digital alarm clocks

Suddenly I had a fascination with timekeeping altogether and found myself compelled to build my own clocks and timers. The real bonus here is that once you’ve mastered keeping time you can do all kinds of things with it from the way you display it to the way you signal specific points in time (alarms) to scheduling specific events to happen (such as turning sprinklers on / off).

The Heart-Beat of Time

In order to keep track of time we’ll need a device that can accurately update even when power is lost. For me this device is the DS1302 from Maxim Integrated Products. The DS1302 is a battery-backed real-time clock IC with RAM. It requires a 32.768kHz crystal in order to function.

DS1302 BBRTC

The DS1302 counts seconds, minutes, hours, date, month, day, and year with leap-year compensation until 2100. It also contains 31 bytes of battery-backed general purpose RAM. With a synchronous serial interface (SPI) and wide operating voltage the DS1302 is an ideal choice for both 5V and 3.3V microcontrollers.

Keeping It Simple

Ever since I built my first clock I have been inspired to create some unique time-pieces, but in the spirit of keeping it simple and to make it easier to learn how you can build your own clock I will demonstrate a basic design that we have been using in our house for a few years now. The three clocks you see here are all based on the same control board design. Each is unique in its appearance and also in function to some degree.

By combining the common elements on the control board, such as the clock chip, alarm amplifier and display driver we can keep the base programming code simple and common to all three versions while having the ability to customize each clock for basic things such as display and input configuration.

The Control Board

These photos show the main control board both unpopulated and partially populated. This board is designed to contain a BASIC Stamp 2 microcontroller, a MAX7219 display driver, a DS1302 RTC, a DS1804 digital potentiometer, an LM386 amplifier and all support components. What it doesn’t contain is the display or input controls.

Instead an interface is available for both the display (along the bottom of the board) and the input (along the left side). This allows for further customization of the display and input without having to redesign the control board. The 8 available I/O all contain 10K pull-up resistors making it easy to connect switches, photocells, thermistors or even a quadrature encoder for input.

The Display Board

These photos show the display board unpopulated as well as two populated versions.

This board was made to connect directly to the control board either by connector or by wires.

The mounting holes are aligned with holes on the control board allowing you to stack it right on the board.

Trimmed component leads were recycled to connect the display board to the control board.

This concept was used for all three clocks and expanded on by connecting the stacked boards directly to each unique enclosure. In populating the display board I used common 7-Segment displays that I got from both Jameco as well as from some old Parallax kits from years ago. These seem to have a common pinout and were available in green or red. When selecting the T1 LEDs to use for the colon, alarm and AM/PM indicators, try to use an LED with a similar forward voltage and / or mcd rating to the 7-segment displays. This will help ensure that the brightness is consistent across the display, especially when using dimming, as the MAX7219 maintains constant current for the entire display. Since the LEDs are free-standing on the board I used heat-shrink tubing to block the light from the side of the displays.

Colored translucent plastic was obtained for a filter for both the red and green displays.

Be careful when cutting this stuff…

I actually cracked a few pieces and had to obtain more to finish the project. There are guides on cutting and drilling acrylic so I won’t go into that here.

Circuit Design

Looking at the schematic (attached below in the ZIP file) you can see the individual blocks of this project all broken down in their basic components. What the schematic does not contain are the inputs for setting time, etc. These are customizable and are slightly different on each clock. So what we will cover is the design of the common components. The BASIC Stamp 2 is the brains of the operation here. I could have used a more powerful BASIC Stamp model and probably would have if I had used a rotary encoder on any of these, but in this case I decided to keep it simple. The BASIC Stamp drives the display using the MAX7219 driver IC. While a little pricey, I really like this chip and find that it simplifies things greatly, especially if your display contains more than 4 digits (adding seconds). The DS1302 is on the same synchronous serial bus as the MAX7219 saving two I/O lines. The DS1804 is used in this design to provide a volume control for the LM386 audio amp IC. The battery backup keeps the time when the power fails.

Design Pitfalls

As with any project it is possible that if you change something even a little bit from what you started with your outcome can vary significantly. This was the case during the original build of these clocks.

Audio Circuit Patch

You may have noticed the extra components tack-soldered on to the back of the control board. When I prototyped the design I used the Parallax Professional Development Board, my favorite resource for BASIC Stamp prototyping. I used the on-board amplifier for testing sound output, but when I designed the LM386 amplifier in the circuit I first built, I used a generic configuration. Imagine my surprise when the alarm sounded not only different, but had poor volume control and range. The patches were made to attempt to correct this and I updated the ExpressPCB files accordingly so you don’t have to do this if you have a board made.

Clock Features

At first these would seem to be ordinary digital clocks, however each clock has additional features. Some features are common to all three clocks such as crescendo alarm capability, multiple alarm times, 12 or 24 hour format, battery backup and dimmable display. Other features are unique for a particular clock or modified to act differently than the others. For example, the clock with the translucent case has a photo resistor used to help the clock determine if it is light or dark in the room. This data is used to adjust the brightness of the display.

Customization Options

Another clock has a programmed set of times in which it brightens or dims its display. These settings are stored in the battery-backed RAM and restored on power-up. The crescendo alarm capability allows the clock to start the alarm at the lowest volume and ramp it up as time goes on at a rate you select. In fact you can even change the alarm sound itself. There are many customizable options here and very little code needs to be modified to enable these features. The base code contains subroutines that handle all the details such as reading / setting the time, reading / writing to the RAM, etc.

Parts Resources

What? You don’t have that in your junk boxes or spare parts? No problem…I listed some sources for the components. Everything used was something I had in my parts cabinets. Two of the enclosures came from RadioShack. The translucent enclosure was purchased from one of the surplus dealers such as All Electronics, although it has been a few years so you might need to look around. I remember those enclosures were available in red, clear and blue, so I took the red cover from one and the clear case from another to make the clock more techie looking. During prototyping I used two AA batteries for the battery backup, but then I found some CR2032 coin cell battery holders on eBay and bought a dozen or so. That is what was used in this design, so if you have the board made from the included ExpressPCB file, bear in mind you may need to make some changes if your battery holder mounts differently or if you use a different type of backup battery altogether. In fact, feel free to adjust the components to what you have on hand. It is a good way to make use of spare parts.

Customizing Things

You should always feel free to experiment with the elements of a design that you feel would better be served by doing things differently. Usually this is a matter of aesthetics such as how the overall end product looks. You might decide you’d rather have a blue display or that the speaker just isn’t loud enough for you. Feel free to experiment and make changes…just be sure you’ve tested those changes before you commit to PCB lest you end up having to patch your design as I did. Of course, these three clocks have been running for over 3 years now and there is very little I would change in the overall design if I started over. In a future article I will show you a very interesting variation on the concepts here. A hybrid Binary / Digital Clock which displays the time in the traditional numeric form we’re all used to (12 & 24 hour modes supported) as well as in binary, with each digital having a matching binary representation of itself displayed in real-time. The day of week, date and temperature are also available on a separate LCD display. All information published here can be found on the Nuts and Volts website for this project as well.

Resources

Savage///Circuits TV – Episode 4

Binary / Digital Clock – Project

Discuss this project on Savage///Chats

This project was published in the February 2010 issue of Nuts and Volts Magazine


Digital Alarm Clocks by Chris Savage is licensed under CC BY 4.0

PLEASE FEEL FREE TO LEAVE YOUR COMMENTS, QUESTIONS, SUGGESTIONS OR FEEDBACK ON THIS POST.

Leave a Reply