Graphical Alarm Clock (ATMEL ATMEGA32)
Matt Meerian
(The downloads are at the bottom of the page)

(Below is a video of some of the features of the clock.  Portions of the video are a little blurry, but that is due to the web cam and not the display of the clock)

Launch in external player


front of the clock

Why build the electronics of a clock?  Well, there are times when I use an electronic device and wish it would have some feature that is not included.  (And I also like to clear out the cobwebs in my brain put there by network television)  When engineering and marketing get together to design an alarm clock in a business, they put in features that only the majority of people would use.  For those of us that would like to see a special “feature” (or features) in a device, our only choice is to do it ourselves.  For many years now, I have turned the face of my alarm clock when I go to bed because the eerie green light from the LED segments are too bright when I am trying to sleep.  This dilemma has led to my “Graphical Alarm Clock” project.

The key ingredients to this “recipe for a clock” are a graphical LCD from Optrex (2.8 inch, 128x64 pixel, blue and white display), a photocell and an ATMEGA32 microcontroller from Atmel. 

Operation:

The clock has a very simple user interface.  The button on the right, “enter” is used to access the menu.  Once in the menu, the user can select several different options by using the up/down switch on the left.  When the user is on the desired operation, the enter button is used to select the operation.  For instance, say we want to set the time.  From the main clock display; press the enter button to enter the menu, move down one line, and press enter and then you are in the “set the Time” screen.  The hour is blinking and the up and down button will change the hour.  Pressing the enter will move to the minute and then the up/down will change the minute.  Anyway, you get the idea.  The month, day, and year are set the same way in the screen.  Once the year is set, press enter, and you are taken back to the main menu.  The cool features of the project are the “Backlight time” and “Photo Trigger Value.”  The backlight time is the on/off time of the backlight.  Usually the values are set to 10:00pm for the backlight to go off and 7:00am for the backlight to come on.  The “Photo Trigger Value” is the light intensity level that the backlight will come on.  For instance, if you get up at 3:00am and turn on a light to go to bathroom, the photocell will sense this and turn on the backlight of the clock.  When you turn off the room light, the photocell will again sense this and turn off the backlight.

Exterior:

The microcontroller board and display mount to the “scrap” front panel circuit board.  (The “Scrap” circuit board is used for mounting the switches, photocell, alarm buzzer, and microcontroller board; it was easier to cut a scrap circuit board than to cut 0.062” aluminum.)  A front panel lexan (with button labels and a title) was made with AutoCAD light ’97.  It is an old program, but works great for front panel lexans.  Double-sided sticky tape was used to attach the lexan to the “scrap” circuit board front panel.  The two buttons on the front panel are toggle switches.  Push buttons on the front would have resulted in the clock being pushed backwards when the user would press them.  The toggle switches have an up/down motion, so the clock does not move when actuated.  The hole on the left side of the Optrex display is the alarm buzzer.  The hole on the right side of the display is the photocell.  The enclosure is a wooden clock from the dollar store.  The original clock guts were tossed in the trash and the “scrap” circuit board was epoxied into the enclosure.  The power for the clock comes from a 9V “wall wart” power supply.  The power comes in through a 2.5mm barrel plug in the back of the clock.

circuitry of the clock

Software:

The software is written in a state machine manner.  Here are the states:  (the state numbers were chosen randomly)

            State 1:  Show the power up graphics

            State 2:  Main time/date display

            State 50:  Main menu

            State 60:  Set the clock

            State 61:  Set the alarm

            State 62:  Set the backlight times

            State 63:  Set the photo trigger values

            State 64:  Show the “About this clock” screen

The software was written in C, using the WinAVR distribution of the GNU GCC compiler.  (version 3.4.1)  Please see http://www.avrfreaks.net/ for tons of good information and examples on using WinAVR.  A good place to start in the Graphical Alarm Clock code is the main.c file.  From there, you will be able to see the main loop and how the 20 milli second polled loop uses flags and variables to make the software come together in a harmonious end user experience.  The makefile is included in the software download.  Please note the software is well commented, so to find out the details of the operation you can go through on a line-by-line basis or on a routine by routine basis.
The EEPROM in the microcontroller stores the alarm time, photocell trigger value, backlight on and off-hour.  In case if power is lost, these values are pulled out so the user does not have to set them again.

Warning:  I put some code in the .h files, which is very bad C structuring.

The Hardware:

The schematic is shown below.  Starting in the upper right, power comes in the unit and Q1 is used to protect the IC’s in case the positive and negative terminals are reversed.  On the far left side of schematic is the connection to the Optrex LCD.  This is a 30 pin, surface mount connector with 0.5mm lead spacing.  It was a real bitch to solder down!  The AT24C256 was not used in the final clock design.  Please note there were several mistakes that I made in the schematic.  First, two 10K resistors need to be used to pull-up the RD and WR lines to 5V.  Second, a brownout detector needs to be used on the ‘RES line of the LCD.  (I used a resistor-capacitor combination along with a diode to keep the ‘RES line low for several hundred milliseconds after power up)

There are several small parts of the design not included on the schematic.  The audio output is on the 13 pin header.  The 3 user buttons and the photocell is attached to the 5 pin header.  See the software comments for more information.  The audio buzzer used has an off board NPN transistor to increase the current of the buzzer beyond the 20 or so milliamps an I/O line on the ATMEGA32 can provide.

ExpressPCB was used to create the circuit board.  Their miniboard service really works well for the hobbiest’s budget.

The Design Experience:

I had designed the PCB for the F-51553 Optrex display earlier this year.  The idea for the alarm clock was hatched on July 6, 2005 according to my engineering logbook. The software, front panel, lexan, testing, pushbuttons and other hardware design concluded on September 1, 2005.  The first step and one of the most important ones is the planning of the project.  It started with a list of features I would like to see, several hand sketches of the end product, and several loose pages of diagramming out the user interface on paper.  From there, I did the nitty-gritty software work and finished up the hardware in last part of August.  Testing lasted several nights.  The first night, I wrote down about 10 issues that needed to be addressed.  The second night had just two issues.

Things I Would Change:

It would be very nice to have a battery backup for the Real Time Clock.  Since we tend to loose power on a semi frequent basis, this would have been a handy feature.  I used regular laser printer paper for the lexan and then laminated it and stuck it to the front panel using double stick tape.  The seams in the double sticky tape can be seen under the paper if you look closely.  It would have been nice to use crack and peel paper so there would not have been the tape seams under the paper.  Actually, the best front panel would have been from www.frontpanelexpress.com but that would have probably cost about $30 (US).  I have order from them and have been very happy with their end product.  The software issues I would like to fix is to have the time take up about 7/8 of the screen so it would be easier to see with my glasses off and to have the backlight stay on for about a minute after I exit the menu at night.  (So on the main screen, I can verify the alarm is set to on)

Graphical Alarm Clock schematic (PDF format)
Graphical Alarm Clock PCB layout (in Express PCB 5.1.0)
Front Panel Lexan (PDF format, scroll to the bottom of the page)
Graphical Alarm clock source code (WinAVR 3.4.1)

As always, use at your own risk!
*All rights reserved, all wrongs deserved*

Author:  Matt Meerian
Last Modified:  January 25, 2010
Return to Home page