Digital alarm clock

Benjamin Hendrickson

Overview

In this project, I chose a clock that can display time, temperature in degrees Fahrenheit and even has an alarm clock built into it. The alarm can be adjusted based on the time you want to wake up at and has a beeping sound. The clock can be powered either by batteries or you can plug the clock into a USB port. The screen displays the time in military time, the month, day and year beneath it and the temperature in the top right in °F.

General view

Hardware

For this project, I used a Freescale MKL05Z32VFK4 Kinetis microcontroller from the KL05 Kinetis family series because of how efficient it is, and that it has a good low power mode capability. For the display, I used a 2x8 character Newhaven LCD display with a backlight if it is plugged in by a USB. The time is updated by the DS3231MZ real-time clock. The DS3231MZ real-time clock is powered by a CR2032 battery when the alarm clock is not powered on to keep the time updated. The temperature is read from the Silicon Labs Si7051 sensor which has low power capability and highly accurate digital temperature sensor.

Schematic Assembly

The microcontoller runs in Low Power Run mode when active, so the device consimes slightly above 1 mA of current. The CPU clock frequency in this mode is 4 MHz with the bus clocked at 0.8 MHz. This is more than sufficient to implement all clock functions. The sensor and RTC chips are placed on I2C bus. The RTC is configured to pulls the INT pin low at the beginning of every minute. This generates an interrupt in the microcontroller that wakes it up from sleep and leads to reading time from it to update the LCD readings. At the same time the new time is compared with the alarm setting and, if enebled and the match occurs, the alarm buzzer is activated.

Software

This program first configures the hardware and runs through the setup routine. When the main loop runs, checks to see if the buttons are pressed and performs the function based on the current clock state and the button you pressed. This program also puts the microcontroller to sleep and wakes it up every 20 milliseconds to save power and efficiently use the battery life. In state 0, at the end of each loop, if the alarmOn variable is equal to 1 (meaning the alarm is turned on), the current time is compared with the alarm time and if the alarm time is equal to the current time, the buzzer starts to beep. Here is the button usage and the main FSM implemented in firmware.

fsm

Here:

B1
Button 1 (left button/change state button). This button is used to change the clock states.
B2
Button 2 (middle button/increase button). This button is used to increase the hours and minutes.
B3
Button 3 (right button). This button changes the clock mode to state 0 and turns the alarm on if it is off and vice versa.

Final Thoughts

I had fun coding and designing this clock and I intend to use this next to my bed since it has a good low light feature. I have learned that microcontrollers are pretty neat and can do tons of things with them that I've never known, the best part is too that they aren't that expensive and can be pretty powerful.

Downloads


Last modified:Mon, Jan 23, 2023.

00082