LED Light Sunrise Clock with Raspberry Pi

This page describes my experiences building a custom coloured LED light that works as a visual light alarm clock, powered by the Raspberry Pi computer.

The Problem


LED Light Sunrise Clock with Raspberry Pi

My LED Light Sunrise Clock w/ Raspberry Pi.
Way back in 1998, I really wanted to buy a piece of new technology, the "Sunrise Alarm Clock", which had the special quality of switching on a light one hour before your wake-up time, and gradually increasing the brightness until your alarm goes off. The theory behind this is that even when your eyes are closed, your brain is still stimulated by bright light that you can sense threough your eyelids. Looking at human evolution, this makes sense. On a bright Cro-Magnon morning a couple of million years ago, as the rising sun shone on your grimy face, this would have caused your brain to flood your system with "wake-up" signals, as it was obviously time to get up and murder some delicious mammoths with stone axes. Today, a sunrise alarm clock is supposed to mimic that primordial circadian rhythm, prepping your body to wake up slowly, stimulating your pituitary gland so that you have a nicer, more naturally transition than being jolted from a deep sleep by loud noises. Sunrise clocks are used by people who have trouble waking up at the correct time, be it because they are shiftworkers, living in a northern clime, or just played a little too much Grand Theft Auto the night before. Sounds great. Still, those lights were costing about $500 back in '98, being serious boutique electronics, which put their price out of reach for me. For a long time, I thought that I would never own one of those things and I stopped thinking about it.

The Inspiration


LED Light Sunrise Clock with Raspberry Pi

Inspiration: The LIGHT by Moorescloud
That is, until 2012, when I was suddenly inspired by the "LIGHT by MooresCloud" (originally LightCloud) project on Kickstarter! These guys, headed by the charismatic entrepreneur/maker Mark Pesce, had designs for an intelligent and connected lamp. Beautiful, translucent, with rounded curves and capable of multicoloured light animation, it was something that would have looked right at home in an Apple computer product catalogue. With an open API, I could see myself using one of those as a sunrise clock with some custom programming. I backed the project to get one of those lights, but unfortunately their Kickstarter bid didn't make it! Perhaps the world is not quite ready for a striking, multicoloured lamp with Internet of Things connectivity. Well God Damn It, if they weren't going to make it available to me, I was now determined to build one. The MooresCloud team released all their custom PCB (Printed Circuit Board) designs, which I considered constructing, but I am really not quite up to the point of custom PCB creation in my electronics hobby career! The MooresCloud guys had designed a really nice set of circuit boards that were exactly the right size and shape, and no doubt chosen components for specific power and heat output, and perfectly spaced out the light emitters. Building this would involve either etching your own board and tackling the idea of playing with acid baths, or having a PCB manufacturing service create one from your submitted design. Having gone that far, you would still have to solder about a hundred connections. Not to mention that the design uses surface mount components which are miniscule. I am not quite ready to dive into that pond, of following complex professional schematics created by real hardware engineers. Far from saying "Just Give Me The Schematics, and Stand Aside!" I am more likely to say in a squeaky voice "Can't Really Solder, Send Help!" I also would not have access to the beautiful custom MooresCloud casing design made of gorgeous translucent plastic (designed by the deadset artistes at Tiller Design), and couldn't really imagine a way of doing that economically. This presented quite a challenge in fact. What approach should I take? Glueing layers of perspex together? Casting fibreglass resin? Blowing a custom bubble out of molten glass? I had limited resources (more on this in a moment).

Tutorials and Background Information


Motion-Sensor LED Light with Raspberry Pi

