Bluetooth Wake-up Lamp

Tatsum Seldl

Overview

The purpose of this project is to create a lamp that uses a sunrise effect to wake a person up in the morning at the optimal point in their sleep cycle. Traditional audio alarms startle people in order to wake them from sleep. By contrast, this lamp helps to ease someone awake by mimicking the color and brightness changes of a natural sunrise. Additionally, traditional alarms wake a person up only based on a specified time. However, research on sleep has found that a person may feel less tired when they wake up, if they wake up at a certain point in their sleep cycle, which in total can last about 70-120 minutes [1]. Thus, this lamp alarm clock uses sleep cycles to calculate the optimal wake up time for a person, based on a target wake up time they choose. Finally, because many people read books or spend time on their phone before bed, this lamp will turn off and calculate the optimal wake-up time after the person puts their book or phone down in front of the lamp before falling asleep. The lamp turns off 30 seconds after having an object placed in front of it and will return to full brightness if the object is removed before it turns off. Overall, the lamp designed in this project will create a more enjoyable sleeping and waking up experience.

Detect demo Sunrise demo Bluetooth

Hardware

The main controller used for this project is the BG22-EK4108A Microcontroller Development Kit from Silicon Labs. A strip of 10 LEDs is cut from the WS2813 RGB LED Strip to provide the colored light in the lamp. The VL53L0X Time of Flight (TOF) sensor is used to measure the proximity of an object in front of the lamp. An A118 M5Stack connector, for the LEDs, and the proximity sensor are soldered together on a board. Jumper wires are used to connect this board to the microcontroller, so that the proximity sensor is perpendicular to the microcontroller and can properly measure distances. Last, these components are mounted inside a lamp shade and a 3D printed lamp base.

Front view Back view Bottom view Inside view

Additionally, a device that is BLE compatible and has the Simplicity Connect app downloaded is needed to modify the initial time and the target wake up time.

Schematic Board layout

Software

The software for this project was written in C and was developed using Simplicity Studio and the Simplicity Connect app to test the Bluetooth functionality. The program begins by initializing the VL53L0x proximity sensor, the WS2813 LED strip, and a sleeptimer to create an event that occurs every minute. Next, the app process action begins.

First, the program checks the current state of the light (on, dimmed, or off) and sets the appropriate value to the LED strip. Then, the proximity sensor performs a check to see if anything is within 90 mm of the lamp. If nothing is detected, the lamp remains at full brightness, and no wake-up time is calculated. If an object is detected during the proximity sensor check that was not detected last time, the program records the detection and the time it occurred, and it dims the lamp by setting the LEDs to a yellow color.

Otherwise, if an object was already detected and it has been 30 seconds since the initial detection time and no wake-up time has been calculated, the lamp is turned off and the program calculates the optimal wake up time. The program calculates wake-up times for 3, 4, and 5 sleep cycles after falling asleep, using 90 minutes as the duration of a sleep cycle and including a 15minute period of time to fall asleep. Thus, wake up times are calculated by: current time + (duration of one sleep cycle * number of sleep cycles) + time to fall asleep. Then, the wake-up times of 3, 4, and 5 sleep cycles are compared to the target wake-up time that the user enters, and the number of sleep cycles with the closest wake-time is chosen as the calculated optimal wakeup time. All of these calculations and comparisons were completed by converting the wake-up times to just minutes.

A minute event also occurs every minute in the program based on the sleeptimer. Every minute, the program updates the calendar that is implemented and gets the value of the current hour and minute. These times are then compared to the calculated wake-up hour and minute. If there is not a calculated wake-up hour and minute (signified by a value of –1), this event does nothing. If there is a calculated wake-up hour and minute, the program compares the current hour and minute to the calculated time. If they are not equal, nothing happens. If they are equal, the LEDS are set to on, and the sunrise animation begins.

The sunrise animation goes through a list of predefined sunrise colors and fades from one color to the next until the lamp is at full brightness. The code for the fade effect is based on the code found here [2] but has been modified to work within the setup of this project. To create the fade effect, each color is separated into its individual red, green, and blue components. Then a delta value is created for each component by subtracting the value of the target color from the current color and dividing it by the number of steps taken between colors. Then, the delta value is added to the current color for the number of steps between colors, with the program waiting for 125 ms on each color. Once the target color is reached, the program waits for 10 seconds on that color and then begins the next transition. Once the sunrise animation is complete, the time of completion is recorded. Finally, the minute event uses the time of the completed sunrise animation to leave the light at full brightness for 10 minutes, before it turns off. Once all of this is completed, the calculated wake hour and minute are reset to –1 to prevent the sunrise from being retriggered. The final part of this program involves the implementation of the Bluetooth features. A Bluetooth connection is established between the lamp and the device running the Simplicity Connect app. A simple user read request and user write request are used to view and change the target wake up hour and minute in the app. User read and write requests are also used to view and change the current time in the app but structs had to be used to properly handle the data. The structs that are used in the program to hold the current time are based on the structs found here [3]. The Bluetooth requests for the current time read from and write to the date time variable implemented in the calendar used in the program.

Final Thoughts

Overall, I really enjoyed completing this project. In the beginning, it was a little overwhelming to select a project, and I wasn't confident in my abilities to accomplish my goal.

As I continued working on my project though, I learned more with every part of the program that I completed and my confidence in my understanding of embedded systems and microcontrollers kept growing. I liked having the freedom to work on a project I selected for myself, because I was much more interested in the concepts I was learning and more eager to learn other aspects of microcontrollers. I did struggle with motivating myself to work on my program, but as the weeks went on, I developed a work schedule that helped me to complete my project on time.

If I were to do this project again, I would like to add an external power source that connects to some sort of button or switch. That way the power to the lamp could be shut off or on without having to unplug it. Additionally, one other thing that I would do differently is look into other ways to set the current date and time that the lamp uses, so that the user doesn't have to set it manually.

References

  1. Stages of Sleep: What Happens in a Sleep Cycle
  2. Fade whole strip from one color to another
  3. KBA_BT_0908: Using RTCC as Timer or Calendar while running BLE stack

Downloads