Pages

Tuesday, February 8, 2011

Arduino Based PC Ambient Lighting

354 comments:

  1. Looks awesome!

    Did you forget to post the code cause I can't find it?!

    ReplyDelete
  2. I am commenting the code properly and uploading it asap! sorry!

    ReplyDelete
  3. Thanks!

    I added some screen-management in the setup to be able to use a second monitor to get the pixel average from. Might be useful if you're like me and connect a TV to the computer and the TV has a light strip behind it.

    How much does it affect the responsiveness if you increase the delay to let say 100 instead of 10? It uses a lot less CPU then, but I can't test it on my LED strip I'm still waiting for a usb cable for my arduino.

    void setup() {
    // Set baud rate
    port = new Serial(this, Serial.list()[0], 9600);

    // Window size (doesn't matter)
    size(100, 100);

    // Objects to handle the current screen
    GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] screenDevices = graphicsEnvironment.getScreenDevices();
    GraphicsConfiguration[] graphicsConfig = screenDevices[screenID].getConfigurations();

    // Set the screen size to capture
    screenWidth = graphicsConfig[0].getBounds().width;
    screenHeight = graphicsConfig[0].getBounds().height;

    // Set the screenID
    if (screenDevices.length == 1) screenID = 0;
    else screenID = 1;

    // Standard Robot class error check
    try {
    robby = new Robot(screenDevices[screenID]);
    }
    catch (AWTException e) {
    println("Robot class not supported by your system!");
    exit();
    }
    }

    ReplyDelete
  4. Wow! Thanks!! Exactly something I thought of doing since I had an external monitor! I am a C person so I didn't know the library to screen manage since processing is in Java. Yeah you can try to change the delay to 100. If the responsiveness is affected, just "cheat" and add a bit of smoothing using a moving average on the Arduino's side:p Thanks again!

    ReplyDelete
  5. Great!

    Perhaps it would be better to ignore the very center of the image, and only take the pixels towards the border of the screen?

    Not to mention independent strips for each border (specially cool if you have a 42" screen)

    ReplyDelete
  6. What about using softpwm library (available on playground) and 3 or 4 RGB LED segments (top, (bottom), left, right)

    ReplyDelete
  7. home made philips ambilight.. very cool.. could you also average out portions of the screen?

    ReplyDelete
  8. Could use some fading to the new value.

    ReplyDelete
  9. you're on Hack A Day!

    ReplyDelete
  10. Congrats on the Hack A day mention. And nice project!

    BTW I think I sort of recognize that circuit layout picture ;)
    http://genericnerd.blogspot.com/2009/05/arduino-mood-light-controller.html

    ReplyDelete
  11. Thanks everyone! Yeah I didn't know I was featured until I saw the comment :D Thanks for tipping hack-a-day about this! Yep the circuit layout is the same since it is the same circuit! Can't get any simpler than that :p Thanks for posting the link to that circuit. I feel bad not to cite it. And thanks everyone for the feedback. The main improvement ideas from everyone are:
    -smoothing using a moving average
    -handling dual monitors
    -using four strips for each average of the screen borders

    ReplyDelete
  12. This just made my day :D Seriously :) nice hack !:D

    ReplyDelete
  13. Hi this is damn good . Was wondering wher i can buy the arduino chipset from .

    ReplyDelete
  14. Thanks František :)
    The arduino chipset can be brought from alot of places. I usually buy it from Sparkfun.com: http://www.sparkfun.com/products/10356

    ReplyDelete
  15. This is awesome! Only problem is, I'm not tech savvy enough to do this. Contact me through my email and lets see if I can work something out to pay you and you put it together and ship it to me. Email me at howdythereneighbors@yahoo.com

    This looks awesome! And as a gamer, this would only enhance my experience! Must have!!!

    ReplyDelete
  16. Nice project, i guess you could get better performance if you make direct access to video memory, you could find many information about it on game developing web pages.

    Instead of treat screenshot as a matrix you could linearize it to improve even more. Just my two cents.

    ReplyDelete
  17. My name is Paul and I am the admin of a site called HackHut. You obviously have a lot of skill, and I just wanted to let you know about HackHut because it seems like a perfect fit for you. We are a hosting service somewhat like wordpress, blogspot, or Instructables accept run by and geared toward the hacker/DIYer. We offer or are working on features that people like you want and can use. I hope you check us out and feel free to contact me there if you have any requests for features or questions about the site.

    ReplyDelete
  18. This is pretty awesome. I can't wait to order a couple of those strips and try it out. I run an XBMC PC in my living-room and I think this would be perfect for it. I agree with many of the people here in that having the borders be different however I have a suggestion. If you do plan on making borders available have a couple Boolean variables at the beginning of the code to enable/disable individual borders. I.E If i wanted to say have the top and bottom only, or if I wanted to have the sides only all I would need to do was set a few true false values. I look forward to the next release!

    ReplyDelete
  19. Good luck! At this point I think everyone has their own specific processor requirements, parts and monitor configs that a next release trying to accommodate all of those would make the code so long that those who want to quickly learn and modify it would find it tiresome. I think the simple platform has been established and its time for everyone to learn and have fun!

    ReplyDelete
  20. Well very nice project but i wondered if it is possible to have transitions between the fadings...
    and could you tell me what the delay is therefore ?

    greets from germany :D

    ReplyDelete
  21. Hey Rajarshi... My name is Tabish Chasmawala. I am also a high school student and wanted to know if we could keep in touch maybe to develop other projects together. My blog is here: http://practical-embedded-hacks.blogspot.com/

    Cool projects by the way. The ambient light project is amazing and easy at the same time!

    ReplyDelete
  22. Oh and also my email is tabchas@yahoo.com...

    ReplyDelete
  23. @Dominic. Greeting! If you mean a smooth transition between two screen capture values the arduino shows, you have to add a code for smoothing on the Arduino's code. Then display the moving average value on the RGB LEDs. Just in case if you don't know what I am talking about, see this: http://www.arduino.cc/en/Tutorial/Smoothing.
    The delay is there so that the Arduino has some time to digest the Serial data before the next set comes in. I am just being extra cautious. You can remove it and it might work :)

    ReplyDelete
  24. Great project!!!!

    I attempted to duplicate you however I'm not able to get any data sent to the arduino uno. I belive it may have something to do with the processing code as I do not have any data scrolling down at the very bottom of the processing screen. The color box changes perfectly

    ReplyDelete
  25. Got it!! had to change the desitnation serial port since mine was on COM6. Works like a champ.

    ReplyDelete
  26. awesome! thanks for telling me! I was figuring out what could have gone wrong in the process!

    ReplyDelete
  27. Hey, thanks a lot for your inspiration.

    http://www.instructables.com/id/Java-Microcontroller-LED-TV-Ambient-Light/

    ReplyDelete
  28. thank Simon! I just checked out your instructable! very cool! amazed at your hard-work! You basically built the uln2003 chip by yourself :D

    ReplyDelete
  29. @ Brian
    How did you change the output port. I think I may have the same problem. When I run the code in the lights blink quickly three times or so and then they stay off.

    ReplyDelete
  30. @Andy

    Hey Andy! I think the problem can be found in this line:

    port = new Serial(this, Serial.list()[0],9600);

    I guess you have more than one serial port (like I have, too). You better show all of your serial ports and then select the right one.

    Try to read out your serial ports by using:

    for(int i=0; i<Serial.list.length; i++)
    {
    System.out.println("portnumber=" +i +", name=" + Serial.list[i].getName());
    }

    I wrote this code just now and do not know if it actually works, but you get an idea. You can find some source code concerning the ports in my enhancement of this project. Just click my name and you'll find it.

    ReplyDelete
  31. Hi,

    great project.
    made myself a slightly different version, with .net C# code for screen analysis instead of processing.
    check it out here : http://www.youtube.com/watch?v=tqnloviYA98
    next step 2 led strips channels , for right and left side of the screen ;)

    thanks for the inspiration

    ReplyDelete
  32. I noticed that you do not use all six pwm in your application.
    I also noticed that only one Arduino, as well as the only
    Serial.read for your application.
    So I made some amendments to them so the seven commands you can connect
    Arduino several series and each has two channels RGB.
    The code for the Arduino is
    http://rapidshare.com/files/452744618/Ambient_Lightingtoy_pde.zip

    ReplyDelete
  33. In continuation of previous ...
    I found some implementations just had a lot
    Arduino Board => Many usb => Prohibition approach!
    The design I made seriaki provides for the exit
    Arduino to the first serial input goes to the second, second to the third ...
    Commands for the Arduino have the form
    1) ID Arduino (If not the right to proceed to the next)
    2) Red1 on pin3
    3) Green1 on pin5
    4) Blue1 on pin6
    5) Red2 on pin9
    6) Green2 on pin10
    7) Blue1 on pin11
    Believe that three is enough, because six channels are many.
    I found your idea by accident and found it very good.
    I would like to give me permission to translate into Greek your application.
    I could do it without your permission, but made so hard, it is wrong not to have your permission.

    George Konstantinidis
    Mechanical Engineer

    ReplyDelete
  34. i make one mistake ...
    In the end, joining the pins must be made
    inside the if (a1 == 1).
    Not as it is the file that I put on rapidshare

    ReplyDelete
  35. like this ...

    if (a1==1) //
    {
    red1 = a2;
    green1= a3;
    blue1 = a4;
    red2 = a5;
    green2= a6;
    blue2 = a7;
    analogWrite (RedPin1, red1);
    analogWrite (GreenPin1, green1);
    analogWrite (BluePin1, blue1);
    analogWrite (RedPin2, red2);
    analogWrite (GreenPin2, green2);
    analogWrite (BluePin2, blue2);

    }

    ReplyDelete
  36. @gewkwn Hey no problem! You have my permission! The whole purpose of this project was to create a simple base platform which people can modify and build upon:) Thanks for sharing your updates!

    ReplyDelete
  37. Hey,
    i`m currently using 1x ULN2003A for driving the stripes...
    but for about 14meters of stripe i would connect 2 power supplies is this possible ?
    would use 2x ULN2003A :S
    need help please ;)

    greets from germany

    ReplyDelete
  38. This comment has been removed by the author.

    ReplyDelete
  39. For ULN2003A from the datasheet I see that can handle current up to 500mA for each channel. I do not know if it can be connected in parallel, but would I suggest buying a Darlington transistor FORCE depending on the current wants each channel so as not to worry, the voltage difference between the output voltage of the Arduino (5V) and stripe (12V )

    ReplyDelete
  40. As regards the power supply would you propose to buy
    a power supply for personal computer that gives a lot
    A at 12 volts. The conversion will have to do is very
    simple
    1) mounted a resistance 5om / 5W between red cable
    and black wires (which is not to burn the power supply, artificial consumption)
    2) Put in operation the power supply by connecting the green wire to black wire.
    3) The 12 volt takes it from the yellow wire and the grounding of the black.

    ReplyDelete
  41. I was wondering if i could do this with 2 strips...

    would 12v 600 ma be enough? 150X2 LED's?

    Or what would be the setup for 2 strips running off 1 supply (how many amps?)... or 2(how the hell do you ground it)?

    Thanks.

    http://www.dealextreme.com/p/rgb-150x5050-smd-led-multicolored-light-strip-5-meter-dc-12v-41523

    ReplyDelete
  42. @ILandscape.info: Yeah its possible to do this for two strips with the one chip, one arduino and one power supply. The additions to the current circuit youll need to make are: 1) Connect Arduino pins 3,5,6 to ULN2003 pins 4,5,6. 2) Connect ULN2003 pins 13,12,11 to 2nd LED strip R,G,B pins. 3) Connect the power pin of the 2nd RGB LED strip to the power pin of the 1st RGB led strip or +12V of supply. Now your code can use Arduino PWM pins 3,5,6 to control the second LED strip.

    There is no need to ground the LED strip because the ULN2003 chip does that. Either the chip leaves an open circuit (LEDs off) or grounds the color channel (LEDs glow since current flow from the +12V through that color channel to ground).

    ReplyDelete
  43. hi,
    i tried to build a project according to the explanation, the only difference is that i used
    ULN 2803 instead of the ULN 2003.
    nothing works... the led strip doesn't glow...
    any idea ?

    ReplyDelete
  44. @ohad: I looked up ULN2803. There really shouldn't be any difference at all.. All the specs are identical! Only the Pin numbering of the Ground in 2803 is 9 whereas that in 2003 is 8. And the LED output pins in 2803 are 18,17,16 whereas that in 2003 are 16,15,14 assuming the control inputs are to pins 1,2,3 to either chip.

    ReplyDelete
  45. Did you do any updates to this project? Im getting into an Arduino lighting project like this one, and i wanted to know if you were able to tweak the code for separete strips(different parts of the screen) Thank you very much!

    ReplyDelete
  46. I moved on to other stuff but someone else continued on with multiple LED strips: http://hackaday.com/2011/03/03/arduino-based-ambient-lighting-improvements/

    ReplyDelete
  47. Hi roy..
    I'm wondering if i could use 4 RGB strips with only 1 arduino and 1 power supply? How many uln2003 chips i need? how do i wire those RGB strips into the chip? Sorry if i ask too many questions, its because i have zero background about electricity and engineering..
    Cheers, kevin..

    ReplyDelete
  48. Hi Kevin,
    Don't worry about asking questions. Knowledge is free :) Well if you look at the circuit, you will see that each strips needs four inputs: 12V, R, G, B. Now, 12V can be common among all your strips and shared from the 12V but the R,G,B inputs to each strip needs to be controlled individually by the Arduino. So for 4 strips you would need 3*4=12 outputs of the Arduino. However, these outputs must all be "PWM" pins. PWM stands for pulse width modulation. This feature allows you to set how much percentage of the time you keep the pin on or off in a repeating pattern. Since the Arduino Uno only has 6 PWM pins, you will need two Unos for 4 led strips. However, you can use one Arduino Mega to control 4 strips since the Mega has more PWM pins. And for each strip you will need 1 ULN2003 chip. So youll need 4 chips. the purpose of the chip is to convert the Arduino's 5V/0V output to a GROUND/Open Circuit output which allows or disallows electricity to flow from the 12V of each strip to the specific R,G,B pin, thus controlling the light.

    ReplyDelete
  49. Thanks for your reply, roy..
    And thanks again for your kind and brief explanation, all of your answer have cleared up my mind now. I have ordered 1 Arduino Mega and all the things you have explained above.
    Now i just have to wait till my items arrived and start to build this project..
    Cheers, kevin..

    ReplyDelete
  50. i used the scripts attached and i have a problem...
    i see tha the rx led in the arduino is flashing, but it has no effect on the leds...
    the all stay bright regardless of the screen color, although the little "window" created by the processing code is showing the right color.
    any idea ?

    ReplyDelete
  51. hi - everythings works great, i had a problem with the leds.
    i need a hint about a code that controls two led strips - one for the color of the right side of the screen and another for the left side...

    any idea ?

    thanks

    ohad

    ReplyDelete
  52. void draw()
    {
    int pixel; //ARGB variable with 32 int bytes where
    //sets of 8 bytes are: Alpha, Red, Green, Blue
    float r1=0; //left
    float g1=0; //left
    float b1=0; //left
    float r2=0; //right
    float g2=0; //right
    float b2=0; //right

    //get screenshot into object "screenshot" of class BufferedImage
    BufferedImage screenshot = robby.createScreenCapture(new Rectangle(new Dimension(1368,928)));
    //1368*928 is the screen resolution


    int i=0;
    int j=0;
    //left 684*928
    //I skip every alternate pixel making my program 4 times faster
    for(i =0;i<684; i=i+2){
    for(j=0; j<928;j=j+2){
    pixel = screenshot.getRGB(i,j); //the ARGB integer has the colors of pixel (i,j)
    r1 = r1+(int)(255&(pixel>>16)); //add up reds
    g1 = g1+(int)(255&(pixel>>8)); //add up greens
    b1 = b1+(int)(255&(pixel)); //add up blues
    }
    }
    r1=r1/(342*464); //average red
    g1=g1/(342*464); //average green
    b1=b1/(342*464); //average blue


    i=0;
    j=0;
    //right 684*928
    //I skip every alternate pixel making my program 4 times faster
    for(i =684;i<1368; i=i+2){
    for(j=0; j<928;j=j+2){
    pixel = screenshot.getRGB(i,j); //the ARGB integer has the colors of pixel (i,j)
    r2 = r2+(int)(255&(pixel>>16)); //add up reds
    g2 = g2+(int)(255&(pixel>>8)); //add up greens
    b2 = b2+(int)(255&(pixel)); //add up blues
    }
    }
    r2=r2/(342*464); //average red
    g2=g2/(342*464); //average green
    b2=b2/(342*464); //average blue



    port.write(0xff); //write marker (0xff) for synchronization
    port.write((byte)(r1)); //write red value
    port.write((byte)(g1)); //write green value
    port.write((byte)(b1)); //write blue value
    port.write((byte)(r2)); //write red value
    port.write((byte)(g2)); //write green value
    port.write((byte)(b2)); //write blue value
    delay(10); //delay for safety


    that should be on the processing side.
    on the arduino's side, again you can define two sets of r,g,b and parse it in this manner:

    if (Serial.available()>=7) {
    if(Serial.read() == 0xff){
    red_left = Serial.read();
    green_left= Serial.read();
    blue_left = Serial.read();
    red_right = Serial.read();
    green_right= Serial.read();
    blue_right = Serial.read();
    }
    }

    ReplyDelete
    Replies
    1. Could you please give the complete arduino code for two sets as above.
      Thanks a lot

      Delete
  53. Hi Rajarshi,

    Compliments. Well Done. I am based out of India (Mumbai) and am not sure if I can get all the components here.
    Would it be possible for you to build the Arduino Based PC Ambient Lighting for me. I have an XBMC runing on Xtreamer Ultra (Ubuntu)
    (am ready to pay the cost for this help)

    Please let me know.

    Thanks,
    Sanju

    ReplyDelete
  54. Hi Sanju,

    Even though the system works, its not very professional (Java isn't the fastest way to go about extracting screenshots and the Arduino is running a program above a bootloader layer rather than raw firmware) and was meant just for people to make their own and have fun with it. So I am really sorry I wont be able to make it for other people since both the Arduino code and the Processing code are too customized to my screen resolution to be used generally by anyone. I heard they sell Arduinos in India at this site: http://www.feemo.in/ .

    ReplyDelete
  55. Hello I am a gewkwn.
    Found a way to
    you can control
    16 channels pwm order to produce
    5 channels rgb.
    This will be done by adding a further
    chip with the code TLC5940.
    The functions in the found in
    http://www.arduino.cc/playground/Learning/TLC5940
    I broke the screen into four pieces.

    ReplyDelete
  56. and the code
    for tlc5940 is
    int red, green, blue; //red, green and blue values
    int red2, green2, blue2; //red, green and blue values
    int red3, green3, blue3; //red, green and blue values
    int red4, green4, blue4; //red, green and blue values
    #include
    void setup()
    {
    Tlc.init();
    Tlc.setAll(0);
    Serial.begin(57600);
    //initial values (no significance)
    int red = 255;
    int blue = 255;
    int green = 255;
    int red2 = 255;
    int blue2 = 255;
    int green2 = 255;
    int red3 = 255;
    int blue3 = 255;
    int green3 = 255;
    int red4 = 255;
    int blue4 = 255;
    int green4 = 255;
    }

    void loop()
    {

    //protocol expects data in format of 4 bytes
    //(xff) as a marker to ensure proper synchronization always
    //followed by red, green, blue bytes
    if (Serial.available()>=13) {
    if(Serial.read() == 0xff){
    red = Serial.read();
    green= Serial.read();
    blue = Serial.read();
    red2 = Serial.read();
    green2= Serial.read();
    blue2 = Serial.read();
    red3 = Serial.read();
    green3= Serial.read();
    blue3 = Serial.read();
    red4 = Serial.read();
    green4= Serial.read();
    blue4 = Serial.read();


    }
    }
    //finally control led brightness through pulse-width modulation
    Tlc.set(1, red*10);
    Tlc.set(2, green*10);
    Tlc.set(0, blue*10);
    Tlc.set(4, red2*10);
    Tlc.set(5, green2*10);
    Tlc.set(3, blue2*10);
    Tlc.set(7, red3*10);
    Tlc.set(8, green3*10);
    Tlc.set(6, blue3*10);
    Tlc.set(10, red4*10);
    Tlc.set(11, green4*10);
    Tlc.set(9, blue4*10);
    Tlc.update();
    delay(5); //just to be safe
    }

    ReplyDelete
  57. the code for processing is :
    https://rapidshare.com/files/3816305279/New_Text_Document.txt

    ReplyDelete
  58. Would be so bad ass to have it as a keyboard backlight!

    ReplyDelete
  59. Hi,
    I'm using a HTPC with hardware video acceleration (ION2).
    will the software work for me?

    thanks,
    BemB.

    ReplyDelete
  60. Maan Gewkwn, the shift register based approach is awesome. I wouldn't have guessed PWM would work over the overhead of shift registers but I recently read Hackaday about it and it does! In short, we can now have a bunch of LED strips from a single Arduino :D

    At BenB: I think it will. If its too slow, skip every 4 or 5 pixels, it will be much faster without losing much accuracy.

    ReplyDelete
  61. Hmm, that's a good idea, how to use LEDs for best benefits and decrease the Losses to zero percent..thank you sharing good ideas...:)

    LED Strip Light

    ReplyDelete
  62. I'm not great with electronics, but I thought I'd try this. Quick question though, is it possible to do without the ULN2003A? The piece itself is super cheap but I'm in Canada and shipping would be expensive...

    Thanks,
    Fletcher

    ReplyDelete
  63. Could you upload a higher resolution picture of your close up setup picture in your blog? I am trying to replicate your setup but as I don't have enough electronics knowledge I would like to study your setup from the picture. Thanks.

    ReplyDelete
  64. Hello

    Could you let me know if anyone in the UK has tried this...i am looking to use it on a product we have developed for healthcare?

    www.besmartcart.com

    Thanks

    ReplyDelete
  65. Wanted to test different sizes and smoothing, decided to replace hardcoded values with variables at the top of the script to make it easier:

    -----

    import java.awt.Robot; //java library that lets us take screenshots
    import java.awt.AWTException;
    import java.awt.event.InputEvent;
    import java.awt.image.BufferedImage;
    import java.awt.Rectangle;
    import java.awt.Dimension;
    import processing.serial.*; //library for serial communication


    Serial port; //creates object "port" of serial class
    Robot robby; //creates object "robby" of robot class

    void setup()
    {
    // port = new Serial(this, Serial.list()[0],9600); //set baud rate
    size(100, 100); //window size (doesn't matter)
    try //standard Robot class error check
    {
    robby = new Robot();
    }
    catch (AWTException e)
    {
    println("Robot class not supported by your system!");
    exit();
    }
    }

    void draw()
    {
    int pixel; //ARGB variable with 32 int bytes where
    //sets of 8 bytes are: Alpha, Red, Green, Blue
    float r=0;
    float g=0;
    float b=0;
    int xres=5760;
    int xsmooth=2;
    int yres=1200;
    int ysmooth=2;
    int xavg=xres/xsmooth;
    int yavg=yres/ysmooth;
    int zavg=xavg*yavg;
    int refreshdelay=10;

    //get screenshot into object "screenshot" of class BufferedImage
    //BufferedImage screenshot = robby.createScreenCapture(new Rectangle(new Dimension(1368,928)));
    BufferedImage screenshot = robby.createScreenCapture(new Rectangle(new Dimension(xres,yres)));
    //1368*928 is the screen resolution


    int i=0;
    int j=0;
    //1368*928
    //I skip every alternate pixel making my program 4 times faster
    for(i =0;i>16)); //add up reds
    g = g+(int)(255&(pixel>>8)); //add up greens
    b = b+(int)(255&(pixel)); //add up blues
    }
    }
    r=r/zavg; //average red (remember that I skipped ever alternate pixel)
    g=g/zavg; //average green
    b=b/zavg; //average blue

    //println("rgb values R " + r + ", G "+ g +" , B "+ b );
    //port.write(0xff); //write marker (0xff) for synchronization
    //port.write((byte)(r)); //write red value
    //port.write((byte)(g)); //write green value
    //port.write((byte)(b)); //write blue value
    delay(refreshdelay); //delay for safety

    background(r,g,b); //make window background average color
    }

    -------

    So:
    -xres and yres describes the size of the screenshot window. ( I have a three-screen setup and I wanted it to grab the whole screen )
    -xsmooth and ysmooth change how many pixels you skip when averaging
    -the xavg/yavg/zavg values pre-compute the number of pixels you need to determine average
    -refreshdelay lets you tweak how long the draw loop sleeps

    So - make changes in one place and see what works best for you.

    ReplyDelete
  66. Hummmm I really have no knowledge of Arduino's and haven't played with electronics in over a decade, but I got a question.

    I'd love to set this up with my home theater but I don't have a computer attached to it. Is it possible to like pre-program this and get it to work without a computer? Perhaps from the signal that goes to the TV from the receiver (HDMI)?

    ReplyDelete
  67. That is effin awesome. I was trying to do the same with Python, but I think I'll use your Processing code. Thank you so much!

    ReplyDelete
  68. What kind of performance hit would a lower powered Intel Atom based htpc take from a setup like this, running in conjunction with XBMC?

    ReplyDelete
  69. Hi Ray,
    I'm looking to get into this project, but I've a few questions: What is the plastic board the ULN chip is mounted on, and how did you attach the 12v power supply to the aforementioned plastic board? In addition, could you link a page, preferably sparkfun, as to where I could buy the plastic board?
    Thanks.

    ReplyDelete
  70. @iank1000 I have the exact same questions as you :-) Thats why asked for a higher resolution picture of the setup a few posts back so as to be able to figure it out. Anw for the board I managed to find it: its a Modular IC Breadboard Socket and u can get it at radioshack http://www.radioshack.com/product/index.jsp?productId=2734155. For the 12v power supply I hope someone else can answer.

    ReplyDelete
  71. I, too, want to make an ambient lighting device like this for use with my home theater. I
    d be using four strips of LED's around my 60 in. screen. I -think- it oughta look real spiffy. But, of course, there's no USB connection when not using the big screen as PC monitor. If anyone has come up with a decent solution for this, I and some others'll be properly grateful.
    BTW, I -have- wondered if there might be some sort of el cheapo camera device, mounted close & in front of the screen, to read the average light color and brightness & report same to the Arduino just as the USB data is. Sadly, I don't code, so I have no idea -if- that'd work, but it sounds like it oughta be easy for a real coder to make happen. Just a thought....

    ReplyDelete
  72. With a little bit of digging I've found I actually have some breadboards. And buying from radioshack is a sin D:<

    ReplyDelete
  73. Great stuff! Ordering parts right now! Thank you.

    ReplyDelete
  74. Has anyone got an idea for taking the composite video output and extracting the RGB information from it to use in a project similar to this? I'd like to able to do ambient lighting without a computer as I use standalone media player. Thanks :)

    ReplyDelete
  75. This comment has been removed by the author.

    ReplyDelete
  76. by the way, your project is now on lifehacker.com which is where I found it.

    http://lifehacker.com/5838840/make-your-own-ambient-lighting-system-for-your-computer-or-home-theater

    ReplyDelete
  77. Hello, I'm currently in the process of ordering all the necessary components; however, I'm new to Arduino and I am not sure how to connect the power supply to the breadboard. I understand I need to splice the 12vdc wire how do i determine whats positive and whats negative coming out from the power adapter?

    ReplyDelete
  78. @speakeasy201: You connect it to the +12V and the nearest pin for color directly on the LED strip. If it doesn't glow, flip it :) -12V wont screw your LED strip (i've done it)
    @test3s: I think some people did low pass filtering on VGA signal to do it.
    @people who want higher res picture: coming soon. Use the circuit diagram in the meantime. You can't go wrong with it
    @anonymus: Awesome code sample! Also refer towards the beginning of the comments section because someone contributed a code to handle multiple monitors
    @Alejandro: No HDMI is a complex protocol, not within my capabilities*time to figure it out :(
    General: any 12V adapter will work. The white board is called a breadboard: http://www.sparkfun.com/products/9567

    Thanks loads guys!! Looking further, from the comment contributions, we can actually:
    -have leds for multiple portions of the screen by changing the code and using shift registers
    -capture multiple portions of screen
    -handle multiple displays
    Maybe over thanksgiving Ill try to integrate all this together :D

    ReplyDelete
  79. Thanks Roy! How about getting the signal from the component or composite outputs?

    ReplyDelete
  80. @Alejandro
    The memory of the arduino is washed small for such a process

    ReplyDelete
  81. "washed small for such a process" Sorry, don't understand you.

    ReplyDelete
  82. Anyone knows why when I paste the code in processing under windows it runs fine but when I paste the same code in processing under ubuntu linux it throws an error???

    ReplyDelete
  83. hello im really interested in this project but i do not know much about electronics, about the chip you are using does it has to be that specific model , acuse in my local store y can find this 3 : ULN2003ADR, ULN2003AN, ULN2003AP. Would one of those work? if so wich one? Thx for your help in advance

    ReplyDelete
  84. @C: ULN2003AN :)
    @Alejandro: One rather expensive option ~189 dollars is to use a device called the Blackmagic Intensity. It captures HDMI data to your computer.

    ReplyDelete
  85. Love this project - working fine here as a proof of concept - however I use windows media center as my PVR/HTPC and have issues.

    Anyone know how to capture from the screen from windows media center when it's running in non-windowed mode? At the moment it always return 0 values for pixels.

    I believe the problem is that MCE writes to the screen directly (you can't for example do a normal screen grab either). I've searched for a delphi component (that's my language of choice) but without any luck. Has anybody got any clues?

    ReplyDelete
  86. This comment has been removed by the author.

    ReplyDelete
  87. Hi Raj,
    I have a question, it might sound so basic, but then I have no experience in electronics or such that.

    So, can I use this set up with TV. I have a LED tv and how do I connect the Arduino to the TV. There is a USB port on my TV but that I guess is input to TV only. Does this require a laptop or PC ?

    Please share your thoughts.

    Congrats and Awesome.

    Regards
    Brijesh.

    ReplyDelete
  88. this is very cool!

    everything seams to be connected correctly bc the led strip lights up but when i run the code in "possessor" and "arduino ide" the light just stays white. nothing happens other than that lil box with the color pops up. iv copied the codes correctly. am i missing something?

    thanks!

    ReplyDelete
  89. i am getting this error in Prepossessing...

    WARNING: RXTX Version mismatch
    Jar version = RXTX-2.2pre1
    native lib Version = RXTX-2.2pre2

    can anyone help?

    thanks

    ReplyDelete
  90. Hey, I love what you have done. I have it somewhat working, but only the red is changing... Its fluctuating with the change in desktop color, but there is no blue or green at all. Any Ideas?

    ReplyDelete
  91. @brett1990, dmitris: Do you guys have the latest version of Processing? Is the color in the little box correct? If so, and you get that error, it is a problem with Processing and Windows 7 drivers because I found a processing forum that discusses this: http://forum.processing.org/topic/how-do-i-install-rxtx-2-2pre1-jar-on-windows-7#25080000000981023

    @Uncled1023: Do each channel of your LEDs work by themselves when you apply 12v directly to them? If so, could you check your circuit to check all the pics are properly connected and most importantly the ground pin of the ULN2003A is connected?

    @Brijesh: I am sorry but this does need a PC. Since there is already ambient light for TVs, my purpose for the project was ambient light for computers.

    @TrickyDicky: Ahhh thats so frustrating.. It works perfectly with Windows media player. I wonder wassup with Windows media center ..

    ReplyDelete
  92. @Rajarshi I get the following error when I try to run the code in Ubuntu:

    Exception in thread "Animation Thread" java.lang.ArrayIndexOutOfBoundsException: 0
    at ColorPicker.setup(ColorPicker.java:43)
    at processing.core.PApplet.handleDraw(Unknown Source)
    at processing.core.PApplet.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:662)

    Any ideas? Thanks!

    ReplyDelete
  93. Rajarshi Roy thanks for the reply! your a pro!

    ReplyDelete
  94. hmm, now im just getting this in the Prossessing console...


    Stable Library
    =========================================
    Native lib Version = RXTX-2.1-7
    Java lib Version = RXTX-2.1-7

    ReplyDelete
  95. @brett1990, dmitris: I have no idea whats going on since I cant recreate the error here on my machine. When I made this video, I was using Processing 1.2.1. Try downloading that version (Standard) from the bottom of this webpage: http://processing.org/download/. Let me know if it works if made with that version!
    @speakeasy201: I soldered some pins onto it: http://www.sparkfun.com/products/116 so that its plugs into the breadboard nicely. But its up to you :) you can use wires too.

    ReplyDelete
  96. =/ still same with 1.2.1. oh well ill keep looking.

    thanks!

    ReplyDelete
  97. This is pretty sweet! thanks for sharing with us!
    I did add a bit to the arduino, just to make it change colours a bit smoother. so far it's working great!

    nred = Serial.read();
    ngreen= Serial.read();
    nblue = Serial.read();
    red = (red + nred)/2;
    green = (green + ngreen)/2;
    blue = (blue + nblue)/2;

    just takes the previous value and the new value and averages them. (you do need to add the new variables to the beginning of the code)

    ReplyDelete
  98. @MSPKD wow nice one! I'm talking a DSP course this semester and this smooths with much less memory needed than averaging a smoothing buffer :D

    ReplyDelete
  99. Hey everyone, I just wrote up a C# version of this. Here is the source code if you want to check it out. http://www.codefiendz.co.cc/led_backlight_changer/Source_Code.7z

    Enjoy. :)

    ReplyDelete
  100. Hi,
    I am able to upload the program to the arduino and run the sketch in processing, but nothing happens on my LED's. I had the same issue as brett1990, but resolved it (I think). I have bluetooth on another COM port. Any suggestions?

    ReplyDelete
  101. Can this be done without soldering anything? I'd like to try this, but I'm awful at soldering and will probably ruin it.

    ReplyDelete
  102. @Anonymous: Hi, yeah with multiple ports in use you have to kinda trial and error in this portion of the processing code:

    void setup()
    {
    port = new Serial(this, Serial.list()[0],9600); //set baud rate
    size(100, 100); //window size (doesn't matter)

    start off with the original code where its Serial.list()[0], if it does't work, change the code to Serial.list()[1], if that doesn't work then again change it to Serial.list()[2] and try. If it doesn't work by 5 or 6, let me know :)

    @Matt: it depends n which led strip you use, the sparkfun ones don't have any pins but only four blobs of solder where you have to solder the pins. Its a reealy minor soldering job! I'm sure you wont ruin it!

    ReplyDelete
  103. This looks amazing. What are the resolutions that you're using on your screen. I am Canada and after looking at this and realizing I have no experience I am going to call in some electronics from a friend... This would be cool to be playing games and have that ambient lighting just for added immersion.

    ReplyDelete
  104. up and running smoothly. Just starting with arduino and electronics. Pretty simple to set up. next step is to under stand the code a little better.

    ReplyDelete
  105. I did exactly as the blog said but my LEDs don't light up. What could I have done wrong?

    ReplyDelete
  106. @Dimitri
    Same issue here. I solved it doing this:
    http://forums.pragprog.com/forums/129/topics/8969
    Not the firmware bit, just copying the .so & jar files into the processing directories from the Arduino002 one.
    I am also using ubuntu 32bit

    ReplyDelete
  107. @Theodoros Thank you! That fixed the java mismatch I was having. Did u have also this error:

    Exception in thread "Animation Thread" java.lang.ArrayIndexOutOfBoundsException: 0
    at Color.setup(Color.java:43)
    at processing.core.PApplet.handleDraw(Unknown Source)
    at processing.core.PApplet.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:662)

    ReplyDelete
  108. Hi guys,
    I was looking at the code and I couldn't figure out what the values 9600 and 255 mean(see below), I need this because with these information, I am able to changed it so it could be easily change for more screenresolutions. I am sorry if it is a silly question.

    Thxs in advance, Passy

    arduino code:
    //--------------------------
    Serial.begin(9600);
    //initial values (no significance)
    int red = 255;
    int blue = 255;
    int green = 255;
    }
    //--------------------------

    ReplyDelete
  109. Anyway to get this to work through a TV or DVD player? I'm guessing not with the coding and all, but it would rock to rig this to my HD TV through a USB or Blu-Ray player USB somehow.

    But, I plan on making this for my gaming PC either way. Awesome stuff!

    ReplyDelete
  110. @passy Serial.begin(9600). 9600 is the bits/second that the computer is analyzing the data stream. As for 255, that is representative of RGB (Red Green Blue) values. The 3 primary colors have 256 values, when combining RGB you can get any color on a computer. Reason for 255 and not 256 is that it is calculated from 0-255, not 1-256. In your code example though, that appears to just be a default constructor. The actual values would have to be calculated based on each pixel on the screen.

    ReplyDelete
  111. @Jazzyflute. Thanx. But does the value 255 need to be changed for different screen resolutions? For Example: How do I change the value 255 for a resolution 1920x1080.

    ReplyDelete
  112. Thanks guys for answering questions for me. The maker/hacker community is truly awesome!
    @passy: the 255 doesn't matter since its just the initial values of red, green, blue. Notice that it is void setup() which only runs once. The code in void loop() is what matter since that code repeats over and over, updating the value of red, green, blue to the latest values. If you want to change screen resolution, the arduino code does not need to be changed. Rather change the processing code to: (for 1920x1080)
    -----------------------------------
    for(i =0;i<1920; i=i+2){
    for(j=0; j<1080;j=j+2){
    pixel = screenshot.getRGB(i,j); //the ARGB integer has the colors of pixel (i,j)
    r = r+(int)(255&(pixel>>16)); //add up reds
    g = g+(int)(255&(pixel>>8)); //add up greens
    b = b+(int)(255&(pixel)); //add up blues
    }
    }
    r=r/(960*540); //average red (remember that I skipped ever alternate pixel)
    g=g/(960*540); //average green
    b=b/(960*540); //average blue
    -----------------------------------------------
    Notice how I changed the bounds of my loop, and value to average over to match your resolution needs

    ReplyDelete
  113. Impressive, most impressive.

    ReplyDelete
  114. anybody get this to work on windows 7 x64 yet? Seems like Processing doesn't like 64 bit.

    ReplyDelete
  115. Hmm. my laptop runs on windows 7 x64. Processing works fine for me. Is you java installed correctly?

    ReplyDelete
  116. i really like this project, however I'm having some problems and i'm not sure how to fix them since i'm brand new to the arduino.
    I have matched your setup, but my LED stays white, no matter what. I've tried writing a simple arduino script just to output a different color, but it doesn't seem to work and i'm not sure if it's because my code is wrong or my setup is wrong. Do you have a simple, easy arduino script that simply changes the color of the led strip that i could use to test my setup and see if i can at least get the led strip to change color?

    Also, is it possible my uln2003a chip is faulty? if so, what would be the indications of that?

    thanks again for sharing such a cool DIY project!

    ReplyDelete
  117. Maybe a stupid question but does the pc must have a serial port in order for this to work??? I only have usb ports on my laptop! What does the serial line in the code in processing do? Thank you.

    ReplyDelete
  118. @Rajarshi via windows 7 x64. Java seems to be installed correctly. originally I was getting a mismatch error like stated above. I installed an older version to get rid of that. either configuration of java, LED's light up (all three colors), change color slightly when loading code to Arduino, then go back to same steady color. Processing Box pops up and changes color with window activity, it just seems that the color changing code isnt getting to the Arduino. I noticed in your video that there is some scrolling code in processing when it is working properly and I do not have that. I can not tell for sure because your video resolution is small.

    ReplyDelete
  119. @Uncled1023 i have the same problem with the red only changing colors. How did you solve your problem? I should have everything in place correctly. Was it the ground to the UL2003n chip?

    ReplyDelete
  120. Does anyone if a tv ambient light system like this can be set up without PC, but using video out and giving tha to aurdino..

    Jayesh.

    ReplyDelete
  121. Nm got it to work. The UL2003N was backwards. Works great now.

    ReplyDelete
  122. I might have stumbled upon the issue that I might be facing, and perhaps others as well.
    The ULN2003A is rated at 500mA, and I was using a 12V adapter I found lying around the house, without noting the current output. It was 2A! I think this is too much current for the ULN2003A to handle.

    I can not say for certain this is my issue, as I am going to have to order another 12v adapter with a lower current output. Perhaps someone with more experience with electronics can confirm or deny my theory.

    ReplyDelete
  123. well, I'm at the end of my ability to go at this alone.

    I've gotten another 12V adapter, this time outputting 1A, but I have the same exact result as before. The led strip just stays white, even with this simple program uploaded to the arduino.




    int RedPin = 9; //Red pin 9 has a PWM
    int GreenPin = 10; //Green pin 10 has a PWM
    int BluePin = 11; //Blue pin 11 has a PWM
    void setup() {}
    void loop()
    {

    for (int num=0;num<255;num++) {
    //finally control led brightness through pulse-width modulation
    analogWrite (RedPin, num);
    analogWrite (GreenPin, num);
    analogWrite (BluePin, num);
    delay(10); //just to be safe
    }
    }

    My wiring is the same as above, i have no idea what is wrong, and I'm out of ideas.

    If anyone is reading this, and could help, I would appreciate it.

    ReplyDelete
  124. Well something is wrong with my setup. I did the connections as per your image above and used all the components from the stores you suggested. However when I connect everything to the arduino and plug the power supply in only the green and blue leds light up!!! If I reverse the ULN2003A chip then only the red led lights up. On top of that I can't get processing to show the scrolling text you have in your video. It is as if is not communicating with the arduino. As per device manager and the arduino application it is on COM3 and also changed the code to:

    port = new Serial(this, "COM3", 9600);

    Its a mess! :-) Can someone help?

    ReplyDelete
  125. I'm dealing with the same problem as some others on here. The Processing box changes with the screen, but the LED's just stay white. Not getting any errors with the code, just can't get the LED's to change color.
    Any help would be great.

    ReplyDelete
  126. I have modified my post to add in a high res pic and also mention that the scrolling text will not appear if you run the code I posted because that was just for my debugging. As for those of you who are having trouble getting it to work, please send me an email (roy2cool@gmail.com) with closeup pictures of your setup, what operating system you are using and your screen resolution. I have had two people who email me and it was mainly small mistakes in connections.

    *NOTE* For those of you whose processing code run and the color changes properly, it means the connection with the Arduino is working. (Try not plugging in the Arduino and running, the code wont run). So the information definitely reaches the Arduino and the problem could thus most likely be: (1) The Arduino did not get flashed with the Arduino code or got wiped clean when it lost power (Happens to faulty UNOs). (2) The connections aren't properly done (power supply is not compatible or wrong wiring or ULN2003 chip is in wrong direction or your LED strip doesn't work/ pins are labeled wrongly)

    **To check if led strip and power supply works, directly connect your power supply's +12V to the +12V pin of the strip and power supply's ground to each R,G,B pin one at a time to see if they light up.
    **To check if your Arduino is retaining the flashed code in its memory, make sure the simple LED blink code works after disconnecting and reconnecting to power.
    **Processing code works (with Arduino connected of course) if you see it run and color in box changed properly. If not, change the serial port number in the code. If still doesn't work, check your Java installation.
    **If all of the above work, its got to be your connections that isn't properly done!

    ReplyDelete
  127. First let me just say thank you. This is such a cool project, I hope there are more to come in the future. And thanks for everyone who is helping (those of us who need it) to trouble shoot, it is greatly appreciated.
    I can't wait to get this running and see it in action!
    I'm getting the LED's staying white syndrome. The Processing box changes perfectly, the Arduino is running on com3, and Processing is set to [0], I don't know if that matters.
    I've rechecked the wiring, it seems fine. In the picture you have the chip facing the opposite way from what I had, so I changed it to be like the picture, but then I got no LED lighting at all. If I have it facing the other way(opposite of the picture) I get green, then when I plug in the Arduino the LED's turn white and stay white.
    When I unplug the Arduino, I can still run Processing and I get the little color changing box. I'm not sure if that means Processing is not communicating properly with the Arduino?

    I'm going to try reinstalling Java, and keep working on it.
    Again, thank you so much for this project!

    ReplyDelete
  128. So do I need to have Processing and Arduino on the same port setting?
    Right now this line of Processing works:
    port = new Serial(this, Serial.list()[0],9600); //set baud rate

    Arduino is on COM3(the only one that works)

    If I change Processing line to:
    port = new Serial(this, Serial.list()[3],9600); //set baud rate

    I get an error.

    Do I need to run Arduino on COM0?

    ReplyDelete
  129. I made some improvements:

    First, I choose the laster com port rather than the first (since I find the arduino is usually assigned to the last).

    Second I sed the screen width and height veriables to set the resolution (no need to hard code).

    Third, I added a sample counter to the loop for averaging: this way its easy to play around with the sampling rate and the area over which the code loops without having to adjust the averaging code.

    Fourth, I made a variable to adjust sampling rate (called speed_factor), I set it to look at every 8th pixel.

    Fifth, I added weights to each colour so that people could adjust for the relative intensities of their strip (tweak these until white looks properly white).

    Sixth, I added the ability to use borders rather than the while screen. (currently the width (border_size variable) is set to 0.5 which is the same as taking the while screen).

    Seventh, I made the window invisible so that this could actually be run in the background without being annoying.

    Finally, I added a running average (adjustable), by taking the next colour value as a mix of the current average and the previous one. The ratio of the mix (previous_value_weight variable) determines the amount of smoothing:

    ReplyDelete
  130. //Developed by Rajarshi Roy, modified (improved) by Daniel Rodgers-Pryor
    import java.awt.Robot; //java library that lets us take screenshots
    import java.awt.AWTException;
    import com.sun.awt.AWTUtilities;
    import java.awt.event.InputEvent;
    import java.awt.image.BufferedImage;
    import java.awt.Rectangle;
    import java.awt.Dimension;
    import processing.serial.*; //library for serial communication


    Serial port; //creates object "port" of serial class
    Robot robby; //creates object "robby" of robot class

    int r=0;
    int g=0;
    int b=0;

    public void init(){
    // to make a frame not displayable, you can
    // use frame.removeNotify()

    frame.removeNotify();
    frame.setUndecorated(true);

    super.init();
    }

    void setup()
    {
    noStroke();
    //frame.setAlwaysOnTop(true);
    frame.setLocation(screen.width,screen.height);
    AWTUtilities.setWindowOpaque(frame, false);
    AWTUtilities.setWindowOpacity(frame, 0.9f);

    size(1, 1); //window size (doesn't matter)
    port = new Serial(this, reverse(Serial.list())[0],9600); //set baud rate
    try //standard Robot class error check
    {
    robby = new Robot();
    }
    catch (AWTException e)
    {
    println("Robot class not supported by your system!");
    exit();
    }
    }

    void draw()
    {
    int pixel; //ARGB variable with 32 int bytes where
    //sets of 8 bytes are: Alpha, Red, Green, Blue


    // Weights
    float rw = .9;
    float gw = 1.0;
    float bw = 1.0;


    //get screenshot into object "screenshot" of class BufferedImage
    BufferedImage screenshot = robby.createScreenCapture(new Rectangle(new Dimension(screen.width, screen.height)));

    int speed_factor=8;
    float border_size=.5; // Percentage of screen width/height to measure for border (must be in [0, 0.5] range)
    float previous_value_weight=.1; // weight of previous colour value in determining (smoothing) new value.

    int i=0;
    int j=0;
    int pixel_samples = 0;

    int r_count=0;
    int g_count=0;
    int b_count=0;

    // Arbitrary speed factor skips pixels to imporve performance
    for(i=0; i>16)); //add up reds
    g_count += (int)(255&(pixel>>8)); //add up greens
    b_count += (int)(255&(pixel)); //add up blues

    pixel_samples++;

    if ((j > ceil(screen.height*border_size)) && (j < floor(screen.height*(1-border_size)))){
    j = (int)floor(screen.height*(1-border_size));
    }
    }

    if ((i > ceil(screen.width*border_size)) && (i < floor(screen.width*(1-border_size)))){
    i = (int)floor(screen.width*(1-border_size));
    }
    }
    r=(int)min((1-previous_value_weight)*(rw*r_count/pixel_samples) + previous_value_weight*r, 255); //average red
    g=(int)min((1-previous_value_weight)*(gw*g_count/pixel_samples) + previous_value_weight*g, 255); //average green
    b=(int)min((1-previous_value_weight)*(bw*b_count/pixel_samples) + previous_value_weight*b, 255); //average blue


    port.write(0xff); //write marker (0xff) for synchronization
    port.write((byte)(r)); //write red value
    port.write((byte)(g)); //write green value
    port.write((byte)(b)); //write blue value
    delay(2); //delay for safety

    //background(r,g,b); //make window background average color

    /*print(" ");
    print(r);
    print(" ");
    print(g);
    print(" ");
    print(b);
    print("\n");*/

    frame.hide();
    }

    ReplyDelete
  131. NICE. I gotta try it this weekend. I especially wanna check out the smoothing effects of the moving average :D

    ReplyDelete
  132. Im looking to buy the chip, but when I search the ULN2003A on the digikey.com website, this page comes up : http://search.digikey.com/scripts/DkSearch/dksus.dll?x=10&y=14&lang=en&site=us&KeyWords=ULN2003A+

    Which chip do I need to buy?

    ReplyDelete
  133. I think figured it out... Is it this one?

    http://search.digikey.com/us/en/products/ULN2003A/497-2344-5-ND/599603

    ReplyDelete
  134. Hi!

    Bare with me, I'm a real newbie in programming… :)

    I'm working at a project which involves mimicking the light from a television and was thinking i could use a modified version of your set-up but with a BlinkM Maxm instead of RGB strip.

    My idea is to "record" lets say 5 minutes of an video. Then put the color values and delays from processing in an Arduino sketch and upload it to the board Arduino for it to play in standalone mode (no computer)

    Is it possible for you to share the code for the debug information you had scrolling in the video. (I thought that was the color values and delays? but maybe I'm mistaken)

    But if so I was thinking I could use that information and put it in the sketch for Arduino.
    Maybe this isn't as easy as i think..

    I would be deeply grateful, if you could point me in the right direction.

    Cheers! /lull

    ReplyDelete
  135. For anyone who's interested, I've rewritten the whole thing in Python (its faster, and it removes the mouse-flicker that java-robot-screengrabbing introduced):

    # Written by Daniel Rodgers-Pryor
    import serial
    import math
    import time
    from PIL import ImageGrab
    import Image
    import win32gui, win32ui, win32con, win32api
    import threading


    def write(r, g, b):
    lock.acquire()
    port.write(bytes(chr(255) + chr(r) + chr(g) + chr(b)))
    time.sleep(0.002) #delay for safety
    lock.release()


    # Settings #
    speed_factor = 16
    border_size = 0.5 # Percentage of screen width/height to measure for border (must be in [0, 0.5] range)
    previous_value_weight = 0.1 # weight of previous colour value in determining (smoothing) new value.

    # Weights:
    rw = .85
    gw = 1.08
    bw = .95


    # Initialise #
    port = serial.Serial("COM3", 9600)

    r = 0
    g = 0
    b = 0
    width = win32api.GetSystemMetrics(0)
    height = win32api.GetSystemMetrics(1)

    lock = threading.Lock()
    writer = threading.Thread(target=write, args=(r, g, b))
    writer.start()

    while True:
    #start = time.time()

    pixel_samples = 0
    r_count = 0
    g_count = 0
    b_count = 0

    screen = ImageGrab.grab()

    """
    hwin = win32gui.GetDesktopWindow()
    hwindc = win32gui.GetWindowDC(hwin)
    srcdc = win32ui.CreateDCFromHandle(hwindc)
    memdc = srcdc.CreateCompatibleDC()
    bmp = win32ui.CreateBitmap()
    bmp.CreateCompatibleBitmap(srcdc, width, height)
    memdc.SelectObject(bmp)
    memdc.BitBlt((0, 0), (width, height), srcdc, (0, 0), win32con.SRCCOPY)
    """

    for i in range(0, width, speed_factor):
    for j in range(0, height, speed_factor):
    pixel = screen.getpixel((i,j)) #the ARGB integer has the colors of pixel (i,j)

    r_count = r_count + pixel[0]
    g_count = g_count + pixel[1]
    b_count = b_count + pixel[2]

    """
    pixel = memdc.GetPixel(i, j)

    r_count = r_count + (255&(pixel>>16)) #add up reds
    g_count = g_count + (255&(pixel>>8)) #add up greens
    b_count = b_count + (255&(pixel)) #add up blues"""

    pixel_samples = pixel_samples + 1

    if ((j > math.ceil(height*border_size)) and (j < math.floor(height*(1-border_size)))):
    j = math.floor(height*(1-border_size))
    if ((i > math.ceil(width*border_size)) and (i < math.floor(width*(1-border_size)))):
    i = floor(width*(1-border_size))

    #print time.time()-start

    r = int(max(min((1-previous_value_weight)*(rw*r_count/pixel_samples) + previous_value_weight*r, 255), 1)) #average red
    g = int(max(min((1-previous_value_weight)*(gw*g_count/pixel_samples) + previous_value_weight*g, 255), 1)) #average green
    b = int(max(min((1-previous_value_weight)*(bw*b_count/pixel_samples) + previous_value_weight*b, 255), 1)) #average blue

    writer.join()
    writer = threading.Thread(target=write, args=(r, g, b))
    writer.start()

    ReplyDelete
  136. hi, i have a question about the processing code. is it possible to get 4 different colour outputs, from different parts of the screen? for example the top left, top right, bottom left and bottom right.

    And then send them to the arduino as separate values? thanks for your help already

    ReplyDelete
  137. Sooo Im a bit stuck here. Any ideas would help as I am not entirely clear with how to run the program.

    I wired the Arduino chip and bread board EXACTLY as specified in this tutorial. The LEDS test OK (tested seperately using the 12v power supply).
    I can run the Processing code and I get the small pop-up window displaying the colors from my screen. However I am not sure if I need to be running the 2nd Arduino code after or before?

    I am not getting any lights on the LED strip?
    I do however get this error in the processing code:
    WARNING: RXTX Version mismatch
    Jar version = RXTX-2.2pre1
    native lib Version = RXTX-2.2pre2
    If I am suppose to run the Arduino code, I hit 'upload' and get a Serial port COM is already in use message, but Ive checked and there are no other devices using the COM port.
    Ugh.

    ReplyDelete
  138. @chachtastic :
    I believe you have to run the Arduino code first. When I run Processing first, I get the 'com port already in use' error. You can specify which COM port to use under the tools tab in Arduino. In Processing you have to modify the line of code to specify the COM port.
    As far as the 'WARNING: RXTX Version mismatch
    Jar version = RXTX-2.2pre1
    native lib Version = RXTX-2.2pre2' error, I was getting that at first too. Somewhere in the above comments it was recommended to try using Processing 1.2.1. and that worked for me.
    Hope this helps, and good luck!

    ReplyDelete
  139. Has anyone gotten this to work with games?
    Just wondering, I can't seem to get it to work on the games I'm trying. It would be really cool, it's great for movies.
    Thanks!

    ReplyDelete
  140. @riverboy6:
    Thanks! I used 1.2.1 which did the trick and I no longer get the error message.
    I set the COM port in Arduino but I am not sure where to edit the line of code to specify the COM port in Processing? I don't see a spot in the code to specify the COM port. Help? Thanks in advance!
    Also does anyone know if there is a minimum as far as amps go? Im using a 12v 300mA adapter.

    ReplyDelete
  141. Try changing this:
    port = new Serial(this, Serial.list()[0],9600); //set baud rate

    To this:
    port = new Serial(this, "COM3",9600); //set baud rate

    I believe that's the correct syntax. I had to change the COM port in Processing as well, and I think that's what I did.

    ReplyDelete
  142. Thanks, I changed the code and it seems to run just fine, but Im still not getting any lights on my LED strip. Im wondering if 300 mA isn't enough?
    That, or I need to doublecheck all the wires are making a connection to the bread board...

    ReplyDelete
  143. @Rajarshi Roy
    can you verify the output amps of your ac adapter?

    @drogers
    FYI, your code does not compile in processing 1.2.

    for(i=0; i>16)); //add up reds

    i have no idea what you're trying to do on this line, but it looks like no for loop i've ever seen

    your python code is unreadable on this site as there is no indentation, so i can't even evaluate if it works or not

    ReplyDelete
  144. Agree with the above.

    I have got it working, but my LED strip just isn't too bright... will wait til night to try it properly.

    Also, would you be able to use a 60 LED strip and run it in exactly the same way?

    Cheers

    ReplyDelete
  145. @dan Mine is also not too bright. I was also thinking of ordering the 1m 60led strip but I would like to confirm that the 60led strips will work before ordering.

    ReplyDelete
  146. Hmm, I am using the updated arduino code from Roy, as well as his base processing code (with the "reverse" addition from Drodgers. I uploaded successfully to the arduino, but the LED strip is only lighting green. The others light up, but they are dim by comparison. Any idea why it wouldn't be changing?

    ReplyDelete
  147. Well, I have the Strip sending out much more reasonable levels of light now, but I still can't get them to change.

    ReplyDelete
  148. @Turbounicorn: see few comments back which has a debugging checklist.
    The output amps of my AC-DC adapter is rated 1.0A. (for those who didn't know this, the 1.0A refers to the max current draw, the actual current draw varies based upon how much load you put on it)
    To those who aren't getting bright LEDs: please check that you ULN2003 chip is grounded and in the correct direction. Something interesting that someone encountered was that his PWM pins 9,10,11 weren't working :S He tried using pin 3,5,6 (with the code changed accordingly) and it worked!

    ReplyDelete
  149. Hmm, I bought the same adapter you did. I don't have a voltmeter where I'm at, but at night the brightness is comparable to what you had in the video. I realize that the discrepancy might be because your laptop is ~15" vs my 24" monitor. I figure that might be what makes mine look dimmer than yours in comparison.

    Right now, I am getting the weird issue of the box showing the right color, but the LEDs only lighting up in varying shades of green. Generally, Red and Blue are bright green (red has a slightly blue tint) and Green is a dimmer version of green. I have checked the wiring 100 times, so I am at a loss atm.

    ReplyDelete
  150. Turns out my ULN2003 chip was bad. Replaced that an I'm up and running! Thanks for the help, and awesome project

    ReplyDelete
  151. Phew!!! I hate these kind of bugs where something totally unforeseen takes you a long route down the wrong debugging pathway. Glad that it works now :D

    ReplyDelete
  152. Can someone tell me where I am going wrong with this thing?
    I bought the suggested adapter, all wiring is correct, checked a bazzillion times. Anyone have any ideas/tips/suggestions? I am this close to giving up on this thing entirely...

    ReplyDelete
  153. @Chachtastic: did you run through the debugging step mentioned earlier? is your circuit working without the arduino? (by this, i mean are individual channels working separately and all together at once when you raise the input pins of the ULN2003 to 5V instead of hooking them to the PWM pins of the Arduino). If this works that means all your wiring and chips and rgb strip works.

    ReplyDelete
  154. THANKS ALL! I finally got it, turns out I was off by 1 pin, lol. I should have checked my wiring a bazzillion and 1 times. Glad I had someone else take a look at my wiring. Awesome, awesome project, totally worth the time and I cant wait to add an additional LED strip for 2x the awesome on my TV. Will definitely post my journey on youtube, update to come. Thanks again!

    ReplyDelete
  155. So, is it determined that 500mA isn't enough for the strip. That's what I have feeding it and there is almost no light coming from the LEDs. I'll try and find a stronger one, but they are kind of hard to come by... Seeing lights that correspond with the screen though - good stuff :)

    ReplyDelete
  156. @Jeff F: Chachtastic got it working with a 300mA adapter. For a LED strip, 500mA should be more than enough actually! Send me an email with your wiring all done if you want me to take a look at it. I have a gut feeling that your ULN2003 chip's pin 8 isn't grounded.

    ReplyDelete
  157. I've had my ground from Arduino connected to pin 8, but not being real experienced in electrical work, I now realize that both need to be connected to ground from the 12v power source. I just did that with some soldering and no light at all comes out of the LEDs. I'm pretty positive I have the polarity right from a multimeter test I did, but again, not real experienced. I wish I could attach a picture of my light output here, but I guess I can't.

    ReplyDelete
  158. Ok, got mine working - turns out it was the power polarity...ugh.

    Here's a crude video demonstrating - it's a bit hard to see how well it matches the video on screen, but here it is anyway:

    http://www.youtube.com/watch?v=Bzjh1NllRdo

    ReplyDelete
  159. your LED strip's blue and green channel's labels are switched. switch them :)

    ReplyDelete
  160. Rajarshi-
    So I built and used the system you created for about a month or so, but one day when I attempted to use it, the code cited an error here:
    port = new Serial(this, Serial.list()[1],9600);
    I had to change which COM port it was using, but now it will only run if I change it back to 0.
    Any ideas?

    ReplyDelete
  161. I have had this setup for a few months now and love it, but is there any way for this to work in blu ray playback software like power dvd 11, or in pc game playback?

    ReplyDelete
  162. anybody know how to fix the slight delay between what is actually on the screen and what the LEDs are doing? When watching movies this can be really distracting...or is this simply a smoothing problem. If so, has anybody written smoothing code for this project?

    ReplyDelete
  163. This comment has been removed by the author.

    ReplyDelete
  164. I have made some LED columns that might be pretty cool with your code implemented. I would have to modify the code to run both channels. But I don't think it would be to hard. Might have to give it a try someday. Cool project. Keep it up!

    http://ennyled.blogspot.com/

    ReplyDelete
  165. Nice! yeah modifying the code isn't hard. Just edit the starting and ending points of the two for loops. 0 to (horizontal resolution)/2 for left channel and (horizontal resolution)/2 to (horizontal resolution) for right channel :)

    ReplyDelete
  166. i like your blog too much so i you have written this blog very nicely and with your complete efforts as i have done my own led computer lights so i would like to thank you dear for sharing it with us and keep keep it up dear for more informative blogs

    ReplyDelete
  167. anyone tried to drive this hardware with the application from http://www.facebook.com/pages/Ambient-Reality-Effects/218635631480498

    ReplyDelete
  168. train horn Train horns for sale are available in many retailers. However, to avoid excessive back and forth searching for the best deal, it is advisable to shop online (at least to begin with) in order to carry out the necessary research to make a good final decision

    ReplyDelete
  169. Hello Rajarshi! I set up the circuit like you described, wrote the code onto the Arduino and ran the required program but I do not see any output on the RGB strip. I'm wondering whether the RGB strip I received is different from yours. My strip has wires coming out of both ends. Where am I supposed to connect the other end of the strip? Also, just to confirm, there are four colored wires on the strip. The black one, I assume is power and the red, green and blue wires are the R, G and B inputs in the circuit diagram.

    ReplyDelete
  170. Can the ULN2003 be used with 18m of led strip(thats 540 leds, 0,3A/m)?

    I made this a while ago but haven't tried it for longer periods of time as the room isn't all done yet. But it works at least for a couple of minutes.

    What can happen?
    Can the ULN2003 break, can there be a fire, can the arduino uno break?

    You should have some kind of sponsormebutton for saying thanks because words don't feel like enough.

    ReplyDelete
  171. Going to bump Ralphie's post. I also recently ordered all the parts and my LED strip has another end with 4 wires coming out. Where are these supposed to be plugged?

    ReplyDelete
  172. Hello!
    I need help.
    I made the connection of a single strand of LED correctly.
    I sent the code to the arduino and processing did, but the LEDs do not light.
    I know that the connection is correct because when sending a type code LED flashes they blink normally.

    void setup() {

    pinMode(11, OUTPUT);//Declara que o pino 11 do arduino é de Saída. Vai mandar dados, energia...
    pinMode(10, OUTPUT);//Declara que o pino 10 do arduino é de Saída. Vai mandar dados, energia...
    pinMode(9, OUTPUT);//Declara que o pino 9 do arduino é de Saída. Vai mandar dados, energia...
    }

    void loop() {

    digitalWrite(11, HIGH); // Diz que o pino 12 do arduino está Ligado. Logo LED ON
    delay(1000); // Espera por 1s

    digitalWrite(11, LOW); // Diz que o pino 12 do arduino está Desligado. Logo: LED OFF
    delay(1000); // Espera por 1s

    digitalWrite(10, HIGH); // Diz que o pino 12 do arduino está Ligado. Logo LED ON
    delay(1000); // Espera por 1s

    digitalWrite(10, LOW); // Diz que o pino 12 do arduino está Desligado. Logo: LED OFF
    delay(1000); // Espera por 1s

    digitalWrite(9, HIGH); // Diz que o pino 12 do arduino está Ligado. Logo LED ON
    delay(1000); // Espera por 1s

    digitalWrite(9, LOW); // Diz que o pino 12 do arduino está Desligado. Logo: LED OFF
    delay(1000); // Espera por 1s

    digitalWrite(11, HIGH); // Diz que o pino 12 do arduino está Ligado. Logo LED ON
    delay(1000); // Espera por 1s
    digitalWrite(10, HIGH); // Diz que o pino 12 do arduino está Ligado. Logo LED ON
    delay(1000); // Espera por 1s
    digitalWrite(9, HIGH); // Diz que o pino 12 do arduino está Ligado. Logo LED ON
    delay(1000); // Espera por 1s

    digitalWrite(11, LOW); // Diz que o pino 12 do arduino está Ligado. Logo LED ON
    delay(1000); // Espera por 1s
    digitalWrite(10, LOW); // Diz que o pino 12 do arduino está Ligado. Logo LED ON
    delay(1000); // Espera por 1s
    digitalWrite(9, LOW); // Diz que o pino 12 do arduino está Ligado. Logo LED ON
    delay(1000); // Espera por 1s
    }

    When I do the processing of the arduino led flashes but does not send power to pin 11,10 and 11.
    Someone tell me how to fix it?
    Thank you.
    Fernando Garcia

    ReplyDelete
  173. Hi Rajarshi,

    I'm working on a Windows C++ port of this, for people who don't want to use Processing. If you want, I'll post the link when I'm done :)

    ReplyDelete
    Replies
    1. Did you ever manage to finish this yet?

      Delete
    2. I Too, Would Like this. As i could set it to autorun on startup. BD

      Delete
  174. Hey! Thanks alot for sharing this! its awesome!

    I seem to got everything working, but I cant seem to get the lights to go green or any shade of green/yellow. Even if i fill the screen with r=0 b=0 g=255, the lights are a blue color....

    If i unplug the blue wire of the LED i can get greens, but no blue obviously.. but once i plug the blue back in, all the greens become blue...

    Any help is greatly appreciated!

    ReplyDelete
    Replies
    1. Switched to pins (2,3,4) on arduino and adjusted code accordingly, and I can now get Green channel working... strange...

      Not liking that if there is a little bit of black on screen it adds red... (i.e. watching a movie widescreen (not full screen) with black bars on top and bottom, typically I'll get red lights, even when majority of screen is filled with any other color...

      anyone else?

      Delete
  175. That is all great tutorial thanks very helpful.

    Arduino

    ReplyDelete
  176. Hi, has anybody else ran into the issue where the lights switch quickly to red, blue, yellow, green, etc. When the colors should be something static. I restart the Java program and it works fine for about 5-10 minutes and starts up again, sometimes it doesn't fix it. I've already replaced the arduino, and uln2003a chip. No change.
    Thanks

    ReplyDelete
  177. So after a few hours I got this working, kind of. It is only taken the top left corner of my screen. The resolution is right. Does anyone know what could cause this? I am using dual monitors, BUT I disconnected the second one and it is still not working.

    ReplyDelete
  178. I also have dual monitors and wondering the same thing.

    ReplyDelete
  179. Not too good with processing myself, any chance of adding a button to the little window, that blacks the strip, for night time.. :3
    my pc is on 24/7 in my bedroom..
    otherwise who wants to see some snazzy pics of my setup? :3
    i crammed, eer... planned out and put it into an old data cartridge box

    ReplyDelete
  180. Hey my name is Dan. I seem to be having problems with the usb comunication from the computer to the arduino.When my arduino is pluged to the pc and i take my tester, nothing is fluctuating on the pins 9, 10 and 11. For the processing part, everything works but nothing with the arduino. What could be the problem? guenette1972@gmail.com is my e-mail.

    Thanks!!!

    ReplyDelete
  181. i`ve got the same problem that Daniel Guenette...
    any idea?

    thanks

    ReplyDelete
  182. Pessoal,
    Acesse o site da EMPRETECNET, eles fabricam um KIT com uma placa compatível com arduino duemilanove, uma placa de rele, de potenciômetro, de sensor de luz, de sensor de luminosidade, de buzzer, de botão e demais componentes que podem ser realizados vários experimentos sem a necessidade de solda. Qualidade excelente!!

    ReplyDelete
    Replies
    1. English please, i dont understand spanish. Sorry!!!

      Delete
  183. Daniel, this is portuguese.

    ReplyDelete
  184. this would be awesome an i would love to do it if i understood it

    ReplyDelete
  185. Just an update, I have been using my arduino setup with my computer and watching movies for the past couple of weeks. Absolutely love it. Makes movie watching (especially Star Wars) so much more enjoyable! Also, added an on/off switch to make movie watching even easier.

    Sad news though, my green stopped working out of nowhere? I checked the connections, and tested the green strip, works fine, but for some reason when everything is connected it doesn't seem to work??? I will have to set some time on the side to work on this. Anyone else have similar issues?

    ReplyDelete
    Replies
    1. for me my green never worked until I switched to pins (2,3,4) on arduino and adjusted code accordingly.. so far it works fine....

      Delete
  186. Excellent tutorial! Thank you very much. I have ordered the kit I need to make this project and can't wait until it arrives. I've never used Arduino before but looking forward to haveing a play with it.

    I've noticed quite a few people saying that colour channels have failed, or only works a short time. This may not be the answer to those issues but is certainly worth considering.

    The maximum current of the ULN2003A is 500ma/channel. If you try to drive more than that the IC will probably fail. When some ICs fail they can go short-circuit and there is a potential to damage the Arduino outputs (I say potential as I am not familiar with the Arduino yet, so don't know if it has its own forms of protection or not). A simple diode on the outputs of the Arduino may solve the issue (if it is an issue).

    Also with the max current fo the IC being 500ma this means that you could only drive a maximum of 1.25 meters of a 5050 based RGB LED channel. 5050 LED channel = 4.8 watts/meter = 400ma/meter @ 12v.

    This is something I need to get around as I will be installing 3 meters of 5050 RGB LED. I have thought about chopping it up into 1m lengths and driving each 1m length with a seperate channel from the ULN2003A (thus needing two ICs). I will need to work out how to parrallel the inputs to the IC so some testing will be required when I get my gear.

    Please note that the figures I have quoted are for the specs of the 5050 RGB LED that I have purchased, other makes/manufactures may vary in spec so it is well worth doing the math.

    I hope this helps anyone, and I will most certainly report back once I have established a way to drive my 3m.

    ReplyDelete
    Replies
    1. Please write here if you find something out.
      I don't have too much experience with these things.
      I followed this guide for 18m of 5050 ledstrip. It works but I don't know if I dare to run if for hours.

      Is there any possibility for a fire?

      Delete
  187. Anyone get this to work inside Windows Media Center. I have a 2 LED channel split screen setup and works great except WMC.

    ReplyDelete
  188. I have a proposal for anyone who would like to purchase a pre-built lighting system based on this design. The design will be completed with a fabricated design, I have made this product and supports 3 channels for left and right. Will come pre-built with an installer package. The only exception is the alpha still isn't working with WMC, i plan on taking a few beta testers to test a few packages. The package will come with the control box, a 12v adapter, usb cable, and two 1 meter light strips for each channel. I am still determining which lights to use, possibly the 5050. Contact me at bradjobe77@hotmail.com if you are interested. Oh not to mention my software will have a taskbar icon to adjust smoothing for both channels and the ability to shut off in 2d enviroment and will kick on during fullscreen video and 3d gaming. Also the ability to support multiple monitors with future patches.

    ReplyDelete