Introduction: Sunrise Alarm Clock With LCD Display and Bluetooth App
Wintertime can be sad. You wake up, it’s dark and you have to get out of bed. The last thing you want to hear is the annoying sound of your alarm clock. If you, like me, have trouble waking up in the morning this alarm clock is just what you need.
In this tutorial, we are going to build a Sunrise Alarm Clock. It's an alarm clock like any other in that you can set the hour and minute you want to wake up, but with the benefit of using light to brighten up your bedroom over a period of time like a sunrise to wake you up instead of an annoying buzzer!
We will also be using a bluetooth module to create an app that let's you set the alarm via your phone onto the clock. The LCD display will show the tiime, date and day of week.
Sunrise lamps exist on the market but they can be expensive (a quick search on Google returns products in the €100 range), fragile and quite clinical-looking. That's why I decided to make my own for my Arduino School Project. All the parts will be listed in the next step. The code can be downloaded from my Github repo sunrise-alarm-clock. Let's begin :)
all code can be found on: https://github.com/Sjorsv/sunrisealarm
Step 1: Gathering the Parts
We'll be using a clock as our input and an ultra-bright LED as our output to simulate our sunrise.
To build the circuit we will need :
- Arduino Uno
- clockmodule RTC DS3231
- a MOSFET to control the brightness of the light
- a super-bright LED (I bought 2, one warm, one cold)
- 9V battery to power the LED
- a breadboard
- a LCD Display (16:2)
- Bluetooth adapter hc-05 so we can use an app to set the alarm.
Everything you need can be bought on www.martoparts.nl
Step 2: Assembling the Circuit
You can refer to the sketch for my circuit, unfortunaly I coudn't find the RTC DS3231 in the program so I had to do with this one. Connections are a bit different in real, here are the connections. (the bluetooth module is not in the sketch but I will explain how it works below cause it rather tricky)
RTC DS3231
GND goes to GND on the arduino
VCC goes to the 5v
SDA goes to arduino
SCL goes to arduino
We won't use SQW & 32K
MOSFET
Gate pin goes to pin~9 on the Arduino Uno because it's PWM
Drain pin goes to the negative side of the LED
Source pin goes to GND on the Arduino
LCD-Display
GND goes to GND on the arduino
VCC goes to 5V
SDA goes to A4 on the arduino
SKL goes to A5 on the arduino
LED
- goes to mosfet
+ goes to the 5v
9v battery
You can buy a 9v battery in any local shop, plug into the arduino with a connector strip.
Bluetooth module hc-05
5V goes to 5V from the arduino
GND goes to GND on the arduino
Now there's 2 more inputs but here comes the tricky part, we have to connect the opposite inputs of those 2 on the arduino
TX from hc-05 goes to RX on arduino
RX from hc-05 goes to TX on arduino
Important: Make sure you DISCONNECT the TX & RX from the HC-05 when you're uploading code on your arduino or you will get an error saying "something went wrong with uploading the code" in the compiler.
Step 3: Setting the LCD Display & Clock
The library used for the LCD display is liquid crystal and can be found at: https://github.com/fdebrabander/Arduino-LiquidCrys... Download the zip file, save it and place it in your Arduino's /libraries folder
The library that I'm using to run the clock can be found at Rinky-Dinky Electronics http://www.rinkydinkelectronics.com/library.php?id=73 and make sure you are on the DS3231 page. Download the zip file, save it and place it in your Arduino's libraries folder.
Time
Include the library DS3231 or DS1307 in your arduino code
Uncomment these 3 lines of code to set the time:
// rtc.setDOW(MONDAY); // Set Day-of-Week to SUNDAY<br>// rtc.setTime(23, 57, 0); // Set the time to 12:00:00 (24hr format) // rtc.setDate(14, 1, 2019); <br>// Set the date to January 1st, 2014
LCD Display
Include the library liqduicrystal_i2c in your arduino code
To print on the LCD Display use
lcd.setCursor(col,row) // position of text printed
lcd.print(~) // text printed
Step 4: Coding
Download the code on: github: https://github.com/Sjorsv/sunrisealarm
Uncomment these 3 lines to set the clock on your LCD display:
// rtc.setDOW(MONDAY); // Set Day-of-Week to SUNDAY<br>// rtc.setTime(23, 57, 0); // Set the time to 12:00:00 (24hr format) // rtc.setDate(14, 1, 2019); // Set the date to January 1st, 2014
Use lcd.setCuros(col,row); to set the position of text on display
lcd.setCursor(0,2);
and print() to print something on the display
lcd.print(rtc.getDateStr());
Change these variables if you want to
<br>int fadeTime = 1; // How long the light will fade to max<br>int setHour = 02; // Set hours to wake (military time)<br>int setMin = 49; // Set minute to wake <br>int uled = 9; // Set pinout with PWM
Bluetooth module code
String firstHalf = getValue(input, ':', 0); // check first input untill ":"
String secondHalf = getValue(input, ':', 1); // check second input after ":"
// use this code if you're not using the bluetooth module // //if (t.hour == setHour && t.min == setMin) // Check if it's time to wake up! // { // start(); // }
// check first 2 digits inputs, then check second 2 digits of input if (t.hour == firstHalf.toInt() && t.min == secondHalf.toInt()) { start(); } }
// logic to seperate strings String getValue(String data, char separator, int index) { int found = 0; int strIndex[] = { 0, -1 }; int maxIndex = data.length() - 1;
for (int i = 0; i <= maxIndex && found <= index; i++) { if (data.charAt(i) == separator || i == maxIndex) { found++; strIndex[0] = strIndex[1] + 1; strIndex[1] = (i == maxIndex) ? i+1 : i; } } return found > index ? data.substring(strIndex[0], strIndex[1]) : ""; }
Step 5: Time for Testing!
Compile your code & test if the components work!
Step 6: Bluetooth App Set-up
Because I found it annoying to dig into the code everytime I wanted to set an alarm I wanted to make a app that would set the alarm, which is way easier.
Go to http://ai2.appinventor.mit.edu
here we can make a simple app that lets us set the alarm, i've included the simple design set-up (you can always tweak this later) and the code used for the bluetooth connection.
You can then publish your app and connect with it on your phone by using a QR code or directly downloading the app on your computer, then porting it over with cable on your phone. (screenshot)
Step 7: Building the Case
You can always build a different case around your arduino clock. I used wood and matte plexiglass to construct my own alarm clock case. I chose matte plexiglass so you can see the light clearly shining through the case but you cannot see the inside of the clock.
Step 8: Finished!
Now that you have uploaded the code to your arduino, build the case and checked if you properly assembled your clock, you can set an alarm on the bluetooth app and start waking up more naturally! :)