Tuesday, May 19, 2009

Arduino Mood light controller

UPDATE: New source code and videos here.

Background
I love black and white, especially white. But I also love color, however I tend to change what type of color I like ALOT. So when saw the concept of coloring a surface with light I knew I had to try it at home.

The hardware I decided to use my new found love the Arduino micro controller to control some sort of light. At first I thought about using IKEAS DIODER but as MikMo pointed out the RGB LED strip from Deal Extreme is quite a much better deal. A little over $16 and free shipping from Hong Kong.


What I wanted to achive


  1. Select a specific color
  2. Pulsate the specified color
  3. Random color swash i.e. go smoothly from color to color.

Controlling the colors
I decided to use a ULN2003 with the Arduino to control the DX RGB LED strip. It can handle enough amps to drive the LED strip and it's also alot neater than multiple transistors.




Arduino control of LED strip via ULN2003
RGB LED strip 400 mA @ 12 V


R1 = 10K Potentiometer (Color selector) R2 = 100 Ohm (Pin protector)
R3 = 10K Ohm (Pulldown resistor) S1 = Switch (Mode selector)





One potentiometer to rule them all
When I first started out mixing RGB colors I used three potentiometers, one for each color. This ofcourse gives you a high resolution but also three different knobs. So inspired by the Philips LivingColors, I decided to streamline my color control using only one potentiometer connected to an analog in pin on the Arduino.



As you can see in the picture below the value 0 on the analog pin is full red and then changes through the color circle back to red as the value reaches 1023.



Note: I used Adobe Illustrator to create the image above, to help me think, but when using gradient fill in Illustrator some colors take up more space than others. At least it looks like that if you space them evenly. I don't know if this also is the case with my color mixer, but I haven't really bothered to figure that out.


At first I used alot of steps before I realized I could remove some of them. Orange for example is produced when you have more red than green on your way to yellow (full red and full green). But purple requires both full red and full blue. Hence some I could remove some steps and had to keep some of them.




Videos



Button presses in the video
Filmed in broad daylight, hence the colors don't really come out too well.
1. On - Select a color with the color selector.
2. Pulse - Pulsate the selected color.
3. Random/Cycle - Cycle randomly through the palette.
4. Off.



Pulse Mode
Filmed in a dark room with the RGB-strip hidden behind the laptop screen.





Random/Cycle Mode
Filmed in a dark room with the RGB-strip hidden behind the laptop screen.


Source code

UPDATE: New source code and videos here.


The finished code with four modes, also available as a download here.
Formatted for Blogger with: formatmysourcecode.blogspot.com
/*
RGB LED controller
4 modes: off, color select, color pulse and random cycle/pulse
By Markus Ulfberg 2009-05-19

Thanks to: Ladyada, Tom Igoe and
everyone at the Arduino forum for excellent
tutorials and everyday help.

*/

// set the ledPins
int ledRed = 10;
int ledGreen = 9;
int ledBlue = 11;

// color selector pin
int potPin = 1;

// lightMode selector
int switchPin = 2;

// light mode variable
// initial value 0 = off
int lightMode = 0;

// LED Power variables
byte redPwr = 0;
byte greenPwr = 0;
byte bluePwr = 0;

// Variables for lightMode 2
// variables for keeping pulse color
byte redPulse;
byte greenPulse;
byte bluePulse;

// Set pulse to down initially
byte pulse = 0;

// floating variables needed to be able to pulse a fixed color
float redFloat;
float greenFloat;
float blueFloat;

// the amount R,G & B should step up/down to display an fixed color
float redKoff;
float greenKoff;
float blueKoff;

// Variables for lightMode 3
// set the initial random colors
byte redNew = random(255);
byte greenNew = random(255);
byte blueNew = random(255);

// misc interface variables
// potVal keeps the value of the potentiometer
int potVal;
// value from the button (debounce)
int switchVal;
int switchVal2;
// buttonState registers if the button has changed
int buttonState;

void setup()
{
pinMode(ledRed, OUTPUT);
pinMode(ledGreen, OUTPUT);
pinMode(ledBlue, OUTPUT);

pinMode(potPin, INPUT);

pinMode(switchPin, INPUT);
buttonState = digitalRead(switchPin);

// serial for debugging purposes only
Serial.begin(9600);
}

