Wouldn’t it be nice to have an internet-connected alarm clock that automatically sets itself, based on your calendar? You would never miss an early appointment, never forget to set your alarm, and enjoy more restful sleep knowing you’ve solved the nightmare of regulating your alarms. An internet-savvy alarm clock could even watch your inbox and wake you up if friends or family send you an important email.

This S.M.A.R.T. Alarm Clock (Setup for Meetings, Appointments, Reminders, and Tasks) uses the Arduino Yún, which is a special Arduino with two processors. One processor runs an embedded version of Linux and is connected to the internet over wi-fi or Ethernet. The other processor uses the same chip as the Arduino Leonardo microcontroller, allowing the Yún to work with most Arduino shields and accessories. By using the Arduino Yún, this project can talk to complex web services with the Linux processor, and interface with hardware — an LCD touchscreen — on the second processor.

The software for the S.M.A.R.T. Alarm Clock uses the Temboo service to communicate with calendar and mail utilities. Temboo is a platform for simplifying access to many web services, and it has great support for the Arduino Yún. To build this project you’ll need to sign up for a free account on Temboo’s website.

S.M.A.R.T. Alarm Clock currently works with Google’s Calendar and Gmail services. If you don’t have a Google account, make sure to sign up before starting the project.

In addition to those accounts, you need only an Arduino Yún with power adapter, microSD card, TFT touchscreen Arduino shield, and a USB speaker. The TFT shield will display the clock interface, while the USB speaker will play the alarm. Make sure to use a USB speaker that receives both power and audio over the USB connection, such as RadioShack #40-380. (some speakers send audio over a separate cable which won’t work with the Yún). The project software includes an annoying alarm clock sound that will jolt you awake, but you can substitute your own MP3 to wake up to something more pleasant.

If you’re new to the Yún, take a moment to read this guide and watch this setup video. You’ll want to make sure your Yún is connected to your wireless (or wired) network and has access to the internet before starting this project. Also, connect the microSD card to the Yún before it’s powered on, so it will mount the card as a root for storing the data used by this project.

1H1A5810

When you’re ready to get started, download the software, then follow the instructions below to build your S.M.A.R.T. Alarm Clock. The code for this project is a basic example of an internet-connected device that you can learn from and modify to build your own smart gadgets. If you have issues with the code or want to contribute, visit this Github page. Meanwhile, enjoy some quality sleep!

What will the next generation of Make: look like? We’re inviting you to shape the future by investing in Make:. By becoming an investor, you help decide what’s next. The future of Make: is in your hands. Learn More.

Project Steps

Set up a Temboo account

Before you begin with any hardware, you’ll need to sign up for a free account at https://temboo.com/. If you aren’t familiar with Temboo, you can find a video overview of the platform at https://temboo.com/videos#intro.

Once you’ve signed up for an account, go to the Account→Applications page and retrieve your Account Name, Application Name, and Key values as shown here. Save these values because they will be used in the configuration of the Arduino sketch.

NOTE: You’ll set up several accounts and logins for this project, so we recommend you use easy-to-remember credentials for all Temboo and Google steps — and open up a text editor or notebook to keep track of them.

Set up Google Calendar access

Follow the setup instructions on Temboo’s Google Calendar library to enable Temboo to access your calendar account: https://temboo.com/library/Library/Google/Calendar/.

Enable Calendar API access for your Google account in the Google Developers Console: https://code.google.com/apis/console/. Confirm that the Calendar API status is ON (see image one).

Next create a new Client ID and choose the “Web application” type. Set the Authorized Redirect URI as provided by Temboo’s instructions: https://{Your Temboo Account Name}.temboolive.com/callback/google

Also set the Authorized JavaScript Origins to https://{Your Temboo Account Name}.temboolive.com

Refer to the second image, but note that my Temboo account is “tdicola” and yours will differ. Once created, take note of the Client ID and Client Secret values on the result page.

NOTE: One step the Temboo instructions don’t mention is that you need to set a Product Name value on the consent screen page of the Google Developers Console. You can set any value, such as “My App Name,” like I set in the third picture above.

Run the “choreo” called InitializeOAuth at: https://www.temboo.com/library/Library/Google/OAuth/InitializeOAuth/. (Choreos are Temboo’s code shortcuts for various API requests, SQL queries, and such.) Specify the Client ID value you found in the previous step, and input the value https://www.googleapis.com/auth/calendar for the Scope. Once run, visit the authorization URL in the output, accept the permissions, and you should see a blank page.

