LED-RGB-stripe remote control via arduino?

Hi there,

I am complety new to arduino, got my starter kit yesterday. First examples with LEDs and the Arduino-IDE run wonderful, great thing! I have some eletronics and programming background.

My idea: I already have some LED-RGB-Stripes with the infrared-remote-controller. E.g. http://www.lumenedge.com/store/images/uploads/rgb_controller_b.jpg This works fine manually, but I want to automate day and night lights for my modellrailroad. E.g. it should be blue in the night for 5 minutes, then fade slowly to daylight, stay there for 5 minutes and fade back to the night then. Loop.

I found some infos about using arduino and rgb-stripes directly with mosfets and I found an infrared-library (https://github.com/shirriff/Arduino-IRremote).

But I did not find any arduino project which emulates/replaces the remote control itself. I thought about putting an IR-LED onto ardunio and then write some software using standard-IR-commands. :)

My question: Has anyone done this before? Whats the best way to start such a project?

Thanks in advance, Sven

Yes it should be easy enough to do with Arduino.

Just get an IR receiver (to decode the existing remote signals) and an IR LED for sending an IR signal ( with maybe a transistor & a couple of resistors if you want good range).

Then you just use the IRremote library as per the link in your post.

There should be several examples of this type of project on this forum (via search box) and there is another great site 'sb projects' ( via google).

BTW: you could just use the Arduino to send the IR signals to the LED strip. There would be no need to drive the LED strip from the Arduino. (unless you have plans, for more complex lighting sequences & presuming the LED stips already have an IR controlled driver)

Awesome tutorial here to control RGB strip lights via android device. http://makezine.com/projects/android-arduino-led-strip-lights/

you can try this tutorial also if you did like to make a mood lamp with rgb leds. http://embeddedsystem1.blogspot.in/search/label/RGB%20LED

thanks all!

I found out that my remote can only switch between 15 colors and some more (brightness, white and some fancy flash/strobe).

I will try the direct approach and already ordered some transistors to connect to the rgb-stripe.

Will write here again then.

sven

If you are brave, you might be able to hack or tap into the existing LED driver circuit using an arduino to replace the 'hardwired' lighting sequences. Might be easier with an Oscillosope or Logic Analyzer.

I finally have a prototyp running. Yippie!

The code is based on the source-code from http://www.arduino.cc/en/Tutorial/ColorCrossfader - I modified only the color array and the order of colorfading in the main loop. Thanks!

Background info for colors came from Arduino LocoNet Light Control – Digital Modellbahn. Thanks!

You can see the Arduino and the RGB-LEDs in the mirror - left corner below.

Using it for some days made me think, that the white light from my RBGs is too “cold”, so I will add a warmwhite led-stripe soon to have a nicer daylight.

http://www.youtube.com/watch?v=81mcno7Cc9Y.

Not bad for a prototype!

Also, an interesting concept of 'using light to simulate darkness'.

Thanks for sharing the video.

after all I forgot to post my latest source code, thanks for reminding :slight_smile:

here it is / have fun

/* 
  Datei v0.3 MoBa RGB-light simulation / seveny
  based on Arduino-Code http://www.arduino.cc/en/Tutorial/ColorCrossfader
  based on Infos from http://pgahtow.de/wiki/index.php?title=Arduino_LocoNet_Light_Control
*/
// Output
int wWPin = 6;   // warmwhite LED,   connected to digital pin 6
int redPin = 9;   // Red LED,   connected to digital pin 9
int grnPin = 10;  // Green LED, connected to digital pin 10
int bluPin = 11;  // Blue LED,  connected to digital pin 11

// Color arrays
int black[3]  = { 0, 0, 0 };
int white[3]  = { 30, 30, 30 };
int red[3]    = { 100, 0, 50 };
int blue[3]   = { 0, 0, 100 };
int green[3]   = { 0, 100, 100 };

// Set initial color
int redVal = black[0];
int grnVal = black[1]; 
int bluVal = black[2];

int wait = 10;      // 10ms internal crossFade delay; increase for slower fades
int hold = 0;       // Optional hold when a color is complete, before the next crossFade
int DEBUG = 1;      // DEBUG counter; if set to 1, will write values back via serial
int loopCount = 60; // How often should DEBUG report?
int repeat = 0;     // How many times should we loop before stopping? (0 for no stop)
int j = 0;          // Loop counter for repeat
int daynightdelay = 5000;  // Time between change of day an night in ms

// Initialize color variables
int prevR = redVal;
int prevG = grnVal;
int prevB = bluVal;

// Set up the LED outputs
void setup()
{
  pinMode(redPin, OUTPUT);   // sets the pins as output
  pinMode(grnPin, OUTPUT);   
  pinMode(bluPin, OUTPUT); 
  pinMode(wWPin, OUTPUT); 
  
  if (DEBUG) {           // If we want to see values for debugging...
    Serial.begin(9600);  // ...set up the serial ouput 
    Serial.println("MoBa RGB-light simulation v0.3 ---- seveny");
  }
}

