Build Your Own Dynamic Ambient Lighting For A Media Center

James Bruce 14-12-2012

media center lightIf you watch a lot of movies on your PC or media center, I’m sure you’ve faced the lighting dilemma; do you completely turn off all lights? Do you keep them on full blast? Or do you use a dimmer switch to keep a dull yellow glow somewhere? Well, suffer no more.


For less than $100, you can set up an amazing lighting system that’s going to reflect what’s on-screen; if the video is a blue night scene, the lights will be blue; when a blaze of orange fire flashes on, so will your lights. Welcome to world of ambient RGB lighting.


  • RGB light strip – this is a 5 metre strip of RGB LEDs which can be bought on eBay and shipped from Hong Kong for less than £20 each. If you purchase in electronics shops you’ll be paying by the metre and a reel of 5m will cost three or four times that, so buy online. These type of LED strips can be changed to any colour, but only all at once – they cannot be individually adjusted.
  • 12v power supply – the power (ampage) required depends on upon how many strips of LEDs you’ll be connecting. Each metre draws approximately 0.6 amps, but this depends on the density of your LEDs so be sure to check your particular LED strip. 3A would be sufficient for the 5m strip I linked above, and separate power supplies can be bought for around £10 if you can’t source one elsewhere.
  • 3 x MOSFET N transistors – you can probaby find cheaper, but I bought a pack of 6 (type STP16NF06FP) for around £10. These are used to isolate the current from the Arduino – connecting the strips directly to the Arduino would fry it with the amount of current they draw. You need 1 MOSFET transistor per LED color channel, for Red,Green, and Blue.
  • Arduino What Is Arduino & What Can You Do With It? The Arduino is a remarkable little electronics device, but if you've never used one before, just what exactly are they, and what can you do with one? Read More – I haven’t included the cost of this item as it’s assumed you’ll already have one, and there are a variety of clones you can buy if you can’t afford an official one.

The total cost was therefore around £40 not including the Arduino.


The project consists of two parts. First we’ll be creating a basic Arduino circuit that listens to commands from the computer, and sets the RGB LEDs to an appropriate colour. The second involves using a new application called Processing and Java on the computer side – to work out what colours are currently on screen, average them, and output that to the serial communications port for the Arduino to react to.

Part 1: Circuit and Arduino

The circuit we’re using is very simple as you can see from the diagram below. The LED strip should be supplied with a male plug on one end that you can place directly into the breadboard.

media center light



Your LED strip may vary, but if you look closely you’ll see 12v, R, G, B written on the rails somewhere. These strips can actually be cut at these copper points (every 3 LEDs on the ones I have), so if you want to cut the strips at the corners of your TV you can safely do that – you needn’t use the whole 5m either, so you may have some left for a future project. Connect the positive 12v directly to the external power supply.

dynamic ambient lighting

The MOSFETs have three pins; gate, drain, and source. The gate is like the electronic switch which the Arduino will control. This then determines the current flowing between the source and drain. The drain of each MOSFET should be connected the ground of the Arduino, and the ground of the power supply, while the source connects to the LED strip channels.


dynamic ambient lighting

When you’ve completed the circuit, download and run this test code (originally from LadyAda, pins modified). You should see your LED strip swirl through a variety of colours.

dynamic ambient lighting

Part 2: Processing

Download Processing and run. You may be surprised to find it looks almost exactly like the Arduino development environment; that’s because the Arduino environment was based on it, though they both perform different functions. Grab this codeoriginally by Silicon Republic but heavily modified by me to make the screen size settings automatic and with better color representation –  and take a moment to look over it. Basically it uses a Java class called Robot to do a screen capture every 10ms; it then picks out every odd pixel and averages the total color. If performance is an issue for you, increase the skipValue variable to 3 or 4 to skip more pixels – the overall effect should be the same but it’ll run faster as it examines less pixels. Finally, I added a filter which helps to saturate the color by increasing the maximum and decreasing the minimum RGB values found (without this, I found the colors to be too white). 


Run the app; the first time, you will probably get an error as it tries 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 what your Arduino is plugged into. In my case on a Mac, the USB connection is port 4. Change the number in this line to the correct port:

port = new Serial(this, Serial.list()[4],9600); //set baud rate

Save and re-run; you should see a small window pop up – this represents the average color of everything on-screen. Launch a painting app or something with strong colors to test it, otherwise it’ll probably just display a murky shade of grey. Stop the application when you’re done testing as we need the serial port access to program the Arduino.


media center light

Lastly, load this code on to your Arduino. Instead of sending random colors to the LED strip, this code reads the values from the serial port (which Processing is outputting to). It’s fairly easy to understand, the only difficult part may be the use of a marker in the serial data:

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

This ensures we read the correct byte values – the Processing app outputs a marker as a “breakpoint” between each set of values so that the Arduino won’t get out of sync and think that the green value is for blue etc.

Once the Arduino code is uploaded (there should be no output on the LED strip initially), then you can load and run the Processing app; immediately you should see your ambient light working.

Here’s a video demo of how it worked out for me with some random trippy music video.

What do you think?! While it isn’t quite as impressive as something that analyses each part of the screen and uses individual LED pixels, it is a lot cheaper and a lot brighter. The only downside to this is that everything must be run on your media center computer – it won’t work with regular TV broadcasting or your Xbox 360, for example. If you have any problems, questions, or suggestions then please ask away; or perhaps link to a video of your completed setup.

Related topics: Arduino, Media Player.

Affiliate Disclosure: By buying the products we recommend, you help keep the site alive. Read more.

Whatsapp Pinterest

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. Aydin Sever
    November 29, 2019 at 10:27 pm

    The LEDs are just flashing random colors. It will sometimes get close to the color displayed, but it will constantly be flashing and varying in color slightly. Most of the time, however, it just flashes random colors. I don't know what I managed to mess up, but I would appreciate if you could at least try to help.

    • Aydin Sever
      November 29, 2019 at 10:50 pm

      I just found out that I may be the biggest idiot on the internet.
      You know that part in the Arduino that says "if (Serial.available()>=4) {
      if( == 0xff){
      red =;
      blue =;
      Yeah, well I switched that 4 to 1 cause I thought it was asking for the Serial Port number..... I really.... Like... How? How did I mess that up?

  2. Jonathan Whitefield
    January 29, 2018 at 6:20 pm

    I know that this is basically superseded by the NeoPixel version, but I went ahead and made this to run as an ambient light strip for my desk edge (rather than around my monitor). So far it seems to work great, but with a couple of "interesting" quirks. First of all, it tends to be WAY over on the blues. For example, while playing AC Origins, and running around the red, sandy desert, the strip is showing almost a white/blue. Also, it's a little annoying that when I turn the computer off, the lights remain on in the last colour they had (usually a white/blue, based on the last point). Is there any way to script something that says "if no signal is sent to the Arduino, turn off the LEDs" or to add in an "off" button that would have an over-ride to the signals sent to the PWM pins?

    • James Bruce
      January 30, 2018 at 10:51 am

      You definitely have the red and blue pins correct? That does odd.

      Try adding an "else if" after first reading the serial signal:

      else if (Serial.available() == -1) {
      analogWrite (RedPin, 0);
      analogWrite (GreenPin, 0);
      analogWrite (BluePin, 0);
      delay(10); //just to be safe

      Serial.available should be -1 if there's no data incoming, and the 0 would turn them all off. You might even get away with just an "else" statement, rather than explicitly checking for -1 on serial, but I've not tested either.

      • Jonathan Whitefield
        January 30, 2018 at 5:03 pm

        Thanks. I'll try the "off switch" today. As for the lights, yes, pin outs are correct. Yellow on screen in full screen paint is yellow lights (no blue on), etc. It's the mixed colours that seems to be too blue. I've dialed back the range on that channel, and that's seemed to work. It may just be the strip that I bought has a too strong blue LED.

  3. Brandon
    February 10, 2017 at 3:38 am

    Will this work on raspberry pi also

  4. Jonathan
    January 17, 2017 at 5:32 pm

    Hi there

    I hope you don't mind me asking but can't seem to find an answer on the tutorials etc.

    Processing halts on "int x = screen.width; //possibly displayWidth" I've tried changing the variable to displayWith with no luck, is there a different command I should be using, I'm on a Win10 machine.



    • Justin
      December 31, 2017 at 11:39 pm

      To fix that problem replace "screen.width" and "screen.hheight" with the actual resolution of your monitor. That fixed it for me, but another problem popped up. I am getting an ArrayIndexOutOfBoundsException: 7 with the line "port = new Serial(this, Serial.list()[7],9600); //set baud rate" highlighted. Haven't figured that one out yet.

    • Justin
      December 31, 2017 at 11:43 pm

      Replace "screen.width" and "screen.height" with your actual resolution.

      I got that to work but now get an "ArrayIndexOutOfBoundsException: 7" realted to this line "port = new Serial(this, Serial.list()[7],9600); //set baud rate" and I have ni idea how to fix it.

      • James Bruce
        January 2, 2018 at 9:38 am

        Serial.list()[7] means grab a list of serial ports and connect to the 7th one (well, 8th, it's zero based index). Out of bounds means you don't have one at index 7. Instead, try listing the serial ports first and then code in the correct one. Heres the relevant bit of text from the article:

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

        port = new Serial(this, Serial.list()[4],9600); //set baud rate

  5. paul
    March 22, 2016 at 7:48 am

    hello. do i need to chgange the battery if i cut the strip led?thank you.

    • James Bruce
      March 22, 2016 at 8:00 am

      There's no battery in this project....

  6. Anonymous
    February 7, 2016 at 11:57 am

    Hello i have already built an ambilight with ws2801 pixels (100 of them) but i like to have some other lighting in my room act also on what is on the screen.

    I used processing 2.1 and i get an error window.height is no longer used or somthing like that (on my test machine i have 3 monitors)

    Now i use processing 3.0 and the result is the same.

    How can i change the processing scheme to use newer processing ide ?

    I use on my tv setup a arduino uno with 2 strands of 50 led pixels (from
    in combination with and boblightd

  7. John
    February 5, 2016 at 5:35 pm

    Hi again, would it be possible if you could upload the wiring scheme including the sensor and buzzer.I'm afraid to do it because I don't have much experienced with electronics.

  8. Anonymous
    October 29, 2015 at 4:02 pm


    I've been trying to start this project except I feel like I'm missing some material for it. The diagram shows some sort of external energy source that I am not aware of. What is this component called and where can I get it?

    Thank you

    • James Bruce
      October 29, 2015 at 5:14 pm

      12v power supply, in the equipment list. However, this guide is quite old. Since then Neopixels have become significantly cheaper, which gives you individual control of each LED rather than just a solid block of color. Check out my newer guide on making DIY ambilight, same principle, but far better end product: //

  9. giorgos
    May 5, 2015 at 7:39 pm

    hello i try to do it with transistor and the color change but not soo much and not the right color of the screen the test code worked well!!

  10. subho
    April 26, 2015 at 4:50 pm

    hiiee everyone. I have a question does this light system work when we play mp3 files?

    • James Bruce
      April 27, 2015 at 7:37 pm

      No. The light reads on-screen color values. Unless your music has a video, it wont react to music.

  11. Alain
    April 14, 2013 at 1:37 pm

    great mod, not as white anymore because of your filter but now black screen shows red color on the strip. With the original it was just no light.

    • MakeUseOf TechGuy
      April 15, 2013 at 7:47 am

      Hmm, curious. I wonder if it's 100% black or there's a tiny bit of red remaining somewhere? The filter basically just amplifies the hue by raising whatever RGB colour is strongest and lowering the weakest - so any tiny amount of red if present would be dominant. It could certainly be improved, I jsut tend to prefer stronger colors. Perhaps an additional filter that ignores everything if the values are less than 55 or something...

      • Alain
        April 17, 2013 at 12:45 am

        Thanks I finally understood how your filter was working (I'm not a programmer) because of that sentence:"The filter basically just amplifies the hue by raising whatever RGB colour is strongest and lowering the weakest".
        I added this after your filter and it fix my problem, thanks
        if(r <= 50){

        • Alain
          April 17, 2013 at 2:19 am

          no it doesn't work. ok it works when it's black completely but when it's totally dark sometimes it's blue or green. It's really annoying, I took of the =0 filter.

  12. Michael
    January 6, 2013 at 4:04 am

    Hello all,

    I built a small java app to control arduino based lighting system. At the moment it has three modes. Ambient lighting, Preset sequences (in which you can modify fade setting, interval for color change. more color sequences can be hard coded at the moment) and manual color selection. It minimizes to the system tray and there is a function to turn the lights on and off.

    I would also like to make a setting for how it scans the screenshots in ambience mode, i found some code that just scans the edge of the screen and i reckon it would be a good setting + minimize cpu usage.

    The code is open source and is available on Github here: and a built jar with library dependencies is in the store folder.

    Feel free to use it in the tutorial and contribute to the project if you a java wizard.

    Also if anybody know how to do this image procesing on the gpu with c++ (if it is even plausible) please get in contact with me.


    • James Bruce
      January 7, 2013 at 10:04 am

      That's fantastic, thanks Michael. I'll see if I have time to write about it again some time.

  13. druv vb
    December 21, 2012 at 4:12 pm

    Thats an interesting light work. But yours seems more like party lighst. I have done almost the same, using only a 12v power source and light strips. I've a green one just below the surface of my table for illuminating the keyboard, mouse and anything below the table. A blue one at the back of the table, allmost like a backlight for the screen.
    And will be doing the same with my tv set in the living room. And all of them are running at only 6v, for a more dimmer and cooling light expereince. Full 12v power is too bright.

  14. Griffin
    December 17, 2012 at 3:34 pm

    What about fiber optic? That stuff looks awesome.

    • Muo TechGuy
      December 17, 2012 at 3:42 pm

      Hmm. The problem with fibre optic is that it only has a concentrated beam of light at once end. It couldn't really be used as a light source to project light around the room. Perhaps you mean electroluminescence (EL) wire?

  15. Junil Maharjan
    December 16, 2012 at 5:14 am

    Arduino seems to be getting much coverage nowadays. It is so useful. Can't wait to get my hands on one of these.

  16. Ron Lister
    December 16, 2012 at 3:08 am

    Looks like a fun and fairly straight forward fun project, James. Thanks.

  17. James Maciel
    December 15, 2012 at 12:10 am

    that looks really cool, nice job

  18. Arben Myrtaj
    December 14, 2012 at 7:49 pm

    Holy sh*t, that's awesome.

  19. Scutterman
    December 14, 2012 at 6:54 pm

    This looks awesome. I may look into building this when I have some spare cash

  20. Arxadius Stark
    December 14, 2012 at 6:18 pm

    Interesting read. Might give it a try when I get some time on my hands. c: