Remote Controlled Arduino RGB LED lit Waterfall-Coding help?

Hello,

I've posted about this project before but had to take time to scale back the complexity of the project as this is my first arduino project/rodeo.

I decided to go with IR instead of voice activation because my Veear voice recognition board was giving me problems and I decided reluctantly that I was in WAY over my head.

I have an arduino UNO that I'm trying to remotely control a relay (Powerswitch Tail II (which will be connected to a water pump)), as well as a 5m string of RGB LED's.

This is a list of everything that I am using (or at least trying to use):
-Arduino UNO R3
-Breadboard
-Grove Base Shield
-Grove LED Strip Driver
-5m RGB LED strip
-12v power supply for LED's
-PowerSwitch Tail II
-IR sensor
-24 multi-color-button remote (bought offline with an LED screw in bulb which works on its own very well making me very upset :grin:)

If you look at the picture of the remote control which I've attached you can see the layout.

End goal is to be able to:
-press "ON" and have the relay switch on power to the water pump.
-press any of the color buttons and have the LED's switch to that color (preferably fade but from reading here that is an absolute nightmare so a hard color change will have to do)
-press "OFF" and have everything turn off.
-it would also be nice if I could figure out a way to press "FADE" and have a random color display but I'm well aware that beggars can't be choosers.

I found a code for a remote controlled RGB LED here: Arduino RGB led managed by remote control other than it being in another language, it's what I think I've been looking for. I changed the button coding for my remote (which was basically the same except for one or two buttons.

The way I have it all hooked up now, I have the Grove Base shield attached and the universal 4 pin cable connected to the LED driver. I don't know if there is a special library that I have to include for the base shield bc the sample code on the base shield's wiki page is "Demo code ()" which isn't entirely helpful. The LED strip will turn on but they won't change color. I opened up the serial monitor and the arduino is receiving the IR signal and the monitor puts out what looks to be the correct RGB values but the LED's won't change color.

The relay will turn off when I press "ON" which is the opposite of the desired button push.

Basically I've been working on this project for a year and a half and I feel like I've improved my arduino knowledge by leaps and bounds but I've got to a point where I need to reach out for help again as I'm not finding the answers I need already in the forums and my girlfriend is getting PO'd because I've had the baseboard ripped off of the walls in the foyer for the entire time :D.

Any help will be GREATLY appreciated!

Here's my code (be gentle...I know I've probably slaughtered it)

#include <IRremote.h>
#include <IRremoteInt.h>

/*
*  Control remoto de LED RGB 
*  Ejemplo de como hacer variar el color y el brillo con un led RGB  
*  con un mando a distancia.
*  Se utiliza un receptor de infrarrojos del tipo TSOP1738 
*  Autor: Jose Daniel Herrera
*  Fecha: 28/08/2012
*  http://arduino-guay.blogspot.com.es
*/
 

 
int RECV_PIN = 3;
int R_PIN = 9;
int G_PIN = 11;
int B_PIN = 10;
int RELAY_PIN = 7;
 
#define ON                0XFFE01F
#define OFF               0xFF609F
#define BRIGHTNESS_UP     0xFFA05F
#define BRIGHTNESS_DOWN   0xFF20DF
#define FLASH             0xFFF00F
#define STROBE            0xFFE817
#define FADE              0xFFD827
#define SMOOTH            0xFFC837
 
#define RED               0xFF906F
#define GREEN             0XFF10EF
#define BLUE              0xFF50AF
#define WHITE             0xFFD02F
 
#define ORANGE            0xFFB04F
#define YELLOW_DARK       0xFFA857
#define YELLOW_MEDIUM     0xFF9867
#define YELLOW_LIGHT      0xFF8877
 
#define GREEN_LIGHT       0XFF30CF
#define GREEN_BLUE1       0XFF28D7
#define GREEN_BLUE2       0XFF18E7
#define GREEN_BLUE3       0XFF08F7
 
