Introduction: Alarm Clock With Wiring (or Arduino)

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.

Functionalities:

  • 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):

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.

Audio amplifier

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.

EEPROM

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, MONO). 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.

Acknowledgements

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.

Comments

author
germap (author)2016-04-02

This project was recognized as one of the Arduino Christmas Contest winners, and awarded an Arduino UNO WiFi on April 2, 2016. See the announcement here: http://www.arduino.org/blog/1-the-new-blog/announcement-of-christmas-contest-winners. That was simply great!!!

arduino-uno-wifi.png
author
gabontz (author)2016-04-04

Hello,

Is myDS3231.h different from the original DS3231.h?

Can you post the code for it if is changed?

Thanks!

author
germap (author)gabontz2016-04-04

Hi!

Yes, they are different. Look at the 3rd step, there is an attachment (wiring-v1.0.1-dev.7z) that includes the whole set of customized libraries I ended up using for the alarm clock.

Regards.

author
zoomx (author)2016-02-03

Great project!

In the festivos Array 150518 mean 18/05/2015 ? So you put all holydays till 2030?

author
germap (author)zoomx2016-02-03

Thanks! You're right, it means 18.05.2015 and there are holidays until 2030.

author
sheena-tech (author)2015-11-26

Loved the tutorial. Instructions are clear, concise, and easy to understand.

author
germap (author)sheena-tech2015-11-26

Glad you love it sheena-tech! :)

author
ajoyraman (author)2015-11-26

Excellent cobtributiopn!

author
germap (author)ajoyraman2015-11-26

Thanks ajoyraman!

author
WilliamKerala (author)2015-11-24

Good work my brother. You have a wonderful music on that video! Please share the title of that music. Thanks in advance

author
germap (author)WilliamKerala2015-11-24

Nice that you like the beautiful "música Andina" (Andean music). The song is "Lluman Tio" by Inkari. Find it here: https://www.youtube.com/watch?v=j5B0IQB-qX8 Regards!

author
WilliamKerala (author)germap2015-11-24

Thank you very much.

author
JulieE7 (author)2015-11-24

Technology has really made the world much smaller than ever before. I also recently develop a page for Iot apps http://www.mobilepundits.com/internetofthings.html... kindly have a look and share your thoughts.

I am looking forward to reading your next post. Cheers !

author
andreinour (author)2015-11-24

Great tutorial, and awesome finished product. Thank you for sharing it!

author
germap (author)andreinour2015-11-24

Thank you very much andreinour! Glad you like it! Very pleased to share
this kind of work, which is only possible because others
shared theirs.

author
seamster (author)2015-11-24

Very impressive work! The finished clock looks great, and your documentation is very well done. Thumbs up! :)

author
germap (author)seamster2015-11-24

Thank you very much for your words! The best part is that my wife likes it :)

About This Instructable

9,280views

122favorites

License:

Bio: My hobbies are surpassing the time I devote to my (serious) work!
More by germap:Rotational Christmas Ceiling DecorationAlarm Clock With Wiring (or Arduino)Soccer Penalty Kicks Game with Wiring and Arduino
Add instructable to: