This is an alarm clock built on the Wiring microcontroller and customized for Colombia (it takes into account holidays and displays all texts in Spanish). The alarm clock displays hour, date, Moon phase, customized messages by day, as well as icons to indicate active alarms. There are two alarms and a warning that sounds after 'X' minutes (very useful when cooking).
The motivation behind it stems from my concern about sleeping near a cellphone/smartphone (you know, waves) just to wake up in time in the morning. I wanted my wife not to use her cellphone/smartphone for that, but another alarm clock. As I was learning some electronics I took this as an opportunity to build a customized one, that could play nice sounds to wake us up.
In the end, it was a very entertaining project for me and an original gift for her. I recommend you building this project for learning how a variety of electronic components work and can be used together.
- Display hour/date and day of the week.
- Display current day's Moon phase.
- Sound played every sharp hour (from 8am to 10pm).
- Sound played every day at 10pm for going to bed.
- Two configurable alarms.
- Alarms can be set forweekdays, weekends, only once, or all days.
- 10 minutes snooze by default and optional extra 10 minutes snooze.
- Countdown for warning with a sound when something is ready (e.g., a meal).
- Display custom messages all day long.
- Display which alarm isactive (if any) and whether or not the countdown is active.
- The alarm clock can be disconnected from power and all configurations (including hour/date and alarms) are safely stored and recalled.
- When setting minutes (hour or alarms), each Up key press goes 5 minutes forward, whereas each Down key press goes 1 minute backward. This helps to set time faster, for example, it avoids having to press 30 times a key going from 1 to 31, instead, you can do it by pressing Up 6 times.
- Everything is displayed in Spanish, but you can tweak the source code and replace it with your language.
- Weekday alarms are deactivated on (Colombian) holidays. You can, of course, set your own country's holidays in the source code.
- You can turn off any sound (while being played) by pressing any key.
Step 1: Materials
To build this alarm clock we use the following components (besides basic materials such as jumper wires, stripboard, solder, and the like):
- Wiring S microcontroller http://www.robotshop.com/en/wiring-s-microcontroller-development-board.html or a powerful enough Arduino (not an Arduino UNO). The main requirement to be fulfilled is a flash memory greater than 32KB. [$25 - $30] Where to buy the Wiring S?
- Speaker 0.5W 8Ω : https://www.sparkfun.com/products/9151 [~$2]
- MicroSD card adapter (http://www.gearbest.com/development-boards/pp_43070.html) and MicroSD card (mine has 1GB of storage capacity, however, this project doesn't require that much). The MicroSD card is mainly used for storing audio files, which easily exceed common microcontroller storage capabilities. We also use it to store text files that contain custom messages. [~$8.5]
- DS3231 Real-Time Clock: http://tronixlabs.com/breakout-boards/real-time-cl... [~$5]
- 16x2 LCD (Liquid Crystal Display): http://linksprite.com/wiki/index.php5?title=16_X_2... [$12 - $15]
- Power Supply AC/DC adapter (Output: 9V 1A): http://www.amazon.com/9V-DC-Power-Adapter-Supply/dp/B004LX146Q Used to power the alarm clock. [$5 - $10]
- 0.22µF and 100µF capacitors.
- P2N2222A transistor.
Step 2: Main Circuit
The LCD needs several pins from the microcontroller: 5V, Ground, analog input (for the push buttons), and 6 digital pins. In the Wiring S, we connected pins 10 to 15 to the LCD pins. See correspondences in the Fritzing diagram.
We connect the other 5V and Ground from the Wiring S to a small circuit that powers the the MicroSD card adapter and the speaker. The clock is powered using one of the 3.3V pins from Wiring S. The sound emitted by the speaker might not be loudly enough for waking you up. We actually attempted to use a variety of sophisticated amplifiers such as this and this, with no success (impossible to get rid of noise). The circuit that best worked for us was a very simple one: One-Transistor Audio Amplifier. Note that Wiring S' pin 6 gives the audio output.
Connecting the DS3231 clock to Wiring S is easy because SDA and SCL ports are written down in both components. The MicroSD card adapter is connected this way: MISO->22, MOSI->21, SCK->23, and CS->20.
If the Fritzing diagram image is not clear enough, just download the original Fritzing diagram file and interact with parts and wires to make sure of connections.
Step 3: Source Code and IDE
The source code of the project can be accessed from my electronics repository in GitHub. Feel free to examine the code, use it (just give the credit when is due), and suggest improvements.
We use the Wiring v.1.0.1-dev as IDE (Integrated Development Environment), which is currently available only on Windows and Mac OS (:( we miss the GNU/Linux version).
For using common Arduino libraries such as TMRpcm (for playback of WAV files from SD cards) on Wiring, one needs to tweak their source code, for example, by including Wiring.h instead of Arduino.h. Since it turned out to be a bit of a pain, we also share the whole Wiring folder, including configured libraries for avoiding you such process.
In order to make hour and alarm settings perdurable we use the EEPROM (Electrically Erasable Programmable Read-Only Memory) (2KB) provided by Wiring S. The source code is optimized in such a way that it prevents to write to the same EEPROM address too many times (EEPROM memory has a lifespan based on the number of read/write operations). For instance, when setting minutes, we only write the final number and not intermediate ones. We use 11 EEPROM addresses to store 4 variables (enabled, type, hours, and minutes) for alarm 1, 4 (enabled, type, hours, and minutes) for alarm 2, and 3 (enabled, hours, and minutes) for warning mode.
Moon phase calculation
We borrow the function for calculating the Moon phase from http://www.ben-daglish.net/moon.shtml and adapt it to C++ code. It's a function based on an algorithm by John Conway, which usually gives the correct Moon phase. It's not exact, but the error is negligible for our purposes.
Step 4: Assembling All Electronic Components Into the Box
The design of the final box was made using the Maker Case web application. It really makes things easier, since you can set your box dimensions, as well as define round and rectangular holes. The final design was cut in MDF with 5mm of thickness.
The LCD was a bit tricky to fix, we decided to let some rectangular hole in right and left sides of the box, but in the end this is something we regret, as the aspect of those sides is not the best, and we had to put some white tape to make them look better. You can of course choose whether to take our design or improve it.
We used some screws to fix electronic components to box sides and wood glue to paste the box sides. The speaker was fixed using cold silicone.
As you can observe, all settings of the alarm clock are controlled using five buttons. There are four directional buttons (Up, Down, Left, Right) and one Mode/Enter button. Buttons are made of a balsa wood stick with 4mm of thickness. We decided not to paint the buttons because it's relatively clear what their function is, but you could of course adjust this part of the design.
Step 5: Special (custom) Characters
We needed some special characters to display alarm statuses and Moon phases. There is room for 8 special characters in flash memory (PROGMEM). For each special character we used a web tool (http://fusion94.org/lcdchargen/) to obtain its binary representation.
We defined these characters: Moon phases (4), 'point above' (1), heart (1), smile (1), bell (1).
Step 6: Audio Files and Custom Messages
Playback of audio files with the library TMRpcm requires the WAV format (8 bits, 16kHz). We have used several mp3 files from Internet and converted them to the required format using a very effective online audio converter. Even though WAV 8 bits-16kHz is a limited format, audios are certainly audible; you can get some clue watching and listening to the video in the first step. The library we use allows us to set the volume for each audio, which is useful to give some audios more strength (e.g., to the warning audio). Audios must be stored in the MicroSD card. I formatted mine using the FAT16 file system.
On the other hand, custom messages can be programmed for each day. Think of special dates such as a birthday, a holiday, an appointment you shouldn't miss, you name it. Each message must be stored as a text file in the MicroSD card. Messages must end with a semicolon, which won't be displayed. The name of such file tells Wiring when to display it in the LCD, i.e., the file name is a date (with no extension) such as 151123 (for a message that will be displayed on November 23, 2015) or 1225 (for a message that will be displayed every December 25). As a rule of thumb, longitude of messages should be shorter than 25 characters, but nothing prevents Wiring from showing very long messages.
Step 7: Finishing Touches
For painting the box you might need several layers of white paint. We added some small red hearts to different sides of the box, we found them in the store where we got the MDF cut.
We also pasted a 3mm cork layer to the bottom side of the box to make it harder to displace when pressing buttons.
Finally, we added a foam layer (taken from a laptop box) in the back hole so that electronic components are not exposed to dust.
I would like to thank Hernando Barragán (creator of Wiring) for the support given in the Wiring forum, which was indispensable for building this project.