#define BLUE_RED          0XFF708F
#define PURPLE_DARK       0XFF6897
#define PURPLE_LIGHT      0XFF58A7
#define PINK              0XFF48B7
 
#define INCREMENTO 10
 
unsigned long rgb = 0;
byte r,g,b;
 
IRrecv irrecv(RECV_PIN);
 
decode_results results;
 
 
void setup()
{
  irrecv.enableIRIn(); // Inicializamos el receptor
  Serial.begin(9600);
  pinMode(R_PIN, OUTPUT);   
  pinMode(G_PIN, OUTPUT);   
  pinMode(B_PIN, OUTPUT);
  pinMode(RELAY_PIN, OUTPUT);  
}
 
 
void variar (byte* color, char valor) {
    if (valor > 0) {
        if ( *color + valor <= 255) {
            *color += valor;
        } else {
            *color = 255;
        }
    } else { 
        if (*color + valor >= 0) {
            *color += valor;
        } else {
            *color = 0;
        }
  }
}
 
void RGB(unsigned long valor) {
   r = valor >> 16; 
   g = (valor >> 8) & 0xFF; 
   b = valor & 0xFF; 
}
 
void loop() {
  if (irrecv.decode(&results)) {
    if ( results.value != 0xFFFFFFFF) {
      switch (results.value) {
           case BRIGHTNESS_UP : 
               variar (&r, INCREMENTO);
               variar (&g, INCREMENTO);
               variar (&b, INCREMENTO);
               break; 
           case BRIGHTNESS_DOWN : 
               variar (&r, -INCREMENTO);
               variar (&g, -INCREMENTO);
               variar (&b, -INCREMENTO);
               break; 
           case OFF : digitalWrite: r,0 ; g,0 ; b,0 ; 7, LOW
           ;
               break;    
           case RED           : RGB(0x00FF0000); break;
           case GREEN         : RGB(0x0000FF00); break;
           case BLUE          : RGB(0x000000FF); break;
           case WHITE         : RGB(0x00FFFFFF); break;
           case ORANGE        : RGB(0x00FF7F00); break;
           case YELLOW_DARK   : RGB(0x00FFAA00); break;
           case YELLOW_MEDIUM : RGB(0x00FFD400); break;
           case YELLOW_LIGHT  : RGB(0x00FFFF00); break;
           case GREEN_LIGHT   : RGB(0x0000FFAA); break;
           case GREEN_BLUE1   : RGB(0x0000FFFF); break;
           case GREEN_BLUE2   : RGB(0x0000AAFF); break;
           case GREEN_BLUE3   : RGB(0x000055FF); break;
           case BLUE_RED      : RGB(0x00000080); break;
           case PURPLE_DARK   : RGB(0x003F0080); break;
           case PURPLE_LIGHT  : RGB(0x007A00BF); break;
           case PINK          : RGB(0x00FF00FF); break;
           case ON            : digitalWrite (7, HIGH);
         }
      Serial.println(results.value, HEX);
      Serial.println(r,DEC);
      Serial.println(g, DEC);
      Serial.println(b, DEC);
      analogWrite(R_PIN,r);
      analogWrite(G_PIN,g);
      analogWrite(B_PIN,b);
    }
    irrecv.resume(); // Receive the next value
  }
}

Remote Control.jpg

This should do the cross-fading. The trick is to keep track of the current color (CurrentR,CurrentG,CurrentB) and the destination of the fade (NextR, NextG, NextB). Then, using the BlinkWithoutDelay trick, move one step toward the destination color every 25 milliseconds. If the fade is too fast or too slow, adjust FadeInterval.

The relay might be 'active low' so you need to set the output pin LOW to turn it on and HIGH to turn it off.

#include <IRremote.h>
#include <IRremoteInt.h>

/*
*  Control remoto de LED RGB 
 *  Ejemplo de como hacer variar el color y el brillo con un led RGB  
 *  con un mando a distancia.
 *  Se utiliza un receptor de infrarrojos del tipo TSOP1738 
 *  Autor: Jose Daniel Herrera
 *  Fecha: 28/08/2012
 *  http://arduino-guay.blogspot.com.es
 */

