Theory behind this project
Another weekend project that I’ve been working on is Wake-up light. Lately I’ve been doing more research on sleep phases and how to “hack” your brain to wake-up more refreshed and adjust your sleep cycle. There are many studies out there explaining this and providing scientific evidence, so if this is something you are interested in, I encourage you to go and get more detailed information on this subject. However I won’t go into too much detail, I’ll just try to give very simple explanation: When you sleep, you are either in REM or deep sleep (NREM) phase. When you wake up in REM phase you feel fresh, relaxed and full of energy. When you are woken up during the deep sleep phase, you feel like you’ve just been hit by a bus, and you take long time to actually wake up.
All life evolved in response to predictable patterns of light and darkness, called circadian rhythms. Modern day electrical lighting has significantly betrayed your inner clock by disrupting your natural rhythms. Little bits of light pass directly through your optic nerve to your hypothalamus, which controls your biological clock. Light signals your brain that it’s time to wake up and starts preparing your body for ACTION. [source]
Problem is that when you set your alarm clock to 6:15, your smartphone is probably not meant to be the device that knows when is the optimal time to wake you up, it will ring at 6:15 no matter if you are in REM or NREM phase.
So for me I’ve found that solution for this problem is not the smart sophisticated one, it’s actually a very simple one.
Here is how it works: Device can control light source and also allows you to set up the alarm. When you set up the alarm to wake you up at 6:00 AM, the device will actually start turning on that light source very very gently and will take anywhere from 30min to 60 minutes to go from off state to full on. While light is in transition for those 60 minutes, you will also eventually transition into a REM phase and your optic nerve will register that there is light in the room and that is time to wake up. This way you will wake up feeling more fresh and be ready for a new day.
How to make it
For this project we will need a small microcontroller, LED strip and RTC (real time clock) for time keeping and 12V DC power supply.
I’ve selected PIC12F1822 as my weapon of choice, it’s very tiny but it has everything that we need for this project and I had it laying around. Also we need a warm white LED strip, power MOSFET for turning on the LED strip and also a RTC chip for time keeping.
Let’s start with briefly explaining the schematic:
J1 is your +12V DC connector that will provide power to the system and also LED strip.
J2 is connector for your warm white LED strip.
MOSFET Q1 is used for switching the LED strip
U3 is a LDO to regulate voltage from 12V down to 5V.
U2 is RTC chip that has 32.768KHz crystal and also is backed up with CR2032 battery to maintain time keeping when power is off.
U1 is our PIC that uses I2C to communicate with RTC, continuously comparing current time with previously set alarm time, and if the current time is X minutes before the target alarm, it will start to provide PWM output on the RA0 pin, slowly turning on LED strip from completely off to full on in ~60 minutes.
There is also UART communication between PIC and HC-05 module that can be used for setting up current time or setting up alarm time and tweaking light turn on speed (this is optional).
Also we can use RTC’s SQW output pin to generate heartbeat signal or to acknowledge that configuration has been stored.
Now let’s go to the firmware part:
Firmware in this project is pretty straight forward, MCU pools current time from the RTC over I2C in predefined intervals. When MCU compares current time with set alarm time and detect that we are 60 minutes away from target, it enters another loop where it will increase the duty cycle of the PWM output on RA0 by 1, sleep for x seconds and then repeat until PWM duty cycle is 100%. When PWM reaches maximum, it will stay in that state until button is pressed.
For communicating with the device we will use UART. We can send when do we want to be waken up, how long should it take from lights off to full on and also how long before target time should we start turning on the light.
If you are curious to see more how this project works or you want to build this project for yourself, all source files, instructions and everything else that you need to build this project yourself, it’s available to you on my GitHub page.