void loop()
{
switchVal = digitalRead(switchPin);      // read input value and store it in val
delay(10);                         // 10 milliseconds is a good amount of time
switchVal2 = digitalRead(switchPin);     // read the input again to check for bounces
if (switchVal == switchVal2) {                 // make sure we got 2 consistant readings!
if (switchVal != buttonState) {          // the button state has changed!
if (switchVal == LOW) {                // check if the button is pressed
if (lightMode == 0) {          // light is off
lightMode = 1;             // light is on and responds to pot
} else {
if (lightMode == 1) {
lightMode = 2;           // light pulsates in the latest color from pot
} else {
if (lightMode == 2) {
lightMode = 3;           // light changes randomly
} else {
lightMode = 0;             // light is off 
}
}
}
}
}
buttonState = switchVal;                 // save the new state in our variable
}
if (lightMode == 0) {      // turn light off
analogWrite(ledRed, 0);
analogWrite(ledGreen, 0);
analogWrite(ledBlue, 0);
}
if (lightMode == 1) {        // set fixed color

// read the potentiometer position
potVal = analogRead(potPin);


// RED > ORANGE > YELLOW
if (potVal > 0 && potVal < 170) {
redPwr = 255;
bluePwr = 0;
analogWrite(ledRed, redPwr);
greenPwr = map(potVal, 0, 170, 0, 255);
analogWrite(ledGreen, greenPwr);
analogWrite(ledBlue, bluePwr);
}

// YELLOW > LIME?? > GREEN
if (potVal > 170 && potVal < 341) {
greenPwr = 255;
bluePwr = 0;
analogWrite(ledGreen, greenPwr);
redPwr = map(potVal, 341, 170, 0, 255);
analogWrite(ledRed, redPwr);
analogWrite(ledBlue, bluePwr);
}

// GREEN > TURQOUISE
if (potVal > 341 && potVal < 511) {
greenPwr = 255;
redPwr = 0;
analogWrite(ledGreen, greenPwr);
bluePwr = map(potVal, 341, 511, 0, 255);
analogWrite(ledBlue, bluePwr);
analogWrite(ledRed, redPwr);
}

// TURQOUISE > BLUE
if (potVal > 511 && potVal < 682) {
bluePwr = 255;
redPwr = 0;
analogWrite(ledBlue, bluePwr);
greenPwr = map(potVal, 682, 511, 0, 255);
analogWrite(ledGreen, greenPwr);
analogWrite(ledRed, redPwr);
}

// BLUE > PURPLE
if (potVal > 682 && potVal < 852) {
bluePwr = 255;
greenPwr = 0;
analogWrite(ledBlue, bluePwr);
redPwr = map(potVal, 682, 852, 0, 255);
analogWrite(ledRed, redPwr);
analogWrite(ledGreen, greenPwr);
}

// PURPLE > RED
if (potVal > 852 && potVal < 1023) {
redPwr = 255;
greenPwr = 0;
analogWrite(ledRed, redPwr);
bluePwr = map(potVal, 1023, 852, 0, 255);
analogWrite(ledBlue, bluePwr);
analogWrite(ledGreen, greenPwr);
}
redFloat = float(redPwr);
greenFloat = float(greenPwr);
blueFloat = float(bluePwr);

redKoff = redFloat / 255;
greenKoff = greenFloat / 255;
blueKoff = blueFloat / 255;

redPulse = redPwr;
greenPulse = greenPwr;
bluePulse = bluePwr;

/*
// Debug
Serial.print("redFLoat: ");
Serial.print(redFloat, DEC);
Serial.print(" redPwr: ");
Serial.print(redPwr, DEC);
Serial.print(" greenFloat: ");
Serial.print(greenFloat, DEC);
Serial.print(" greenPwr: ");
Serial.print(greenPwr, DEC);
Serial.print(" blueFloat: ");
Serial.print(blueFloat, DEC);
Serial.print(" bluePwr: ");
Serial.println(bluePwr, DEC);
// End debug
*/

}

if (lightMode == 2) {     // pulse fixed color

// display the colors
analogWrite(ledRed, redFloat);
analogWrite(ledGreen, greenFloat);
analogWrite(ledBlue, blueFloat);

// add delay here for speed control
delay(5);

// pulse down
if (pulse == 0) {
if (redFloat > 10) {
redFloat = redFloat - redKoff;
}
if (greenFloat > 10) {
greenFloat = greenFloat - greenKoff;
}
if (blueFloat > 10) {
blueFloat = blueFloat - blueKoff;
}

// If all xFloat match 10 get pulse up
if (byte(redFloat) <= 10) {
if (byte(greenFloat) <= 10) {
if (byte(blueFloat) <= 10) {
pulse = 1;
}
}
}
}
// Pulse up
if (pulse == 1) {
if (redFloat < redPulse) {
redFloat = redFloat + redKoff;
}
if (greenFloat < greenPulse) {
greenFloat = greenFloat + greenKoff;
}
if (blueFloat < bluePulse) {
blueFloat = blueFloat + blueKoff;
}
// If all Pwr match Pulse get pulse down

if (byte(redFloat) == redPulse) {
if (byte(greenFloat) == greenPulse) {
if (byte(blueFloat) == bluePulse) {
pulse = 0;
}
}
}
}
/*
// Debug
Serial.print("redFloat: ");
Serial.print(redFloat, DEC);
Serial.print(" redPulse: ");
Serial.print(redPulse, DEC);
Serial.print(" greenFloat: ");
Serial.print(greenFloat, DEC);
Serial.print(" greenPulse: ");
Serial.print(greenPulse, DEC);
Serial.print(" blueFloat: ");
Serial.print(blueFloat, DEC);
Serial.print(" bluePulse: ");
Serial.print(bluePulse, DEC);
Serial.print(" pulse: ");
Serial.println(pulse, DEC);
// End debug
*/
}

if (lightMode == 3) {  // randomsize colorNew and step colorPwr to it
if (redPwr > redNew) {
redPwr--;
}
if (redPwr < redNew) {
redPwr++;
}
if (greenPwr > greenNew) {
greenPwr--;
}
if (greenPwr < greenNew) {
greenPwr++;
}
if (bluePwr > blueNew) {
bluePwr--;
}
if (bluePwr < blueNew) {
bluePwr++;
}

// If all Pwr match New get new colors

if (redPwr == redNew) {
if (greenPwr == greenNew) {
if (bluePwr == blueNew) {
redNew = random(254);
greenNew = random(254);
blueNew = random(254);
}
}
}

// display the colors
analogWrite(ledRed, redPwr);
analogWrite(ledGreen, greenPwr);
analogWrite(ledBlue, bluePwr);
delay(20);
}
}