const unsigned long FadeInterval = 25;

const int RECV_PIN = 3;
const int R_PIN = 9;
const int G_PIN = 11;
const int B_PIN = 10;
const int RELAY_PIN = 7;

#define ON                0XFFE01F
#define OFF               0xFF609F
#define BRIGHTNESS_UP     0xFFA05F
#define BRIGHTNESS_DOWN   0xFF20DF
#define FLASH             0xFFF00F
#define STROBE            0xFFE817
#define FADE              0xFFD827
#define SMOOTH            0xFFC837

#define RED               0xFF906F
#define GREEN             0XFF10EF
#define BLUE              0xFF50AF
#define WHITE             0xFFD02F

#define ORANGE            0xFFB04F
#define YELLOW_DARK       0xFFA857
#define YELLOW_MEDIUM     0xFF9867
#define YELLOW_LIGHT      0xFF8877

#define GREEN_LIGHT       0XFF30CF
#define GREEN_BLUE1       0XFF28D7
#define GREEN_BLUE2       0XFF18E7
#define GREEN_BLUE3       0XFF08F7

#define BLUE_RED          0XFF708F
#define PURPLE_DARK       0XFF6897
#define PURPLE_LIGHT      0XFF58A7
#define PINK              0XFF48B7

#define INCREMENTO 10

unsigned long rgb = 0;
byte CurrentR,CurrentG,CurrentB;
byte NextR, NextG, NextB;

IRrecv irrecv(RECV_PIN);

decode_results results;


void setup()
{
  irrecv.enableIRIn(); // Inicializamos el receptor
  Serial.begin(9600);

  // Start wit everything off
  CurrentR = NextR = 0;
  digitalWrite(R_PIN, LOW);
  pinMode(R_PIN, OUTPUT);   
  CurrentG = NextG = 0;
  digitalWrite(G_PIN, LOW);
  pinMode(G_PIN, OUTPUT);   
  CurrentB = NextB = 0;
  digitalWrite(B_PIN, LOW);
  pinMode(B_PIN, OUTPUT);
  digitalWrite(RELAY_PIN, LOW);
  pinMode(RELAY_PIN, OUTPUT);  
}


void variar (byte* color, int valor) {
  if (valor > 0) {
    if ( *color + valor <= 255) {
      *color += valor;
    } 
    else {
      *color = 255;
    }
  } 
  else { 
    if (*color + valor >= 0) {
      *color += valor;
    } 
    else {
      *color = 0;
    }
  }
}

void RGB(unsigned long valor) {
  NextR = valor >> 16; 
  NextG = (valor >> 8) & 0xFF; 
  NextB = valor & 0xFF; 
}