Interior parts in my project
Still, the system design of the MooresCloud got me thinking and I was intrigued to see that it had some components running on Linux and using the Python Programming language. I am pretty handy with Python, and have been schooling myself in Linux-flavoured operating systems and the Raspberry Pi, having bought one recently. I decided to make my own lamp based on the Raspberry Pi, but strike out with my own hardware and software design. I wanted to build it quickly and do a minimum of soldering. To create this project, I once again leaned heavily on the Adafruit tutorials, which rock. Definitely check those out if you are getting into electronics — easily the best tutorial set on the Internet. I identified a digital, addressable, multicoloured LED strip in the Adafruit store, which recently had had some brand-new Python Raspberry Pi drivers created for it by some wags at a hackerspace weekend event. The LED strip took a few days to arrive and then I was set. Taking my Raspberry Pi, I wrapped the LED strip around my transparent Raspberry Pi case, bolstered it with some transparent plastic, and soldered on the four connections (see the tutorial here). Note that this tutorial refers to connecting to an Arduino: to wire up the LED strip to the Raspberry Pi, you connect CLOCK IN (CI) on the strip to to SCLK on the Pi, and DATA IN (DI) on the strip to MOSI on the Pi. Of course you also connect 5V to 5V, and ground to ground. Once that was done, I was ready to rock. Once I had the software worked out it would radiate light in all directions. I was missing the beautiful translucent perspex(?) casing of the MooresCloud prototypes, but I had a plan to get around that later.  

Programming Light


Motion-Sensor LED Light with Raspberry Pi

Mini Wifi Adapter for Raspberry Pi

Along with the drivers for the LED strip, for the operating system on the Raspberry Pi I used the Adafruit Occidentalis Linux distribution, which allows hardware SPI (Serial Peripheral Interface), while the more generic "Raspbian Wheezy" distro does not. With Occidentalis set up, I was all ready to write my code to control the lights. This was a little trickier than anticipated as the drivers didn't really abstract any form of knowledge of the colours it can do such as "red". I had to create my own little library of light values, and I couldn't re-use some other scheme (such as HTML colours) as these strips use an odd RGB system which has 127 values for each colour and doesn't easily map to another system. I was a little bit disappointed that you can't dim the light level or set a brightness on this particular LED strip, each light is either fullbright or off. Still, by starting with one light and gradually switching them all on, this creates a rising scale of brightness in the room. I made the program light up one yellow LED each minute, and once all 30 lights are lit, switch to bright white. I also wrote another script that would fade smoothly between two chosen colours, which has a really hypnotic effect.

 

 

 

Accidental Lockout


That seemed to work great, and I had done all the programming so far on the Raspberry Pi directly. Now, I wanted the program to run on boot, so I edited the Linux operating system's init.d startup list to make the Python program run on startup. This was a bad idea. I somehow misconfigured it so that on boot, that program prevented other things from completing, making logging into the machine impossible. Talk about shooting yourself in the foot! The light worked, but I had seemingly no way of recovering the code I had spend several nights perfecting. Finally, a Linux wizard friend of mine called Hugh was kind enough to do a Linux filesystem recovery for me on his Ubuntu box, digging into the SD card with surgical bash commands. From that point on, I only edited the code in Github and regularly deployed it back to the Pi every time. I wrote a very simple set of bash scripts to do that. A lesson sorely learned! I also found out that you can simply put programs that you want to run on boot into a special directory on the Occidentalis/Raspbian filesystem, the etc/init directory. From there, any executable scripts will be run by the OS, without much risk of bricking the computer.

What's the Time?


With my basic sunrise lamp effect running, it was only a matter of making sure that the Raspberry Pi time was correct when it booted up. This was easier said than done! The Raspberry Pi doesn't have a clock battery on board, so every time you boot it up, the time is at some random value. Still, as the Linux OS on the Pi will seek a clock correction from an Internet time server during the boot process, all I needed to do was to get a tiny WiFi adapter from Adafruit (I got this one, and was really happy with it). That worked a charm, and once I'd set up my access point values in the Occidentalis GUI interface, it was synching up the time perfectly on boot via the Internet. It also made it a lot easier to access the Pi in the project as I could now SSH into it over WiFi without using a cable connection or plugging in Ethernet, which are both annoying, especially once you've built a casing around your Pi and made it quite fiddly to reach those ports.

Got Milk?


LED Light Sunrise Clock with Raspberry Pi

