Spark: Ambient Lighting System

Published on November 10, 2016 under Projects

Abstract

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.

Development

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.

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
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.20202688872814178, "perplexity": 761.7840248193875}, "config": {"markdown_headings": false, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2018-43/segments/1539583517495.99/warc/CC-MAIN-20181023220444-20181024001944-00299.warc.gz"}