void loop() {
  static unsigned long lastFadeTime = 0;
  if (millis() - lastFadeTime > FadeInterval)
  {
    lastFadeTime = millis();
    if (NextR > CurrentR)
      CurrentR++;
    if (NextR < CurrentR)
      CurrentR--;
    if (NextG > CurrentG)
      CurrentG++;
    if (NextG < CurrentG)
      CurrentG--;
    if (NextB > CurrentB)
      CurrentB++;
    if (NextB < CurrentB)
      CurrentB--;
    analogWrite(R_PIN,CurrentR);
    analogWrite(G_PIN,CurrentG);
    analogWrite(B_PIN,CurrentB);
  }

  if (irrecv.decode(&results)) {
    if ( results.value != 0xFFFFFFFF) {
      switch (results.value) {
      case BRIGHTNESS_UP : 
        variar (&NextR, INCREMENTO);
        variar (&NextG, INCREMENTO);
        variar (&NextB, INCREMENTO);
        break; 
      case BRIGHTNESS_DOWN : 
        variar (&NextR, -INCREMENTO);
        variar (&NextG, -INCREMENTO);
        variar (&NextB, -INCREMENTO);
        break; 
      case ON: 
        digitalWrite (RELAY_PIN, LOW);
        break;
      case OFF: 
        digitalWrite( RELAY_PIN, HIGH);
        break;    
      case RED           : 
        RGB(0x00FF0000); 
        break;
      case GREEN         : 
        RGB(0x0000FF00); 
        break;
      case BLUE          : 
        RGB(0x000000FF); 
        break;
      case WHITE         : 
        RGB(0x00FFFFFF); 
        break;
      case ORANGE        : 
        RGB(0x00FF7F00); 
        break;
      case YELLOW_DARK   : 
        RGB(0x00FFAA00); 
        break;
      case YELLOW_MEDIUM : 
        RGB(0x00FFD400); 
        break;
      case YELLOW_LIGHT  : 
        RGB(0x00FFFF00); 
        break;
      case GREEN_LIGHT   : 
        RGB(0x0000FFAA); 
        break;
      case GREEN_BLUE1   : 
        RGB(0x0000FFFF); 
        break;
      case GREEN_BLUE2   : 
        RGB(0x0000AAFF); 
        break;
      case GREEN_BLUE3   : 
        RGB(0x000055FF); 
        break;
      case BLUE_RED      : 
        RGB(0x00000080); 
        break;
      case PURPLE_DARK   : 
        RGB(0x003F0080); 
        break;
      case PURPLE_LIGHT  : 
        RGB(0x007A00BF); 
        break;
      case PINK          : 
        RGB(0x00FF00FF); 
        break;
      }
      Serial.println(results.value, HEX);
      Serial.print(" ");
      Serial.print(NextR,DEC);
      Serial.print(" ");
      Serial.print(NextG, DEC);
      Serial.print(" ");
      Serial.println(NextB, DEC);

    }
    irrecv.resume(); // Receive the next value
  }
}

John,

Thank you so much. That code looks great! Thank you again.

The relay works perfectly with the remote now.

I'm still having trouble with the LEDs. I know I just have them hooked up wrong. I've been looking for the proper schematics online for the last couple of hours (and all of last night) but I haven't been able to figure it out. I don't know if the Seeed LED driver (http://www.seeedstudio.com/depot/grove-led-strip-driver-p-1197.html) is the way to go. Everything that talks about it online says that it outputs PWM so it should work. It's got these universal 4 pin connectors with "Signal 1", "Signal 2", "VCC", and "Ground". I've got the LED string connected to the LED driver. I bought both the Grove Base shield and a Grove "screw terminal" so that I could try both (surely I'd be able to get one of them to work) and either way I have it connected to the arduino, the LED rope just lights up at a random time as either light purple or white and won't respond to the remote at all.

I'd try to skip the driver altogether and wire it straight to the arduino but I don't know how I'd power the LED string without it.

Have you, or anyone else out in the forums, had any experience with Grove products?

Thank you all very much for looking!

Did you read the two documents "Preface - Getting Started" and "Introduction to Grove" on that seeedstudio page?

Absolutely I did...countless times.

The "Preface-Getting Started" is just a loose intro to Arduino in general and the "Introduction to Grove" says to copy the "Demo code" from the wiki page but the Demo code is:

Demo code
{
}

....and that's it.

I was hoping that I had just missed something in those documents.

I'm going to try and email Grove to, if nothing else, let them know that there isn't anything on their wiki page as far as the demo code goes.

I took the lights off of the LED Driver and took the Grove shield off of the UNO and just wired the LED string directly to my breadboard using some MOSFETs and it works perfectly. I plugged the 12v into the arduino and it started to get warm. The 9v power supply seems to work just fine but I don't know if that will be sufficient for extended use.

I emailed Seeedstudio to see if they could help me with the Grove Base shield code. I'd rather have the 12v powering the LED string just bc I know that's what the LED's are supposed to have.

Remote works great at 60 feet too. I'm impressed.

Thank you very much for your help with that code. This is the most progress I've had in almost two years on this thing. Now I have to get back to fiberglassing the basin for the waterfall....ugggghhhh.

PS...How might I go about having a random rainbow effect tied to one of the buttons. I don't suppose it would be as simple as "CASE FADE" digtalWrite( Random colors fade in and out NOW!)......JK.

Thank you again John. HUGE help!

John,

I got the example code for the base shield and the LED driver that I have. I wanted to ask if you might have an idea as to how I could incorporate it into the current sketch that you pulled me out of the weeds on. I haven't seen anything like it before and thought you might be able to make sense of it. I tried to insert the new definitions into the current sketch and change the code to what I thought made sense (ex.

  case RED           : 
       Driver.begin() ;
       Driver.SetColor(255, 0, 0) ; 
        break;

)

