bluetooth sunrise alarm clock + iRise smartphone app

idea

This time I had the idea of creating a sunrise alarm clock. I know they are available for buying, but still I wanted to create my very own version.

My idea was to use an Arduino microcontroller and some RGB LEDs. The sunrise alarm clock should work without a display. A smartphone app should be used to connect via bluetooth to the alarm clock. The smartphone app should be able to set the time, the alarm, steer the LEDs, etc. .

make it happen

With an example I figured out how to create a ’normal‘ Arduino alarm clock using an RTC. This example was easily adapted to steer the RGB LEDs and to integrate the HC-06 bluetooth controller.

principal scheme of hardware setup + working mode

IMG_20151128_114853_principalscheme

I left out the on/off switch and the battery in the basic scheme. It is obvious.

It is definitely recommended to change the name and the PIN of the bluetooth module as described in the bluetooth cookbook.

Switching the alarm on at the time desired was easy. But how to turn the alarm (light) off again? Using the smartphone might be tricky in the morning. I was also thinking of a proximity or a light sensor but this could be error-prone. The next best thing I thought of was a capacitative touch sensor instead of a switch. In the end I realized three possibilities to turn the alarm off:

  • using a simple capacitative touch sensor
  • using the iRise app to send the off command
  • an automatic timeout

The bluetooth controller is connceted to the Arduino as a serial device. A simple Serial.read() does the trick and reads the characters sent via bluetooth. Sending data back is possible using the Serial.write() function.
Before creating a dedicated smartphone app the bluetooth connection can be tested with a bluetooth terminal app from the play store.

protocol

I invented some codes for communication via bluetooth to steer the basic functionality of the alarm clock such as

  • setting the actual time: i12:34z
  • setting the alarm time: s07:30z
  • stopping the alarm: tz
  • turning the RGB LEDs on: c0..9z
  • sending back the current time of the clock: bz

The character ‚z‘ marks the end of a command.

Since I do not want to give anyone the possibility to launch „Denial-of-Sleep“-attacks I will not publish the codes I really use. 🙂

libraries

To avoid a long and confusing Arduino program it is possible to create C++ libraries. For the alarm clock functionality and driving the RGB LEDs I created two simple Arduino libraries.

hardware

In the end I transferred the project to a clone of an Arduino Pro Mini. This small plate has all the required connections and has a minimal size for a reasonable prize.

iRise smartphone app

The smartphone app ‚iRise‘ is pretty straightforward. I decided to go for plain Material design. On http://www.androidhive.info/2015/04/android-getting-started-with-material-design/ I found a good example to start with.
Numerous examples explain how to find and pair a bluetooth device. E.g. http://www.tutorialspoint.com/android/android_bluetooth.htm or http://examples.javacodegeeks.com/android/core/bluetooth/bluetoothadapter/android-bluetooth-example/ explain everything.

rainbow and mood light

The bluetooth sunrise alarm clock can do some more: it also serves as a mood light. Several single colors can be selected in the app. Alternatively a rainbow color change or blueish night mode can be switched on.

The bluetooth state is displayed on another fragment of the app.

extending iRise

Another idea for extension is to capture smartphone notifications such as calendar reminders or incoming messages. Such notifications could trigger the sunrise alarm clock to blink in a dedicated color. This could be solved using a service and a user activated listener as well as the smartphone to be near the alarm clock for a working bluetooth connection.

Another possible extension is to measure the battery voltage to estimate the remaining battery time.

components used

Clone of Arduino Pro Mini 
Lilypad RGB LEDs
RTC – real time clock module
HC-06 bluetooth module
capacitative touch sensor
rechargeable 3.7 V battery
slide switch
buzzer
cables
FTDI cable
for development and testing: Arduino Uno
a box for the clock

For simplicity I used the Lilypad RGB LEDs. They bring the required resistance along. But any other RGB LED or even a RGB LED strip (5V!) will do as well.

software development

Arduino IDE from https://www.arduino.cc/en/Main/Software
Android Studio from http://developer.android.com/sdk/index.html

good to know

Whenever the Arduino sketch is transferred to the board the bluetooth adapter may not be running because it is using the serial connections. Simply remove the power of the HC-06 before the software upload starts and put it back afterwards if required. A reversible connection between the VCC input of the bluetooth module and the power source is a good solution for software updates.

During development it might help a lot to attach an LDC display the the Arduino to display the current settings of the alarm clock.

some pictures and a screenshot

 

source code examples

sunriseclock.ino

AlarmClock

RGBLED

BluetoothUtils.java

construction of a box

This was not simple. One of the first ideas was to construct a paper box. But this is not a durable solution. So the box will be -under construction- for a while! Maybe it will be a wooden box with an acrylic glas top in the end.

references

https://github.com/pAIgn10/AlarmClock

http://arduino-hannover.de/2013/07/20/bluetooth-kochbuch-fur-arduino/

http://lilypadarduino.org/?page_id=548

https://www.arduino.cc/

 

FTDI troubleshooting

While working on an Arduino based project I was suddenly not able to upload sketches using an FTDI anymore. From one minute to another I received errors such as

avrdude: stk500_getsync(): not in sync: resp=0x00
avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x51

when trying to upload a sketch to an Arduino Pro Mini or Lilypad.

I checked several possible causes such as

 

But the error persisted. None of the possibles causes I checked was responsible.

With the tips in this forum entry I found out that my (original) FTDI chip was the problem, somehow the TX line went dead. Further tests on Linux confirmed this. How and why this happened is unclear.

My final solution? I had to buy a new one…