Spark: Ambient Lighting System

Published on November 10, 2016 under Projects

I have recently put together a new rig, and it just so happened I had several LED strips leftover from one of my previous projects. Sadly, I couldn't get my hands on a monitor with built-in ambient lighting so I decided to build my own solution. This was the core idea for Spark, an ambient lighting system built using an Arduino, Java and some LED strips.


Initially I was going to use C++ or C# with Visual Studio to make a Windows application, but then decided to stick with Java as a way quicker and simpler solution for this particular problem, especially considering the limited amount of time I could invest into this project. Another unfortunate outcome of this was that I did not have the time to bring both hardware and software for this project to a high enough level of quality, so I would not recommend reusing the source code for this project anywhere else. Instead, consider it to be something like a proof of concept and maybe an inspiration for similar ideas.

The whole setup essentially consists of 2 major parts: The host machine, which extracts the "average" colour from the current image on the screen, serialises it and sends it to Arduino over USB serial, and Arduino itself which deserialises the data and adjusts the voltages on the LED strip to change the colour and brightness of LEDs. You can see a picture of the Arduino with a bread board and some MOSFETs, a 12v battery and an LED strip below.

Arduino with a bread board, some MOSFETs, 12v battery and an LED strip.

The Java source code is pretty self explanatory. The code takes a screenshot of the screen every set interval of time using an AWT Robot and extracts the "average" colour from screenshot by averaging red, green and blue channels for every 5th or so pixel. Then, it converts the intensity of each RGB channel from 0-255 to 0-36 scale and produces a string of length 3 and format RGB, where R, G and B are intensities in base 36 (more about it below). Once the string is ready, it is sent to the Arduino over serial.

To send less characters over serial I decided to use base 36 numbers, which basically utilises all 10 digits from 0 to 9 and all lowercase letters in the English alphabet. When Arduino receives the RGB string, it converts it back to base 10 and to 0-255 scale. Once this is done, it changes the voltages on the pins corresponding to each colour to match the intensity extracted from the string. Then, using some MOSFET magic on a bread board, 12v battery powers the LED strip which lits up in our desired colour.

I am aware that everything described above is far from perfect, but sadly at the time I didn't have the chance to improve anything. I will definitely be revisiting this idea in the future to come up with a better solution.

Demo and source code

All of the source code can be found in Spark's GitHub repo. Below is a short demonstration of the system in action. Keep in mind the Ambient lighting system is only controlling the LEDs behind the monitor, everything else is controlled by other 3rd party software.

End of Article

Timur Kuzhagaliyev Author

I'm a computer science graduate from UCL & Caltech, working as a systems engineer at Jump Trading. Before Jump, I was doing computer vision for Video Quality Analysis team at Amazon.