Finally, run the FinalizeOAuth choreo at: https://www.temboo.com/library/Library/Google/OAuth/FinalizeOAuth/. Specify the Client ID and Client Secret values from the Google Developers Console, and the Callback ID returned by the InitializeOAuth choreo. Once run, remember the Refresh Token value that is returned in the output.

To recap, make sure you have the following values from the steps above before you continue: Client ID, Client Secret, and Refresh Token.

Save a Google Calendar profile

Make sure access to your Google Calendar account is working, and run the GetCalendar choreo on Temboo at https://live.temboo.com/library/Library/Google/Calendar/GetCalendar/. Fill in the Client ID, Client Secret, and Refresh Token values you gathered in the previous steps. For the Calendar ID value, specify your Google account name (typically your email address). See the image above with my example values.

The choreo should run successfully. If there are any errors, carefully follow the instructions in the previous steps to make sure you get the required Client ID, Client Secret, and Refresh Token values.

Click the Save Profile button and give the profile a name like “GoogleCalendar.” Save this profile so the Arduino sketch can access the calendar credentials through the saved “GoogleCalendar” profile.

Set up Gmail access

Gmail setup is simple. Go to the Gmail Inbox Feed choreo on Temboo at https://live.temboo.com/library/Library/Google/Gmail/InboxFeed. Enter your Gmail account username and password, then run the choreo to check that it runs successfully.

Save the profile for access to your Gmail account, just like you did for the Calendar account. Give this profile a name like “GoogleMail.”

NOTE: If the choreo fails to run and you’re sure your username and password are correct, try accessing your Google account’s security page to check if Temboo’s access has been inadvertently flagged as suspicious. Access this page at https://security.google.com/settings/security/activity and confirm the activity was from you. Wait a few minutes and run the Inbox Feed choreo again to verify it works.

Install the TFT Arduino library

Install the TFT library fork I’ve written to be compatible with the Arduino Yún: https://github.com/tdicola/TFT_Touch_Shield_V1/releases/download/1.1/TFT_Touch_Shield_V1.zip.

Import the downloaded zip file into the Arduino IDE as a new library. If you aren’t familiar with the library import process, consult this guide for more detailed information. Remember to use Arduino IDE Version 1.5.6-r2 BETA (not 1.0.5).

Download and install the Touchscreen library: https://github.com/tdicola/TFT_Touch_Shield_V1/releases/download/1.1/Touch_Screen_Library.zip.

Connect TFT shield to Arduino Yún

Connect the TFT Touch Shield to the Arduino Yún by inserting the header pins of the shield into the pins of the Arduino.

NOTE: The shield won’t sit completely flush, as the Ethernet port pushes it up slightly on one end. This is OK and should not affect the connections, just make sure the shield is pushed into the Arduino as far as it will go.

Format the SD card

The SD card must be formatted properly for the sound files to work. Follow the guide at playground.arduino.cc/Hardware/Yun#using_sd_card, particularly this instruction:

Create a folder on the microSD card called arduino/www starting from the root of the microSD card. This will let you upload your www folder when using wi-fi to upload.

In its factory setup, Yún supports the file systems FAT32 (including vFAT), EXT3/4, HFS(+), Reiser, Fuse, and NTFS. You can install additional packages for MSDOS, ISO, BtrFS, MinixFS, UDF, XFS, CiFS, NFS, and even AutoFS. FAT64 is not supported.

Windows should allow you to format a card in FAT32/vFAT/NTFS file systems by default (for vFAT it may say “Extended FAT,” and this option may be missing in XP).

Mac OS lets you use either HFS+ (“Mac OS Extended”) or vFAT (“ExFAT”), but HFS+ cards can be quirky in Linux, so it’s best to stick to one of the FAT file systems.

Linux users should have little-to-no trouble formatting the card in any of the other fully supported file systems.

Install Arduino Yún dependencies

Power up your Arduino Yún using the wall wart, and wait about 2 minutes for the Linux processor to finish booting. (All programming will be wireless, so we don’t recommend plugging the Yún into your computer.)