Milk bottle... or light casing?
My clock worked, but the raw LEDs were starkly bright on their own, and it looked pretty ugly just draped around the Pi casing with wires tangled around it everywhere. What I needed was some kind of diffuser casing, along the lines of the Moores Cloud LIGHT casing which resembled a beautiful misty-hued block of ice. My expedient path to a light diffuser casing was to slice open a used two litre milk bottle. Hey, the material is just the right shade of translucent white, easy to cut and fairly robust, for what it is (HDPE plastic). So I marked up the bottle with dotted lines and cut out all my parts with scissors. Where parts needed to be joined, I used transparent tape to hold them together. I made a bit of a flip-top lid, as I knew I would need to get inside to drag out the Pi occasionally to change something or do maintenance.

The MilkLight!
LED Light Sunrise Clock with Raspberry Pi

Placing electronics into the casing.
With my ghetto milk-bottle light diffuser assembled, I cut a port in the side for the USB power cord to feed in, and lowered in the Raspberry Pi with LED strip assemblage. Booya! I was quite happy with how the milk bottle plastic diffused the light, not to mention the (relatively) crazy low cost of the project. The next morning, I was gently awoken by sun-coloured light that gradually ramped up to full brightness at my scheduled wake-up time. It worked a treat! It was kind of good actually, after using it a couple of times, you can gauge how long it is until your wake-up time by the amount of lights that are illuminated at the moment (if you wake up early). And if you're really knocked out, it's less of a jarring shock to be yanked out of a sleeping state when the light in the room has been warmed up gradually. It really does seem to prepare your mind to transition to a wakeful state.

 

 

 

Web What?


LED Light Sunrise Clock with Raspberry Pi

Fully assembled.
I thought about setting up a web server to allow the lights to be controlled by responsive things, such as a build server's status, website uptime (see my example code for this) or indicating when you have new email or social media responses. The MooresCloud LIGHT prototype (and their successful follow-up project, Holiday, which you can actually get) has this kind of functionality, (a LAMP stack, even) along with a really nice front-end range of mobile device apps which let you easily plug and play effects and visualisations. I haven't got to the point of setting up a web server yet, but there is no shortage of Python friendly web servers that can do this on the Pi. I may get to that one day. "It is a simple matter of programming!" as my laconic ex-colleague Oysta would have proclaimed. Still, I don't really need that and have pretty much achieved everything I wanted out of this project. The Sunrise Clock function works a treat, and that is what I was gunning for in the first place.

Conclusion


LED Light Sunrise Clock with Raspberry Pi

Turned out great.
If you'd like to build this project, I estimate the assembly and configuration of all these parts will take around four days, but you will learn something about setting up Raspberry Pi operating systems and installing Python libraries. On the positive side, this really was the most amazing journey of discovery for me and I learned a lot of new skills that have been immediately helpful for me at work. If you would like to build something like this for your own reasons (and you have a pretty strong motivation), go for it. You can grab my source code for the Sunrise Clock and colour morpher from Github.

 

 

 

For this project, here's the bill of materials:

Total: ~$130 You will need a few other things like hookup wire, serial cable, and soldering iron. And then you can begin assembly! If you don't want to build it yourself, an alternative path, that will have you creatively coding on your light-based ideas earlier, is to get one of the Holiday lights by MooresCloud. With that, you'll also be instantly set up and ready to go if you wanted to get into some light-centric programming. For the cost of that, you'll easily be well ahead of what this project cost me after buying all of the bits and pieces required, burning my fingertips soldering tiny LED strip connections, and inhaling vapourised lead! ;-) Another track to take is to get one of the new generation Sunrise Clocks or "Dawn Simulators" (such as this one by Phillips, or see a good discussion of other models here), if the Sunrise Clock is all that you really wanted. Those generally cost less than this project, at the time of writing (December 2013).

Thanks for reading! If you'd like to know more about anything I've mentioned here, grab me on Twitter.

LED Light Sunrise Clock with Raspberry Pi LED Light Sunrise Clock with Raspberry Pi LED Light Sunrise Clock with Raspberry Pi LED Light Sunrise Clock with Raspberry Pi LED Light Sunrise Clock with Raspberry Pi