I also changed it to use HEX RGB values but that didn't seem to work either. I also took out the current RGB pin definitions but then I just got a HUGE error when I went to verify the code.

When I run the example code by itself the LED strip runs fine...just when I try to run the IR code it doesn't want to cooperate.

Here is the example code that just quickly changes the the LED to R->G->B->....:

#include "RGBdriver.h"
#define CLK 2//pins definitions for the driver        
#define DIO 3
RGBdriver Driver(CLK,DIO);
void setup()  
{ 

}  
void loop()  
{ 
  Driver.begin(); // begin
  Driver.SetColor(255, 0, 0); //Red. first node data
  Driver.end();
  delay(500);
  Driver.begin(); // begin
  Driver.SetColor(0, 255, 0); //Green. first node data
  Driver.end();
  delay(500);
  Driver.begin(); // begin
  Driver.SetColor(0, 0, 255);//Blue. first node data
  Driver.end();
  delay(500);

And here again is the code that you originally helped me with:

#include <RGBdriver.h>
#include <IRremote.h>
#include <IRremoteInt.h>

/*
*  Control remoto de LED RGB 
 *  Ejemplo de como hacer variar el color y el brillo con un led RGB  
 *  con un mando a distancia.
 *  Se utiliza un receptor de infrarrojos del tipo TSOP1738 
 *  Autor: Jose Daniel Herrera
 *  Fecha: 28/08/2012
 *  http://arduino-guay.blogspot.com.es
 */

const unsigned long FadeInterval = 25;

const int RECV_PIN = 3;
const int R_PIN = 9;
const int G_PIN = 11;
const int B_PIN = 10;
const int RELAY_PIN = 7;

#define ON                0XFFE01F
#define OFF               0xFF609F
#define BRIGHTNESS_UP     0xFFA05F
#define BRIGHTNESS_DOWN   0xFF20DF
#define FLASH             0xFFF00F
#define STROBE            0xFFE817
#define FADE              0xFFD827
#define SMOOTH            0xFFC837

#define RED               0xFF906F
#define GREEN             0XFF10EF
#define BLUE              0xFF50AF
#define WHITE             0xFFD02F

#define ORANGE            0xFFB04F
#define YELLOW_DARK       0xFFA857
#define YELLOW_MEDIUM     0xFF9867
#define YELLOW_LIGHT      0xFF8877

#define GREEN_LIGHT       0XFF30CF
#define GREEN_BLUE1       0XFF28D7
#define GREEN_BLUE2       0XFF18E7
#define GREEN_BLUE3       0XFF08F7

#define BLUE_RED          0XFF708F
#define PURPLE_DARK       0XFF6897
#define PURPLE_LIGHT      0XFF58A7
#define PINK              0XFF48B7

#define INCREMENTO 10

unsigned long rgb = 0;
byte CurrentR,CurrentG,CurrentB;
byte NextR, NextG, NextB;

IRrecv irrecv(RECV_PIN);

decode_results results;


void setup()
{
  irrecv.enableIRIn(); // Inicializamos el receptor
  Serial.begin(9600);

  // Start with everything off
  CurrentR = NextR = 0;
  digitalWrite(R_PIN, LOW);
  pinMode(R_PIN, OUTPUT);   
  CurrentG = NextG = 0;
  digitalWrite(G_PIN, LOW);
  pinMode(G_PIN, OUTPUT);   
  CurrentB = NextB = 0;
  digitalWrite(B_PIN, LOW);
  pinMode(B_PIN, OUTPUT);
  digitalWrite(RELAY_PIN, HIGH);
  pinMode(RELAY_PIN, OUTPUT);  
}


void variar (byte* color, int valor) {
  if (valor > 0) {
    if ( *color + valor <= 255) {
      *color += valor;
    } 
    else {
      *color = 255;
    }
  } 
  else { 
    if (*color + valor >= 0) {
      *color += valor;
    } 
    else {
      *color = 0;
    }
  }
}

void RGB(unsigned long valor) {
  NextR = valor >> 16; 
  NextG = (valor >> 8) & 0xFF; 
  NextB = valor & 0xFF; 
}


void loop() {
  static unsigned long lastFadeTime = 0;
  if (millis() - lastFadeTime > FadeInterval)
  {
    lastFadeTime = millis();
    if (NextR > CurrentR)
      CurrentR++;
    if (NextR < CurrentR)
      CurrentR--;
    if (NextG > CurrentG)
      CurrentG++;
    if (NextG < CurrentG)
      CurrentG--;
    if (NextB > CurrentB)
      CurrentB++;
    if (NextB < CurrentB)
      CurrentB--;
    analogWrite(R_PIN,CurrentR);
    analogWrite(G_PIN,CurrentG);
    analogWrite(B_PIN,CurrentB);
  }

  if (irrecv.decode(&results)) {
    if ( results.value != 0xFFFFFFFF) {
      switch (results.value) {
      case BRIGHTNESS_UP : 
        variar (&NextR, INCREMENTO);
        variar (&NextG, INCREMENTO);
        variar (&NextB, INCREMENTO);
        break; 
      case BRIGHTNESS_DOWN : 
        variar (&NextR, -INCREMENTO);
        variar (&NextG, -INCREMENTO);
        variar (&NextB, -INCREMENTO);
        break; 
      case ON: 
        digitalWrite (RELAY_PIN, LOW);
        break;
      case OFF: 
        digitalWrite( RELAY_PIN, HIGH);
        break;    
      case RED           : 
        RGB(0x00FF0000); 
        break;
      case GREEN         : 
        RGB(0x0000FF00); 
        break;
      case BLUE          : 
        RGB(0x000000FF); 
        break;
      case WHITE         : 
        RGB(0x00FFFFFF); 
        break;
      case ORANGE        : 
        RGB(0x00FF7F00); 
        break;
      case YELLOW_DARK   : 
        RGB(0x00FFAA00); 
        break;
      case YELLOW_MEDIUM : 
        RGB(0x00FFD400); 
        break;
      case YELLOW_LIGHT  : 
        RGB(0x00FFFF00); 
        break;
      case GREEN_LIGHT   : 
        RGB(0x0000FFAA); 
        break;
      case GREEN_BLUE1   : 
        RGB(0x0000FFFF); 
        break;
      case GREEN_BLUE2   : 
        RGB(0x0000AAFF); 
        break;
      case GREEN_BLUE3   : 
        RGB(0x000055FF); 
        break;
      case BLUE_RED      : 
        RGB(0x00000080); 
        break;
      case PURPLE_DARK   : 
        RGB(0x003F0080); 
        break;
      case PURPLE_LIGHT  : 
        RGB(0x007A00BF); 
        break;
      case PINK          : 
        RGB(0x00FF00FF); 
        break;
      }
      Serial.println(results.value, HEX);
      Serial.print(" ");
      Serial.print(NextR,DEC);
      Serial.print(" ");
      Serial.print(NextG, DEC);
      Serial.print(" ");
      Serial.println(NextB, DEC);

    }
    irrecv.resume(); // Receive the next value
  }
}

Thank you very much in advance for even taking the time to look at this.

-Ben