73 comments:

  1. Great job! I'd like to do something similar, but with sensor data as the input instead of a pot. Possibly a motion detector?

    ReplyDelete
  2. Thanks! It's funny that you mention a motion detector, since that actually was my original plan. Well not motion, rather proximity, but close enough (ooh.. a pun!).
    I would have to change the interface a bit but most things should work as they are with just a minor hardware changes.

    ReplyDelete
  3. Hi, this is awesome, I've been thinking of doing this with the IKEA DIODER (Round version) lamps I have...

    Do you know if this can run all four of them at the same time?

    ReplyDelete
  4. I don't really know what the IKEA DIODER looks like on the inside. But from what I can assume, you should be able to use this as a base to control it. I guess the crucial part is "where" on DIODER you should install it.

    ReplyDelete
  5. I'm thinking of putting it before the splitter.

    But each color is 6 LEDs in 4 lamps, so that adds up to a total of 72 LEDs, potentially all on at the same time.

    So I'm not quite sure if this will be able to handle it.

    Alternatively: What would it take to control each lamp individually?

    ReplyDelete
  6. Well I suppose it comes down to how many amps and volts you can throw at the ULN2003. If I'm not mistaken it's 50V and 500mA. If you don't have the specs of each lamp it should be fairly easy to measure if you are willing to gut the device. I had the specs but did measure the amps @ a certain voltage anyway, just to be sure.
    Individually I probably still would use a ULN2003 since you can control all three colors for each lamp with one chip. The alternative would be three transistors or perhaps some other way I don't know of. Keep in mind this was my first "big" electronics project so I'm not the best source of information on the subject.

    ReplyDelete
  7. Well, you know more than me :P

    But yeah, I'll go ask on the arduino forum when I have the time :)

    ReplyDelete
  8. The good part is, it's not that hard once you get the hang of it. And don't forget to come back and show me the result!

    ReplyDelete
  9. I just stumbled accross this code and i must say that you are a genious, with your code i had a small scale version up and running in 10 minutes and it worked a treat. Thankyou.

    ReplyDelete
  10. Wow, thanks! Don't know about the genius part, but I sure am happy to hear you were successful using my code.
    Happy coding & building!

    ReplyDelete
  11. I finally got around to implementing this.

    It works really nice with the IKEA DIODER.
    There are no problems with running all four lamps at the same time.

    ReplyDelete
  12. I have cleaned the script up a bit.

    Made it delay-less, using some stuff from here: http://arduino.cc/en/Tutorial/BlinkWithoutDelay

    And changed it so the pulse/random speed is controlled by the pot.

    http://dl.dropbox.com/u/615699/RGB_LED_control.txt

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

    ReplyDelete
  14. I have made a version that can be controlled with an IR remote.

    It has some more stuff I couldn't be bothered to backport to my non-IR version.

    http://dl.dropbox.com/u/615699/RGB_LED_control_IR.txt
    Please note that the file is updated whenever I save locally, and may at any time, not work ;-)

    ReplyDelete
  15. Nice work!
    I've been meaning to fix the pulse/speed controller myself but I haven't had any time for any serious coding this winter/fall.

    I've also planned some sort of remote. My original idea was remote control via radio but I realized that would require an extra arduino. What kind of IR controller are you using?

    I haven't checked all your code yet but I'll be sure to do it once I get some free time. That might take some time though since I've got an eight days old daughter now.

    ReplyDelete
  16. I'm using a some generic remote control that came with a TV card, that I don't use anymore.

    (I know it's generic because I have the exact same remote, but with other colours and functions for a VCR.)

    The receiving bit is just an IR sensor.

    ReplyDelete
  17. Sweet, I never thought of that. I have at least one old remote lying around that can be used for this. I guess you just had the reciver plugged in to the computer and looked at the serial output to se what codes the different buttons gave?

    ReplyDelete
  18. I am using this library for IR: http://arcfn.com/2009/08/multi-protocol-infrared-remote-library.html

    The IRrecvDump examples makes it easy to get the codes.

    The IR reciever/demodulator is something like a Vishay TSOP4838 or an OSRAM SFH 5110-38.

    ReplyDelete
  19. Ah, neat! Now I just need to get a IR reciver and some free time ;)

    ReplyDelete
  20. Great work never knew it could be so simple:D I already tried to make a mood/bob light with a pic from the bottom up, no succes but I orderd my arduino and this is one of the first things I'm gonna try on it.

    Btw I will look into combining the boblight code and your code. If i have succes ill post it;)

    ReplyDelete
  21. Thanks!

    Since you mention boblight you should check out Szymons project, it uses boblight and parts of my code.

    You can find it here: http://geekswithblogs.net/kobush/archive/2009/11/27/136572.aspx

    I'm looking forward to see your results.

    ReplyDelete
  22. I have put my sketchfolder on GitHub, so feel free to fork or download from it: http://github.com/DarkFox/Arduino

    The most updated one is RGB_LED_controller_IR

    I have added fading between colors, when changing color and saving the state in the EEPROM.

    ReplyDelete
  23. Hey man ! I was recommended this code by an Arduino guy. What I am trying to do is this.

    This is the intended set-up:
    A non lockable push button = input
    RGB LED Strip = Output
    A flow chart would be as follows.

    Push and Release Button 1 ---> RGB LED Strip lights up instantly AFTER button is pushed to a preset colour (e.g. Liliac) -----> RGB LED Strip fades out to off.

    Push and Release Button 2 ----> LED Strip performs same action but turns Blue

    I am aiming at having 6-8 buttons, each with their own corresponding colour represented by the LED strip.
    And if its possible can I do this?
    Button 3 + 4 pressed = Led Colour Yellow?

    Or could i set it up that no matter what button i press a different colour will appear, even with combination buttons?
    I would like it to appear random.

    Please let me know! I have to get this all done by and working by Tuesday 26th of Jan !

    ReplyDelete
  24. Hi Victor,
    I see no problems in doing what you want to do by using parts of my code. Both your examples seem possible to me. The only thing that might be a problem is the number of inputs on the arduino, but 8 inputs (buttons) and 3 outputs (the -> ULN2003 -> LED strip) shouldn't be a problem.

    I don't really know if that's the answer you wanted but I'm afraid that's all I can give. If you build my circuit and load up my code you should be a bit on your way. From there on just start stripping the parts you need for your project.


    Keep in mind that this was my first "big" project in coding so there's probably a better way to do what I've done.

    Good luck!

    ReplyDelete
  25. Hey Markus! Thanks!

    I ordered the LED Strip today as well as the Transistor you used, I have to incorporate relays as my light needs a higher current.

    Is it possible for 1 button to make the LED make a corresponding colour in a range ?

    For example Button 2 generates a random colour in the blue spectrum ?

    Button 3 a random colour in the Green Spectrum
    Etc.

    The code would mean that if input is detected then out put will can be with in a certain range for that corresponding input!

    Thanks!

    ReplyDelete
  26. As I've said before I'm quite new to electronics so I'm a bit unsure wether or not you can get relays to work in a pulse width modulated circuit. But then again I don't know where you intend to put the relays either.

    On the question wether a button can generate a random color within a specific range, the answer would be yes. You could play with the RGB color mixer in Adobe Photoshop, Illustrator or really any any graphics app, to figure out what values you want to use for your range. Especially with mixed colors like yellow.

    In my code the closest thing would be the lightMode 1, where the potentiometer sets the color. First a reading is taken from the pot, this would equal your pushed button. Then this value is translated into RGB values in the color wheel (the picture).

    Best of luck to you!

    ReplyDelete
  27. Hey,

    Got the light strip!
    But there is no grounding cable on it?
    I have R G B and Yellow (Power)

    How did you ground your Light?

    Im gonna try and set up my light now, have a working button code etc.

    Do you happen to know how to get another funtion to occur while another process is taking place?

    Here is a link to the post on the arduino forum describing what i would like to achive!

    http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1264342929

    Please let me know what you would suggest and how the hell am i supposed to ground the light?!

    ReplyDelete
  28. Hi Victor,
    If I'm not mistaken ground is really the R G and B cable. But test it out first, so put power in your power cable and ground one of the colours, it should light up. This means that in my circuit the ULN2003 is really blocking how much current goes thru to ground and not how much current goes out to the LEDs.

    I looked at your post on the Arduino forum and those who have already answered have pointed you in the right way. There is a piece of example that's called BlinkWithoutDelay (it's under Examples > Digital) it's pretty well documented and should get you started.

    ReplyDelete
  29. Red Switches on and off fine.

    But how do get Green and Blue to turn on and Off along side red producing a colour once fully on?




    const int ledPinR = 9;
    const int ledPinG= 11;
    const int ledPinB = 10;

    const int buttonPin1 = 3;

    int buttonState1 = 0;

    byte redPwr = 0;
    byte greenPwr = 0;
    byte bluePwr = 0;

    void setup()
    {
    pinMode(ledPinR, OUTPUT);
    pinMode(ledPinG, OUTPUT);
    pinMode(ledPinB, OUTPUT);


    pinMode(buttonPin1, INPUT);
    buttonState1 = digitalRead(buttonPin1);

    // serial for debugging purposes only
    Serial.begin(9600);
    }
    void loop()
    {
    buttonState1 = digitalRead(buttonPin1);
    if (buttonState1 == HIGH){
    redPwr = 255;
    bluePwr = 125;
    analogWrite(ledPinR, redPwr);
    greenPwr = 100;
    analogWrite(ledPinG, greenPwr);
    analogWrite(ledPinB, bluePwr);
    }
    else {
    digitalWrite(ledPinR, LOW);
    digitalWrite(ledPinG, HIGH);
    digitalWrite(ledPinB, HIGH);

    }
    }

    ReplyDelete
  30. I don't really know what you are trying to achive with the code you posted but from what I can tell it would:
    Check if the button is pressed down, if it is it would go full power on the red LED, about half on the Blue and a little less on the green. When the button is not pressed or released the red would be turned off completely while both blue and green should light up fully.

    Is this what you want to happen or is it something else?

    ReplyDelete
  31. Good Work!
    I'm looking for a similar setting but i only have to dim white leds. Is it possible to adapt yours. Do i need the ULN2003 too to make it just with whites?

    ReplyDelete
  32. Thanks!
    Yes it would be very possible, but there is alot of code you don't really need.

    The reason I used the ULN2003 is because the Arduino can't handle the current (and voltage) my LED strip required. Also the ULN2003 is really just a convenient package for multiple darlington pairs. I needed one for each color (red, green and blue). If you just want to control a single color LED-strip you could do with a single transistor or mosfet. I shouldn't go further in recommending what you should use since I really don't have that kind of experience, but hopefully it will get you started in the right direction.

    ReplyDelete
  33. Thanks a lot!
    I used the scheme for an art project course on my university. We had to make a lamp inspired by a city. And mine was based on Dubai. The lamp color, materials and form are searching for a right balance just like Dubai (investment problems).

    http://www.facebook.com/album.php?aid=223457&id=717160055&l=1f30d7af15

    ReplyDelete
  34. very nice coding......

    i made a similar program a few months ago... here was my take.. but i spaced them evenly, i may take your suggestion and slide the adjustment out a bit like you illustrated.

    const int fg = 4; // Assign each color for each handle ex: fg = Front Green and rr = Rear Red
    const int fb = 3; // Interior light are tied to front door handles
    const int fr = 2;
    const int rg = 7;
    const int rb = 6;
    const int rr = 5;

    while (digitalRead (intlights) == LOW && digitalRead (alarmIn) == HIGH){ //code for interior lights to change colors selected by 5K pot

    totalValue = 0; //reset variables at beginning of loop
    trueValue = 0;

    for (int i=1; i<=50 ; i++){ //take 50 readings from Analog Input pin
    trueValue = analogRead(colorIn);
    totalValue = trueValue + totalValue;
    sampleTotal = i;
    }

    colorValue = totalValue/sampleTotal; //get average of 50 readings pulled in from loop

    Serial.println(colorValue); // Print average color value to serial port

    intLights (0, 175, 0, rr, 0, fr); // takes a value from the pot (0-1023) and uses that value to change the colors on the led
    intLights (165, 345, rr, rb, fr, fb);
    intLights (335, 515, rb, rg, fb, fg);
    intLights (505, 685, rg, rr, fg, fr);
    intLights (675, 855, 0, rb, 0, fb);
    intLights (845, 1015, 0, rg, 0, fg);

    }

    void intLights (int low, int high, int LEDlower1, int LEDraise1, int LEDlower2, int LEDraise2){ //takes the value from the pot and turns it into led values

    if(colorValue == 0) {
    digitalWrite(rr, LOW);
    digitalWrite(fr, LOW);

    digitalWrite(rg, LOW);
    digitalWrite(fg, LOW);

    digitalWrite(rb, LOW);
    digitalWrite(fb, LOW);
    }

    else if(colorValue >1000){
    digitalWrite(rr, HIGH);
    digitalWrite(fr, HIGH);

    digitalWrite(rg, HIGH);
    digitalWrite(fg, HIGH);

    digitalWrite(rb, HIGH);
    digitalWrite(fb, HIGH);
    }

    else if (colorValue > low && colorValue < high){

    int LED1 = map (colorValue, low, high, 255, 10);
    int LED2 = map (colorValue, low, high, 10, 255);
    int LED3 = map (colorValue, low, high, 255, 10);
    int LED4 = map (colorValue, low, high, 10, 255);

    analogWrite (LEDlower1, LED1);
    analogWrite (LEDraise1, LED2);
    analogWrite (LEDlower2, LED3);
    analogWrite (LEDraise2, LED4);

    }
    }

    ReplyDelete
  35. How did that work for you? Did some colors get extra long twist-lenght on the potentiometer and some very short or did they space out evenly? I mean when you actually have it turned on and twist the pot?

    ReplyDelete
  36. some colors were short. I really didn't realize it until i space it out like your code though. lol. I had no real comparison. I don't adjust very much anyway. usually set it and forget it. Mostly coded it in because i wanted to see if i could.

    ReplyDelete
  37. Well I probably wouldn't have noticed it either if I hadn't used Adobe Illustrator to make a gradient in the firts place. But it's nice to hear that my extra effort weren't unecessary.

    ReplyDelete
  38. i just realized i must have put an older version of the code in here. that's still kind of the 'proof of concept' code. very buggy. I must have opened the wrong file. Once i get back on my pc with the right one on it i'll post up the new rev.

    ReplyDelete
  39. i can use the same configuration whit a vulgar ledstrip rgb?

    ReplyDelete
  40. I'm sorry Nico but I'm not familiar with the ledstrip you mention. Give me a link to the specs and see if I can give you a better answer.

    ReplyDelete
  41. Hi,
    This looks pretty cool and I can't wait to try it. One quick question, what power source are you using the 12V DC to power the RGB strip?
    Cheers!

    ReplyDelete
  42. Hi mrbook!

    I'm using a AC/DC transformer with variable output. It's the same size as an ordinary laptop power-brick.

    I guess you can buy it in most tech/hardware stores.

    ReplyDelete
  43. Hi Markus,

    I hope to receive my LED strip soon. (RGB 1-Meter 30-LED 6W Light Strip (DC 12V))

    Can you tell me if the resistors are built-in already and do you have to connect additional ones when you shorten the strip to e.g. 50cm?

    And isn't the IC getting hot when you run it at 12V 6W?

    Many thanks!

    ReplyDelete
  44. Hi Marteen,

    I'm afraid I don't have any facts to share on those points. Regarding built in resistors I wouldn't want to say anything til I took a look at the strip itself. But if memory serves me right I've seen people use slices of LED-strip all over the place without any additional resistors. However if they were still running at 12V is a another good question.

    I do remember getting a hot IC but if that was from this project or another I can't really say. I don't think it ever got hot and from what I've read whats been fed throught the IC is within its limits.

    But please do go over your calculations one last time before you plug anything in!

    Best of luck with your project!

    ReplyDelete
  45. Hi Markus,

    Thanks for you reply! I received the strip and, if I'm correct, it has 1 resistor per color per set of three LEDs. I think these sets of three LEDs are all in parallel which would mean you can split them without problem.

    Time to do some testing!
    Cheers,
    Maarten

    ReplyDelete
  46. That sounds about right, good luck! Be sure to post a link to your project here in the comments if you put it somewhere.

    ReplyDelete
  47. I am new to this.. What would the code be to use just the potentiometer?

    ReplyDelete
  48. Hello Anonymous,
    I think you'll have to be a bit more specific. Do you just want the Arduino to read a value from the potentiometer?

    ReplyDelete
  49. Yes. I don't have a switch so I just want to control the lights with the potentiometer. I am new to this but a little tinkering and I figured it out.

    ReplyDelete
  50. thanks by the way..

    ReplyDelete
  51. Great! Good luck with whatever project you're doing. If you're blogging about it I'd really like a link to it here in the comments.

    ReplyDelete
  52. It's anonymous from before. Me and my brother are working on a LED table. There will be a blog or an instructable as some point. I will keep you posted. Once again I am pretty new to this. I have only had my arduino and RGB lights for a couple of weeks. I have been able to figure out all kinds of cool things in pretty short amount of time.

    I got the code modified to just control the lights with the pot. Then to futher my understanding a little more I actually modified it to control 2 RGB strips with 2 different pots.

    I went and bought a 9mm tact switch from radio shack that is rated a 12DCV, and 50mA.
    I am having trouble wiring it up tho.
    I am powering my arduino with a 12V wall wart and accessing this power from the vin pin on the arduino. The way I wired it initially was to hook one side of the switch to the vin pin, and then on the other side of the switch one pin was hooked the 10K ohm resistor which went to the pot. And the other pin went to a 100 ohm resistor wired to pin 2.

    end result the switch and pot are not functioning. And the lights only cycle blue to violet when I remove the side of the switch I plugged to the 100 ohm resistor.

    Can you explain to me how the switch,pot and resistors are suppose to be wired? I can't seem to figure it out. Any help would be greatly appreciated.

    ReplyDelete
  53. Hi Scott,
    Nice to hear from you again. I'll see if I can do my best to answer your questions.
    1. The tact switch, here's an excellent tutorial on switches (and lot's of other useful things): http://www.ladyada.net/learn/arduino/lesson5.html
    But you also need to tell me what you want the switch to do, otherwise it's hard for me to tell you how to wire it up.
    2. If you look at my wiring diagram I use the wall brick to power circuit with the LED strip and the ULN separately. The important thing here is that the wall brick power does not run through the Arduino to the LED strip. Why this is important I can't remember but someone at the Arduino forum told me so I'm running with it. However I am using powering my Arduino from the wall brick, I'm just tapping that power with two other wires in parallell with those that enter the circuit. One more thing, make sure you have a common ground otherwise all kinds of wierd things will happen.

    Hope this helps, if not ask again.

    ReplyDelete
  54. I am just trying to replicate what you have. Thanks for the link I am actually already in the process of going through that tutorial. Very useful site.
    So you have your 12v plugged directly in to the bus strip on your bread board. then a wire running from that to the 5v pin of the arduino and one to the 12v of the lights? Am I understanding that correctly?

    ReplyDelete
  55. Indeed Ladyada's site is loaded with useful information for beginners.

    You're right up until that I don't feed 12V into the 5V pin of the Arduino. Instead I stick it to the "Vin" pin. You could use the power connector on the Arduino aswell but then you would need something to plug into the hole.


    BTW I have the Arduino Duemilanove, so check if you have the same specs before connecting anything i.e if your Arduino can handle up to 12V in.

    ReplyDelete
  56. Thank you for you quick replies. I am sure these questions probably seem dumb.
    sorry I didn't make my self clear earlier. I am using the power connector on the arduino. I was plugging a old 12 volt dc wall plugging with a 2.1mm barrel jack to power the arduino, and then using a jumper wire from the vin pin to the + bus strip on the bread board and obviously using a jumper to connect the grd pin to - bus strip.
    I am getting the hang of the switch by following the tutorial and with a little more tinkering should be able to figure this out.

    ReplyDelete
  57. I got it all up and working. One more question those. My dark blue and violet flicker when using the potentiometer. Any ideas as to why this might be?

    ReplyDelete
  58. Just one thing! Since the led strip might draw alot of current it might, I'm not saying it will, you will have to read the Arduino specs, be smart to not let the led strip tap its power from the arduino but from the wall plug first. I think it's easiest to explain like this:
    Led strip
    Wallplug 12VDC --- Breadboard --<
    Arduino

    Not shown here is of course a common ground.
    Am I making sense?

    ReplyDelete
  59. Not having a common ground could cause flickering I suppose. But you could try to debug it by changeing the code to use dark blue/violet for the whole range of the potentiometer.

    ReplyDelete
  60. Nice job, made one myself, thanks for schematic.

    ReplyDelete
  61. Hi there, and thank you for posting such an informative post/tutorial.

    I am trying to replicate the electronics side of this (without the potentiometer part, I will control color programatically) for use with the expansion header on a beagleboard xM. (1.8V signaling, 30mA max current). The beagleboard is already powered, so I don't need to worry about that. In my case, would I just eliminate the entire bottom part of the circuit except for connecting the uln2003 to ground?

    Thanks for your help, the old electronics knowledge is a little rusty.

    ReplyDelete
  62. Hi there trickyoho!
    You're welcome. It's fun to see that people still drop in and want to ask questions about this. I'll try to help you as much as possible.

    To answer your question, I have no idea what a beagleboard is but I don't think I have to, to be able to say: Yes, but if things don't work, it could be that you everything needs a common ground.

    I honestly can't remember if a common ground is a good or bad idea when plugged in to a computer. But I think it is. Just don't blame me if things blow up, in other words ask someone who do know, before you do that.

    ReplyDelete
  63. Hi,
    From the schema I mthink Your using a common anode Led Strip, to turn that of, I need to set R=255,G=255,B=255 something to do with pulling the current. Can Yoy comment on that, because obiovously for You it worked.
    efbe

    ReplyDelete
  64. Hi efbe,
    Seems like something is reversed in your circuit. I suggest you find out how your LED-strip works without a microcontroller. I.e hook it up to a powersource and use three potentiometers to control it. This should give you a clue on how it works and if it is infact a common anode and not a common cathode strip.

    ReplyDelete
  65. Hi Markus,

    nice work, just looking for something similar.

    I am wondering how to power/drive a strip of 3 meters (or more). Can i still use the ULN2003 for this or do i have to use three ULN2003s, one for each meter? and is one 12V power supply with ~2A suitable for powering all 3 strips together? thanks in advance!

    ReplyDelete
  66. Hi Hannes,

    Thank you, hope you found the inspiration or code you can use. Regarding the power questions I'd feel more comfortable if you asked that question in say the Arduino forum at http://forum.arduino.cc/ the folks there have more experience with those kinds of questions and usually pretty quick to help.

    ReplyDelete
  67. Hello. We are trying to do this using an Arduino Uno. We do not have ULN2003 is there anyway we can do this without? We have transistors so could you help us with the schematic of this?

    thank you

    ReplyDelete
    Replies
    1. Depends on what you want to light up so to speak. If it's just a single RGB led you don't even need transistors just a couple of resistors between the arduino pins an the cathodes/anodes. Otherwise it's pretty much up to how much current your transistor can handle. A ULN chip is a darlington array and a darlington is basically just a transistor that can handle more current (it's really two transitors in series).

      I'm no expert on electronics but you should be able to use pretty much all of my circuit and adapt it to use three suitable transistors. I do believe you need to have them all (and the Arduino) connected to the same ground.

      Let me know if that works for you if not I'll try to help you some more.

      Delete
  68. Hey Markus. Great Post! I've been looking for this for a long time!!

    Is there any way you could post an Arduino schematic? (with the wiring, pots, etc shown). I'm just getting into this after a few months of getting up the bravery to buy the stuff and I'm not too great at wiring diagrams. I have the components (breadboard, wiring, etc etc. Just need something pretty and neat showing how to connect it all.

    Once again thank you and keep up the fantastic work!!

    ReplyDelete
    Replies
    1. Thanks for the kind words Roy. Unfortunately I don't think I will be doing a new wiring diagram for this anytime soon, I simply don't have the time for that at the moment. But do take a look a the diagram at the top of the post. Once you've connected the obvious parts it shouldn't be too hard to figure out the rest.

      Delete
    2. I'll do my best and if I have the time,after figuring it out, to diagram it , Ill share it with you so others can use it as well! Thanks!

      Delete
    3. Sounds great, and don't hesitate to ask me questions if you are unsure on how to read my sketch.

      Delete