- Atmel ATmega328P Microcontroller with 32kB Program Memory and running at 16MHz
- Philips PCF8574A IO Port Expander
- Maxim DS1307 Real-Time Clock
- 16×2 HD44780 Monochrome LCD with Blue Backlight
- UM66 Melody IC
- 4×3 Numerical Keypad
- LM7805 Voltage Regulator
- Display Time in 12-Hour AM/PM Format
- Display Date in dd/mm/yyyy Format
- Display Day
- Set Alarm Time
- Set Date
- Set Time
- Menu Based Navigation System
- Anti-Sleepiness Alarm Function
- Auto Generated Day Function
The Making of the Digital Alarm Clock
This Digital Alarm Clock project started its’ life on a breadboard, and with a brand new ATmega328P MCU bought from Cytron.
Together with the Microcontroller, I bought the UC00B USB to Serial adapter to program the MCU using the Arduino IDE.
To make it work on the Arduino platform, the microcontroller must have the appropriate bootloader. There are many ways to burn the bootloader but I settled on the ArduinoISP method (using my Arduino Uno R3).
I made a video on the bootloader burning process.
After successfully burning the bootloader, I can now use the Cytron UC00B USB to Serial adapter to upload code into the MCU.
With the basic Arduino circuit done, I can start the programming and also assembling other hardware components.
To read more on how to make your own Arduino on a breadboard, read this post 🙂
Next, I made some special push buttons so that the user can identify its’ function more easily.
Here’s how I assembled these push buttons.
I ended up using 4 breadboards to completely construct the prototype circuit.
Writing the Code
First and foremost, I should mention and give credit to a few libraries that I’ve had to use in my code.
- Wire by Arduino (Source) : Establish I2C connection to/from the PCF8574A and DS1307
- LiquidCrystal by Arduino (Source) : Interface with the HD44780 LCD
- I2CKeypad by Angel Sancho (Source) : Interface with the 4×3 Keypad through the PCF8574A
- TrueRandom by Peter Knight (Source) : Generate true random numbers for the random math question
Other than the libraries mention above, the code is solely written by yours truly.
It is 1,029 lines long, and takes up around 16kB of program memory. It took me close to 50 hours to come up with this.
My initial idea of using an ATmega16 to cut cost was scrapped because this code and the bootloader takes up around 18kB of program memory, which is more than the 16kB capacity of the ATmega16.
Designing the Schematic and PCB in Eagle 6.2.0
I chose to use the Eagle software to design the schematic and PCB because the library is huge and it’s simple to use (IMHO).
This is the final revision of the schematic :
Initially, I plan to make a dual layer PCB but because of time constraint, I had to settle for a single layer PCB.
This is the final revision of my PCB.
I’ll admit that I used autoroute, and it’s not that smart, so I had to give it a bigger workspace to work on. Thus I’m using a 25cm by 15cm PCB.
Printed the PCB layout on a transparency sheet to mask the PCB from UV exposure.
I’ve wrote a post before this on how to make your own PCB. You can read them here 🙂
The end result.
Tour of the Board
At the centre of the board is where all the magic happens, ATmega328P MCU, DS1307 Real-Time Clock and the PCF8574A IO Port Expander.
There is also a backup battery for the DS1307 Real-Time Clock IC. Even if the power runs out, the ‘clock’ will still continue to tick.
The 6 Buttons. Menu, Back, Forward, Cancel, OK and Alarm ON/OFF.
At the bottom left is the 4×3 Numerical Keypad for user input. It is used for setting the time, date and also answering the math question.
At the top left are the buzzer, the UM66 Melody IC, and a 10k potentiometer to adjust the LCD Contrast.
Lastly, at the left hand side of the board is the programmer port, where I can plug in the UC00B USB to Serial adapter to upload a new code into the ATmega328P.
Menu-Based Navigation System
The user can press the Back and Forward button to scroll through the Menu. To select the desired function, press Enter.
Anti-Sleepiness Alarm Function
To turn off the Alarm, the user has to answer a simple math question. The alarm will not turn off until a correct answer has been entered. The question is generated randomly everytime the alarm rings.
Auto Generated Day Function
To set the date, the user doesn’t have to enter the Day. The code has an algorithm that will determine the correct Day that corresponds to the date entered.
Below is a list of all the components that are used in this project and also their cost. So much money!
The total cost shown below does not even reflect the true amount of money I spent, there are things like troubleshooting cost, buying new components to try out, soldering cost, flux, damaged components, etc.
Looking aside the cost, I’m thankful that I’m able to complete this project and I did learn alot from it.
I hope you’ve enjoyed reading this post as much as I’ve did during the making of this project.
Thank you 🙂