When you boot the Yún, it will create its own wi-fi network. Open the Yún’s web panel at arduino.local/ and configure it to connect to your home wi-fi network. The Yún will restart. Connect your laptop to your home wi-fi, open the Yun’s web panel again at arduino.local/, and copy the IP address.

Now connect to the Yún using SSH so you can access its Linux command prompt. Follow the steps at http://arduino.cc/en/Tutorial/LinuxCLI if you need more information on connecting to the Yún over SSH. Be patient, this can take 25 seconds or more.

Once connected to the Yún, run the following command: opkg update && opkg install kmod-usb-audio madplay alsa-utils python-openssl

NOTE: The command should fit on one line. Any line breaks in the text formatting above should be ignored.

Connect the speaker

Plug the speaker’s USB connection into the Arduino Yún’s USB Host port.

Set up the S.M.A.R.T. Alarm Clock sketch

Download the sketch for the S.M.A.R.T. Alarm Clock from: https://github.com/tdicola/SmartAlarmClock/archive/master.zip.

Unzip the archive and open the sketch in the Arduino IDE.

Toward the top of the sketch adjust the #define values to match your Temboo account details. Set TEMBOO_ACCOUNT to your Temboo account name, TEMBOO_APP to your Temboo application name, TEMBOO_KEY to your Temboo application key, and CALENDAR_ID to your Google account name (same value used in testing the calendar choreo earlier). If you used different names, adjust CALENDAR_CREDENTIALS and GMAIL_CREDENTIALS to the credential profile name you saved on Temboo’s site earlier.

Other #define configuration values don’t need to be changed now, but take a look to see other adjustments you can later make to the sketch. In particular the ALARM_FILE value points to an MP3 to use for the alarm sound. If you’d like to change the sound, put your own MP3 into the www subfolder and update the ALARM_FILE value.

Upload and run the sketch

Once the #define configuration values have been adjusted, upload the sketch to your Arduino Yún. Make sure to upload over wi-fi by selecting the “Arduino at (Arduino Yún)” port in the Arduino IDE. Don’t use the USB cable/serial connection for the upload or else the required Python scripts will not be installed!

Once the sketch is uploaded (it can take about 5 minutes, so be patient) the TFT display should refresh with a clock image. The current time will be displayed as both a watch dial and numerical formats.

NOTE: You can set the time by adjusting the time on the Arduino Yún at its web admin panel (typically accessed at http://arduino.local/).

Using the alarm

To test that the alarm sets itself based on calendar appointments, add an event to your Google Calendar for early the next morning. By default the alarm clock will only look at meetings before noon and set itself to go off one hour before the earliest meeting. You can change this behavior by adjusting the #define values ALARM_LATEST_HOUR and ALARM_BUFFER_MINS in the sketch.

After adding the event, press the REFRESH button on the clock. The clock should update to show the alarm in the upper right corner. The clock will check your calendar every two hours and set itself appropriately (this can also be changed in the #define configuration).

If an alarm is enabled but you’d like to disable it, press the CANCEL button. This will remove the alarm and stop checking for new alarms for the next 24 hours (or until you press REFRESH).

If the alarm goes off, press anywhere on the touchscreen to stop it.

NOTE: When you restart the Arduino Yún, the time might be displayed incorrectly, since the Yún needs to connect to the internet to get the current time. Press the REFRESH button to force the time to be refreshed a few minutes after the Arduino Yún finishes booting.

Using the wake-up e-mail

The Yún will periodically check your Gmail account for unread messages that contain “WAKE UP” in the Subject line. This allows family or friends to wake you up in case there’s an issue that needs your immediate attention.

To test this functionality, try sending yourself an email with the text “WAKE UP” in the subject. (This keyword is case-sensitive and should be in all capitals.) Press the REFRESH button to force the clock to check for new messages. The alarm should sound! (Press anywhere on the touchscreen to stop the alarm)

By default the clock will check for wake-up messages once every two hours. You can change this frequency with the ALARM_KEYWORD_MINS #define value in the sketch.

NOTE: Each mail check will cause a choreo to execute, and your free Temboo account allows 1,000 choreo executions per month.

You can also change the keyword used for wake-up mails by changing the GMAIL_ALARM_KEYWORD #define value. Remember this value is case-sensitive!

Now your S.M.A.R.T. Alarm Clock is fully configured and ready to wake you whenever it’s needed — and let you get some sleep when it’s not.