// Main program: list the order of crossfades
void loop()
{
  Serial.println("START: warmwhite in progress");
  
  analogWrite(wWPin, 255);   // Write current values to LED pins
  
  Serial.println("color in progress: white");
  crossFade(white);
  Serial.println("color in progress: red");
  crossFade(red);
  
  Serial.println("warmwhite fade out");

  for (int i = 255; i >= 0; i--) { 
    analogWrite(wWPin, i);   // Write current values to LED pins
    delay(50); // Pause for 'wait' milliseconds before resuming the loop
  }
    Serial.println("color in progress: blue");
  crossFade(blue);
  Serial.println("wait then sunrise");
  delay(daynightdelay);
  

  Serial.println("color in progress: red");
  crossFade(red);

   Serial.println("warmwhite fade in");
   for (int i = 0; i <= 255; i++) { 
    analogWrite(wWPin, i);   // Write current values to LED pins
    delay(50); // Pause for 'wait' milliseconds before resuming the loop
  }
  
  Serial.println("color in progress: white");
  crossFade(white);

  Serial.println("wait then sunset");
  delay(daynightdelay);
}

/* BELOW THIS LINE IS THE MATH -- YOU SHOULDN'T NEED TO CHANGE THIS FOR THE BASICS
* 
* The program works like this:
* Imagine a crossfade that moves the red LED from 0-10, 
*   the green from 0-5, and the blue from 10 to 7, in
*   ten steps.
*   We'd want to count the 10 steps and increase or 
*   decrease color values in evenly stepped increments.
*   Imagine a + indicates raising a value by 1, and a -
*   equals lowering it. Our 10 step fade would look like:
* 
*   1 2 3 4 5 6 7 8 9 10
* R + + + + + + + + + +
* G   +   +   +   +   +
* B     -     -     -
* 
* The red rises from 0 to 10 in ten steps, the green from 
* 0-5 in 5 steps, and the blue falls from 10 to 7 in three steps.
* 
* In the real program, the color percentages are converted to 
* 0-255 values, and there are 1020 steps (255*4).
* 
* To figure out how big a step there should be between one up- or
* down-tick of one of the LED values, we call calculateStep(), 
* which calculates the absolute gap between the start and end values, 
* and then divides that gap by 1020 to determine the size of the step  
* between adjustments in the value.
*/

int calculateStep(int prevValue, int endValue) {
  int step = endValue - prevValue; // What's the overall gap?
  if (step) {                      // If its non-zero, 
    step = 1020/step;              //   divide by 1020
  } 
  return step;
}

/* The next function is calculateVal. When the loop value, i,
*  reaches the step size appropriate for one of the
*  colors, it increases or decreases the value of that color by 1. 
*  (R, G, and B are each calculated separately.)
*/

int calculateVal(int step, int val, int i) {

  if ((step) && i % step == 0) { // If step is non-zero and its time to change a value,
    if (step > 0) {              //   increment the value if step is positive...
      val += 1;           
    } 
    else if (step < 0) {         //   ...or decrement it if step is negative
      val -= 1;
    } 
  }
  // Defensive driving: make sure val stays in the range 0-255
  if (val > 255) {
    val = 255;
  } 
  else if (val < 0) {
    val = 0;
  }
  return val;
}

/* crossFade() converts the percentage colors to a 
*  0-255 range, then loops 1020 times, checking to see if  
*  the value needs to be updated each time, then writing
*  the color values to the correct pins.
*/

void crossFade(int color[3]) {
  // Convert to 0-255
  int R = (color[0] * 255) / 100;
  int G = (color[1] * 255) / 100;
  int B = (color[2] * 255) / 100;

  int stepR = calculateStep(prevR, R);
  int stepG = calculateStep(prevG, G); 
  int stepB = calculateStep(prevB, B);

  for (int i = 0; i <= 1020; i++) {
    redVal = calculateVal(stepR, redVal, i);
    grnVal = calculateVal(stepG, grnVal, i);
    bluVal = calculateVal(stepB, bluVal, i);

    analogWrite(redPin, redVal);   // Write current values to LED pins
    analogWrite(grnPin, grnVal);      
    analogWrite(bluPin, bluVal); 

    delay(wait); // Pause for 'wait' milliseconds before resuming the loop

/*    if (DEBUG) { // If we want serial output, print it at the 
      if (i == 0 or i % loopCount == 0) { // beginning, and every loopCount times
        Serial.print("Loop/RGB: #");
        Serial.print(i);
        Serial.print(" | ");
        Serial.print(redVal);
        Serial.print(" / ");
        Serial.print(grnVal);
        Serial.print(" / ");  
        Serial.println(bluVal); 
      } 
      DEBUG += 1;
    }*/
  }
  // Update current values for next loop
  prevR = redVal; 
  prevG = grnVal; 
  prevB = bluVal;
  delay(hold); // Pause for optional 'wait' milliseconds before resuming the loop
}

thanks for posting the code!