If you watch a lot of movies on your PC or media center, I’m sure you’ve run into a lighting dilemma; Do you turn off all lights completely? Are you running them at full capacity? Or are you using a dimmer to keep a dull yellow glow somewhere? Well, don’t worry anymore.

For less than $100, you can install an amazing lighting system that reflects what’s on the screen; if the video is a blue night scene, the light will be blue; when the flame of orange fire flares up, so will your fires. Welcome to the world of RGB lighting.


  • The RGB light bar is a 5m strip of RGB LEDs that can be bought on eBay and shipped from Hong Kong for less than £20 each. If you buy from electronics stores, you will be charged by the meter and the cost of a 5m coil will be three to four times more, so buy online. These types of LED strips can be changed to any color, but only all at once — they cannot be customized individually.
  • 12V power supply — the required power (amps) depends on how many LED strips you will connect. Each meter draws approximately 0.6A, but this depends on the density of your LEDs, so be sure to check your specific LED strip. 3A will be enough for the 5m strip I connected above and separate power supplies can be bought for around £10 if you can’t find them elsewhere.
  • 3 x MOSFETs N transistors — you can probably find cheaper, but I bought a pack of 6 (type STP16NF06FP) for about £10. They are used to isolate current from the Arduino — connecting the strips directly to the Arduino will fry it with the amount of current they draw. You need 1 MOSFET for each color LED channel, for red, green and blue.
  • Arduino — I have not included the cost of this item as it is assumed you already have it and there are plenty of clones you can buy if you can’t afford the official one.

The total cost was about £40, not including Arduino.


The project consists of two parts. First, we will create a basic Arduino circuit that listens for commands from the computer and sets the RGB LEDs to the appropriate color. The second involves using a new application called Processing and Java on the computer side to find out what colors are currently displayed on the screen, average them and output to the serial communication port so that the Arduino reacts to them.

Part 1: Schematic and Arduino

The circuit we are using is very simple as you can see in the diagram below. The LED strip should come with a plug on one end that you can place directly into the breadboard.

media center

Your LED strip may be different, but if you look closely, you will see somewhere 12v, R, G, B on rails. These strips can be cut into these copper points (every 3 LEDs on the ones I have) so if you want to cut the strips at the corners of the TV you can do it safely — you don’t have to use the whole 5 meters either so u you may have something left for a future project. Connect the positive 12V directly to an external power supply.

dynamic ambient lighting

MOSFETs have three pins; gates , stock and source . The gate is like an electronic switch that the Arduino will control. It then determines the current flowing between source and drain. The drain of each MOSFET must be connected to Arduino ground and power supply ground while the source is connected to the LED strip channels.

dynamic ambient lighting

When you’re done with the circuit, download and run this test code (originally by LadyAda, modified contacts). You should see swirling LED strips in different colors.

dynamic ambient lighting

Part 2: Handling

Download Processing and launch. You may be surprised to find what it looks like almost the same, as an Arduino development environment; this is because the Arduino environment was based on it even though they both perform different functions. Take this code — originally from Silicon Republic, but it has been heavily modified by me to make the screen size settings automatically and with better color display — and take the time to review it. Basically it uses a Java class called Robot for creating snapshot screen every 10 ms ; it then selects every odd pixel and averages the overall color. If for you important performance, increase variable skipValue up to 3 or 4 to skip more pixels — the overall effect should be the same, but it will run faster as it explores fewer pixels. Finally, I added a filter that helps to saturate the color by increasing the maximum and decreasing the found minimum RGB values. (without this, I found the colors to be too white).

Launch the application; the first time you will probably get an error when you try to access the wrong serial port.

dynamic ambient lighting

Check the debug window for a list of current serial ports and note the number next to the one your Arduino is connected to. In my case on a Mac, the USB connection is port 4. Change the number on this line to the correct port:

  port = new Serial (this, Serial.list () [4], 9600);  // установить скорость передачи 

Save and restart; You should see a small popup — it represents the average color of everything on the screen. Fire up a drawing app or something with bright colors to test it out, otherwise it will probably just show a muddy grayscale. Stop the application when you’re done testing as we need serial port access to program the Arduino.

media center

Finally, upload this code to your Arduino. Instead of sending random colors to the LED strip, this code reads the values ​​from the serial port (which outputs the processing). It’s pretty easy to understand, the only hard part might be using the marker on the serial data:

if (Serial.available()>=4) { if(Serial.read() == 0xff){ red = Serial.read(); green= Serial.read(); blue = Serial.read(); } } 

This ensures we’re reading the correct byte values ​​- the processing application outputs a marker as a «breakpoint» between each set of values ​​so the Arduino doesn’t get out of sync and think green is for blue, etc.

After uploading the Arduino code (initially there should be no output on the LED strip), you can download and run the Processing app; immediately you should see the ambient light work.

Here’s a video demo of how I did it with some random trippy music video.

What do you think?! While not as impressive as one that analyzes every part of the screen and uses individual LED pixels, it is much cheaper and brighter. The only downside to this is that everything has to be done on your media center computer — it won’t work with regular TV broadcasts or your Xbox 360, for example. If you have any problems, questions or suggestions, please feel free to ask; or perhaps a link to a video of your completed setup.

Похожие записи