loading


This is my first instructable.  Have been a long time lurker and tinkerer.  This year I decided to make a RGB LED Christmas wreath with some cool led patterns.  I decided to use an Arduino Uno microcontroller that I had laying around.  When looking at controlling the RGB LEDs, I found that I needed 3 PWM pins per channel of LEDs.  I found that with the Uno, I could only have 2 channels of LEDs due to only having 6 PWM pins total.  From another project, I already had 7 common cathode RGB LEDs laying around, so I assigned 4 to the main channel, and 3 to the other channel.


Materials Required:

Wreath
Arduino Uno/compatible with 6 PWM pins
at least a few RGB LEDs, Common Cathode
5' Cat5e or similar 8 conductor wire
Dolphin clips crimpable wire connectors (not really necessary)
Soldering iron & solder
Break Away Headers - Long (PRT-1015 from Sparkfun)
9v battery clip (with header, or solder one to the wires)
SPST switch for power (optional, I actually used SPDT)
Hot glue gun
Zipties

Step 1: Breadboard First

So I took to the breadboard and assembled all the RGB LEDs on there for testing.  Using 2 channels (3 leds in series for one channel, 4 leds in series for another channel), with a common ground from the arduino, I wanted to make some cool patterns.  I found some code @ http://forum.arduino.cc/index.php/topic,11293.0.html and it worked, so I started modifying it and came up with some different types of patterns.

Basically, just put 2 LEDs on the breadboard.  The pinout for the LEDs I used were Short-Long-Med-Short = Red-Ground-Green-Blue.  Connect the grounds together and to the GND pin on the arduino using jumper wire.  The PWM pins you have to use on the arduino are 3,5,6, and 9,10,11.  Connect LED1 red to 3, LED1 green to 5, LED1 Blue to 6.  Then LED2 Red to 9, LED2 Green to 10, LED2 Blue to 11.  I didn't use any resistors in this circuit because these LEDs are pretty solid and I haven't had one burn up yet.  You could put a 200-300 ohm resistor in front of each pin but I didn't have any low impedance resistors at the time.  It only has to work for a month out of every year! =]

Sorry my breadboard picture is so bad, I only got a cellphone camera video and the quality was not great.

Here is the most important part of it all: the code.


/*
*
* ARDUINO RGBLED XMAS WREATH 2013
* by amplex (alexdatsko@gmail.com)  12-6-13
*
* This project consists of an Arduino Uno (R3, doesn't matter).  You just need 6 PWM pins to be able to control the RGB LEDs.  I know, I should have put some resistors in but I bench tested it for hours and nothing burned out.
* This project uses 2 channels of RGB LEDS (https://www.sparkfun.com/products/9853 I used common cathode, pinout is Red,Ground,Green,Blue (see below) ) cycles between different patterns for an xmas wreath
* Enjoy the Blinkenlights!
*
* some code stolen from ( http://forum.arduino.cc/index.php/topic,11293.0.html ) and ( https://www.instructables.com/id/RGB-LED-transition-Arduino/ )
* and got heavily modified, made a bunch of new patterns, etc.  the fun part.  there was some debugging that got annoying so I just commented out those routines.  After the program looped once completely, they would hang after 2 iterations (cycles).. Not sure why.
* Feel free to figure it out and clue me in.  Tried checking memory, removing new subroutine variables and constants, tried another arduino, same issue.  Not all code standardized or pretty by any means..
*
*
* ARDUINO PINOUT, TO CAT5E COLORS
* -------------------------------
* pin 3  - Red     -  ORANGE
* pin 5  - Green   -  GREEN
* pin 6  - Blue    -  BLUE
* pin 9  - Red     -  WHITE/ORANGE
* pin 10 - Green   -  WHITE/GREEN
* pin 11 - Blue    -  WHITE/BLUE
* ground - Brown   -  BROWN
* (UNUSED)         -  WHITE/BROWN
*
*       RGB LED PINOUT
*       --------------
*               _
*              ( )
*              /~\
*             /| |\
*            / | | \
*            | | | |
*            | | | |
*            | | | |
*              | | BL
*           RED| GR 
*             GND
*
*
*   LED Colors used on Cat5e cable
*   ------------------------------
* 1 BL OR GR       - BRN-Ground
* 2 w/BL w/OR w/GR - BRN-Ground
* 3 BL OR GR       - BRN-Ground
* 4 w/BL w/OR w/GR - BRN-Ground
* 5 BL OR GR       - BRN-Ground
* 6 w/BL w/OR w/GR - BRN-Ground
* 7 BL OR GR       - BRN-Ground
*

*/


// set analog pins

#define LED1 3
#define LED2 5
#define LED3 6
#define LED4 9
#define LED5 10
#define LED6 11

#define PLASMADELAY 4 
#define VERYQUICKDELAY 10
#define QUICKDELAY 30
#define LONGDELAY 100

#define fade(x,y) if (x>y) x--; else if (x<y) x++;

int redNow = random(255);
int blueNow = random(255);
int greenNow = random(255);
int redNew = redNow;
int blueNew = blueNow;
int greenNew = greenNow;


float RGB1[3];
float RGB2[3];
float RGB3[3];
float RGB4[3];
float INC[3];
float INC2[3];

int red, green, blue;
int red2, green2, blue2;

int pause=10;
int up=1;
int cycles=2;
int x=0;
int y=0;
int xx=0;


void setup()     //  **************************** SETUP *********************************
{
  Serial.begin(9600);
  randomSeed(analogRead(0));
 
 
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
 
  pinMode(LED4, OUTPUT);
  pinMode(LED5, OUTPUT);
  pinMode(LED6, OUTPUT);

  for (x=0; x<3; x++)
  {
    RGB1[x] = random(256);
    RGB2[x] = random(256);
    RGB3[x] = random(256);
    RGB4[x] = random(256);
  }

  showfreeram();  // check RAM left, my Serial strings seem to take a lot of memory, causing lockups once in awhile for some reason.

  RGBtest();   // Test both RGB LED Channels.  Test LED 1 Red, then green, then blue, then LED 2 Red, Green, Blue

  randomSeed(analogRead(0));
}

void dopause() {
    delay(pause);  
    if (up==1) pause=pause+10;
    if (up==0) pause=pause-10;
    if (pause>=200) up=0;  // reset timer, timing is now going down
    if (pause<=0) up=1;  // timing is going back up
}

void dopause2() {
    delayMicroseconds(pause*10);  
    if (up==1) pause=pause+10;
    if (up==0) pause=pause-10;
    if (pause>=200) up=0;  // reset timer, timing is now going down
    if (pause<=0) up=1;  // timing is going back up
}

void domicropause() {
//  delay(VERYQUICKDELAY*pause);
    delayMicroseconds(pause*10);  
    if (up==1) pause=pause+1;
    if (up==0) pause=pause-1;
    if (pause>=20) up=0;  // reset timer, timing is now going down
    if (pause<=0) up=1;  // timing is going back up
}

void LEDwrite(int led, int red, int green, int blue) {
  if (led==1) {
      analogWrite (LED1, red); 
      analogWrite (LED2, green);  
      analogWrite (LED3, blue);    
  } else
  if (led==2) {
      analogWrite (LED4, red); 
      analogWrite (LED5, green);  
      analogWrite (LED6, blue);  
  }

//      delay(VERYQUICKDELAY);  
}


void LEDplasmawrite(int led, int red, int green, int blue) {
  if (led==1) {
      analogWrite (LED1, red); 
      analogWrite (LED2, green);  
      analogWrite (LED3, blue);    
  } else
  if (led==2) {
      analogWrite (LED4, red); 
      analogWrite (LED5, green);  
      analogWrite (LED6, blue);  
  }

      delay(PLASMADELAY);   // VERYQUICK DELAY IS TOO SLOW
}

void randomjumpfade() {    // &&&&&&&&&&&&&&&&&&&&&&&&& RANDOM JUMP FADE &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

  Serial.print("\nRandomJumpFade..\n");

  for (y=0; y<cycles; y++) {
    Serial.print(y);
    Serial.print("..");
    for (x=0; x<3; x++) {
      INC[x] = (RGB1[x] - RGB2[x]) / 256;
      INC2[x] = (RGB3[x] - RGB4[x]) / 256;
    }
    for (x=0; x<256; x++) {
      red = int(RGB1[0]);
      green = int(RGB1[1]);
      blue = int(RGB1[2]);

      red2 = int(RGB3[0]);
      green2 = int(RGB3[1]);
      blue2 = int(RGB3[2]);

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
 
      for (xx=0; xx<3; xx++) {
         RGB1[xx] -= INC[xx];
         RGB3[xx] -= INC2[xx];   // INC[xx] for 'different' jumps
      }
      delay(QUICKDELAY);   // dont need to wait 1000.. make it smoother 
    }
    for (x=0; x<3; x++) {
      RGB2[x] = random(956)-700;
      RGB2[x] = constrain(RGB2[x], 0, 255);
      RGB4[x] = random(1856)-1600;
      RGB4[x] = constrain(RGB4[x], 0, 255);
    }
  } // end y<cycles
}

void slowfadeinwhite() {    // &&&&&&&&&&&&&&&&&&&&&&&&& SLOW FADE-IN 'BLINK' &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

  Serial.print("\nSlowFadeinWhite..\n");
    for (x=0; x<256; x++) {

      red = x;
      green = x;
      blue = x;

      red2 = 0;
      green2 = 0;
      blue2 = 0;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);

      delay(VERYQUICKDELAY);
    } //end x<256
   
  for (y=0; y<cycles; y++) {
    Serial.print(y);
    Serial.print("..");

    for (x=0; x<256; x++) {
      red = 255-x;
      green = 255-x;
      blue = 255-x;

      red2 = x;
      green2 = x;
      blue2 = x;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);

    delay(VERYQUICKDELAY);      

    } //end x<256

    // BLINK  ***** switch states   

    for (x=0; x<256; x++) {
      red = x;
      green = x;
      blue = x;

      red2 = 255-x;
      green2 = 255-x;
      blue2 = 255-x;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);

      delay(VERYQUICKDELAY);
    } //end x<256
   
  }  // end y<cycles

}

void fastblink() {    // &&&&&&&&&&&&&&&&&&&&&&&&& FAST BLINK &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

  Serial.print("Fastblink..\n");
 
  for (y=0; y<cycles*16; y++) {
// serial buffer being overrun?
//      Serial.print(y);
//      Serial.print("..");
 
      red = 222;
      green = 222;
      blue = 222;

      red2 = 0;
      green2 = 0;
      blue2 = 0;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      dopause();  

    // BLINK

      LEDwrite(1,red2,green2,blue2);
      LEDwrite(2,red,green,blue);
      dopause();

   
  }  // end y<cycles
}

void fastblinkcolorfade() {    // &&&&&&&&&&&&&&&&&&&&&&&&& FAST BLINK COLOR FADE &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

  Serial.print("\nFastblink Colorfade..\n");
 
  for (y=0; y<cycles*4; y++) {
    Serial.print(y);
    Serial.print("..");
 
    for (x=0; x<256; x++) {

      red = x;
      green = 255-x;
      blue = 0;

      red2 = 0;
      green2 = 0;
      blue2 = 0;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      domicropause(); 
    } //end x<256

   
    // BLINK
    for (x=0; x<256; x++) {

      red = 0;
      green = 0;
      blue = 0;


      red2 = x;
      green2 = 255-x;
      blue2 = 0;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      domicropause();   
    } //end x<256
   
    //  &&&&&&&&&&&&&&&&&&&&&&&&&&&& 2
   
    for (x=0; x<256; x++) {

      red = 0;
      green = x;
      blue = 255-x;

      red2 = 0;
      green2 = 0;
      blue2 = 0;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      domicropause(); 
    } //end x<256
   
    // BLINK
    for (x=0; x<256; x++) {

      red = 0;
      green = 0;
      blue = 0;


      red2 = 0;
      green2 = x;
      blue2 = 255-x;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      domicropause(); 
     
    } //end x<256

    //  &&&&&&&&&&&&&&&&&&&&&&&&&&&& 3
   
    for (x=0; x<256; x++) {

      red = 255-x;
      green = 0;
      blue = x;

      red2 = 0;
      green2 = 0;
      blue2 = 0;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      domicropause(); 
    } //end x<256
   
    // BLINK
    for (x=0; x<256; x++) {

      red = 0;
      green = 0;
      blue = 0;


      red2 = 255-x;
      green2 = 0;
      blue2 = x;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      domicropause(); 
     
    } //end x<256
  
  }  // end y<cycles
}

void fastblinkcolorfademod() {    // &&&&&&&&&&&&&&&&&&&&&&&&& FAST BLINK COLOR FADE MODIFIED .. &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

  Serial.print("\nFastblink Colorfade Modified..\n");
 
  for (y=0; y<cycles*4; y++) {
    Serial.print(y);
    Serial.print("..");
 
    for (x=0; x<256; x++) {

      red = x;
      green = 255-x;
      blue = 0;

      red2 = 0;
      green2 = x;
      blue2 = 255-x;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      domicropause(); 
    } //end x<256

   
    // BLINK
    for (x=0; x<256; x++) {

      red = 0;
      green = x;
      blue = 255-x;


      red2 = x;
      green2 = 255-x;
      blue2 = 0;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      domicropause();   
    } //end x<256
   
    //  &&&&&&&&&&&&&&&&&&&&&&&&&&&& 2
   
    for (x=0; x<256; x++) {

      red = 0;
      green = x;
      blue = 255-x;

      red2 = 255-x;
      green2 = 0;
      blue2 = x;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      domicropause(); 
    } //end x<256
   
    // BLINK
    for (x=0; x<256; x++) {

      red = 255-x;
      green = 0;
      blue = x;


      red2 = 0;
      green2 = x;
      blue2 = 255-x;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      domicropause(); 
     
    } //end x<256

    //  &&&&&&&&&&&&&&&&&&&&&&&&&&&& 3
   
    for (x=0; x<256; x++) {

      red = 255-x;
      green = 0;
      blue = x;

      red2 = 0;
      green2 = x;
      blue2 = 255-x;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      domicropause(); 
    } //end x<256
   
    // BLINK
    for (x=0; x<256; x++) {

      red = 0;
      green = x;
      blue = 255-x;


      red2 = 255-x;
      green2 = 0;
      blue2 = x;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      domicropause(); 
     
    } //end x<256
  
  }  // end y<cycles
}

void fastblinkswap() {    // &&&&&&&&&&&&&&&&&&&&&&&&& FAST BLINK COLOR swap .. &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

  Serial.print("Fastblink color swap..\n");
 
  for (y=0; y<cycles; y++) {
    Serial.print(y);
    Serial.print("..");

    Serial.print("(1),");
    for (x=0; x<256; x++) {

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      domicropause(); 
      LEDwrite(1,0,0,0);
      LEDwrite(2,0,0,0);
      domicropause(); 

    } //end x<256
    for (x=255; x>0; x--) {

      red = x;
      green = 255-x;
      blue = x;

      red2 = x;
      green2 = x;
      blue2 = 255-x;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      domicropause(); 
      LEDwrite(1,0,0,0);
      LEDwrite(2,0,0,0);
      domicropause(); 

      LEDwrite(1,blue,green,red);
      LEDwrite(2,blue2,green2,red2);
      domicropause(); 
      LEDwrite(1,0,0,0);
      LEDwrite(2,0,0,0);
      domicropause(); 
    } //end x<256

    Serial.print("(2),");
    // ********************************** 2
  
    for (x=0; x<256; x++) {

      red = 255-x;
      green = x;
      blue = x;

      red2 = x;
      green2 = 255-x;
      blue2 = x;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      domicropause(); 
      LEDwrite(1,0,0,0);
      LEDwrite(2,0,0,0);
      domicropause(); 

      LEDwrite(1,blue,green,red);
      LEDwrite(2,blue2,green2,red2);
      domicropause(); 
      LEDwrite(1,0,0,0);
      LEDwrite(2,0,0,0);
      domicropause(); 

    } //end x<256
    for (x=255; x>0; x--) {

      red = 255-x;
      green = x;
      blue = x;

      red2 = x;
      green2 = 255-x;
      blue2 = x;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      domicropause(); 
      LEDwrite(1,0,0,0);
      LEDwrite(2,0,0,0);
      domicropause(); 

      LEDwrite(1,blue,red,green);
      LEDwrite(2,blue2,red2,green2);
      domicropause(); 
      LEDwrite(1,0,0,0);
      LEDwrite(2,0,0,0);
      domicropause(); 

    } //end x<256

    Serial.print("(3),");
    // ********************************** 3
  
    for (x=0; x<256; x++) {

      red = x;
      green = x;
      blue = 255-x;

      red2 = 255-x;
      green2 = x;
      blue2 = x;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      domicropause(); 
      LEDwrite(1,0,0,0);
      LEDwrite(2,0,0,0);
      domicropause(); 

      LEDwrite(1,blue,green,red);
      LEDwrite(2,blue2,green2,red2);
      domicropause(); 
      LEDwrite(1,0,0,0);
      LEDwrite(2,0,0,0);
      domicropause(); 

    } //end x<256
    for (x=255; x>0; x--) {

      red = x;
      green = x;
      blue = 255-x;

      red2 = 255-x;
      green2 = x;
      blue2 = x;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      domicropause(); 
      LEDwrite(1,0,0,0);
      LEDwrite(2,0,0,0);
      domicropause(); 

      LEDwrite(1,blue,green,red);
      LEDwrite(2,blue2,green2,red2);
      domicropause(); 
      LEDwrite(1,0,0,0);
      LEDwrite(2,0,0,0);
      domicropause(); 

    } //end x<256

  }
}


void fastRGBblink() {    // &&&&&&&&&&&&&&&&&&&&&&&&& FAST COLOR BLINK &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

  Serial.print("\nfastRGBblink..\n");
 
  for (y=0; y<cycles*4; y++) {
    Serial.print(y);
    Serial.print("..");


  // **** 1 *********************************************************   LED1 = RED, LED2 = GREEN
    Serial.print("1,");
    for (x=0; x<256; x++) {

      red = x;
      green = 0;
      blue = 0;

      red2 = 0;
      green2 = 0;
      blue2 = 0;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      dopause2();

    } //end x<256

   
    // BLINK
    for (x=0; x<256; x++) {

      red = 0;
      green = 0;
      blue = 0;


      red2 = 0;
      green2 = x;
      blue2 = 0;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      dopause2();
 
    }  //end x<256


  // **** 2 ********************************************************* LED1 = GREEN, LED2 = BLUE
 
    Serial.print("2,");
    for (x=0; x<256; x++) {

      red = 0;
      green = x;
      blue = 0;

      red2 = 0;
      green2 = 0;
      blue2 = 0;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      dopause2();
    } //end x<256

   
    // BLINK
    for (x=0; x<256; x++) {

      red = 0;
      green = 0;
      blue = 0;

      red2 = 0;
      green2 = 0;
      blue2 = x;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      dopause2();
    }  //end x<256

   
  // **** 3 ********************************************************* LED1 = BLUE, LED2 = RED
 
    Serial.print("3, ");
    for (x=0; x<256; x++) {

      red = 0;
      green = 0;
      blue = x;

      red2 = 0;
      green2 = 0;
      blue2 = 0;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      dopause2();
    } //end x<256

   
    // BLINK
    for (x=0; x<256; x++) {

      red = 0;
      green = 0;
      blue = 0;

      red2 = x;
      green2 = 0;
      blue2 = 0;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      dopause2(); 
    } //end x<256

   
  }  // end y<cycles
}




void fastcolorfade() {    // &&&&&&&&&&&&&&&&&&&&&&&&& FAST COLOR FADE &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

  Serial.print("\nFastcolorFade..\n");
 
  for (y=0; y<cycles; y++) {
    Serial.print(y);
    Serial.print("..");

// **************** fadein red (1)
  Serial.print("fadein red..");
    for (x=0; x<256; x++) {
      red = x;                             // RED IN, GREEN OUT, BLUE OFF
      green = 255-x;
      blue = 0;

      red2 = 0;
      green2 = x;
      blue2 = 255-x;
     
      LEDplasmawrite(1,red,green,blue);
      LEDplasmawrite(2,red2,green2,blue2);
    } //end x<256

    for (x=255; x>0; x--) {
      red = x;                            // RED OUT, GREEN IN, BLUE OFF
      green = 255-x;
      blue = 0;

      red2 = 0;
      green2 = x;
      blue2 = 255-x;
     
      LEDplasmawrite(1,red,green,blue);
      LEDplasmawrite(2,red2,green2,blue2);
    } //end x<256

// **************** fadein green (2)
  Serial.print("fadein green..");

    for (x=0; x<256; x++) {
      red = 0;                           // RED OFF, GREEN OUT, BLUE IN
      green = 255-x;
      blue = x;

      red2 = x;
      green2 = 0;
      blue2 = 255-x;
     
      LEDplasmawrite(1,red,green,blue);
      LEDplasmawrite(2,red2,green2,blue2);
    } //end x<256

    for (x=255; x>0; x--) {
      red = 0;                           // RED OFF, GREEN IN, BLUE OUT
      green = 255-x;
      blue = x;

      red2 = x;
      green2 = 0;
      blue2 = 255-x;
     
      LEDplasmawrite(1,red,green,blue);
      LEDplasmawrite(2,red2,green2,blue2);
    } //end x<256

// **************** fadein blue (3)
  Serial.print("fadein blue..");
    for (x=0; x<256; x++) {
      red = x;                           // RED IN, GREEN OUT, BLUE OFF
      green = 255-x;
      blue = 0;

      red2 = 0;
      green2 = x;
      blue2 = 255-x;
     
      LEDplasmawrite(1,red,green,blue);
      LEDplasmawrite(2,red2,green2,blue2);
    } //end x<256

    for (x=255; x>0; x--) {
      red = x;                         
      green = 255-x;
      blue = 0;

      red2 = 0;
      green2 = x;
      blue2 = 255-x;
     
      LEDplasmawrite(1,red,green,blue);
      LEDplasmawrite(2,red2,green2,blue2);
    } //end x<256

   
    Serial.print("\n");
  } // end y<cycles*16
}

int freeRam ()
{
  extern int __heap_start, *__brkval;
  int v;
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}

void showfreeram() {
  Serial.print( "\nFree RAM = " );
  Serial.println( freeRam() );
}

void randomfadeslow()
{
  Serial.print("\nRandomfadeSlow..\n");

  for (y=0; y<cycles*4; y++) {
    Serial.print(y);
    Serial.print("..");
    LEDwrite(1,redNow,greenNow,blueNow);
    LEDwrite(2,redNow,greenNow,blueNow);
    redNew = random(255);
    greenNew = random(255);
    blueNew = random(255);
    // fade to new colors
    while (( redNow   != redNew   )  ||
           ( greenNow != greenNew )  ||
           ( blueNow  != blueNew  ))
    {
      fade(redNow,redNew)
      fade(greenNow,greenNew)
      fade(blueNow,blueNew)
      LEDwrite(1,redNow,greenNow,blueNow);
      LEDwrite(2,redNow,greenNow,blueNow);
      delay(QUICKDELAY);
    }
  } //end y<cycles
}

void RGBtest() {
  LEDwrite(1,0,0,0);
  LEDwrite(2,0,0,0);
  for (y=0; y<cycles; y++) {
//test LED channel 1
      LEDwrite(1,255,0,0);
      delay(LONGDELAY*4);
      LEDwrite(1,0,255,0);
      delay(LONGDELAY*4);
      LEDwrite(1,0,0,255);
      delay(LONGDELAY*4);
      LEDwrite(1,0,0,0);
      delay(LONGDELAY*4);

//test LED channel 2
      LEDwrite(2,255,0,0);
      delay(LONGDELAY*4);
      LEDwrite(2,0,255,0);
      delay(LONGDELAY*4);
      LEDwrite(2,0,0,255);
      delay(LONGDELAY*4);
      LEDwrite(2,0,0,0);
      delay(LONGDELAY*4);
  }
}


void loop() {    //  **************************** MAIN *********************************

/*

// THESE WERE CAUSING LOCKUPS WHEN THEY ITERATE TWICE FOR SOME REASON..

  fastblinkswap();

  fastblink();
  showfreeram();
*/


 
  randomSeed(analogRead(0));

  randomfadeslow();
  showfreeram();
 
  fastRGBblink();
  showfreeram();

  slowfadeinwhite();
  showfreeram();
 
  fastblinkcolorfade();
  showfreeram();

  fastblinkcolorfademod();
  showfreeram();
 
  randomjumpfade(); 
  showfreeram(); 

  fastcolorfade();
  showfreeram();

}


Step 2: Construction: Wiring

As you could see in the top of my code, I decided to go with this wiring color scheme, due to the simplicity of it: Orange is closest to Red, Green to Green, Blue to Blue.  And the White/Or, White/Gr, White/Bl will be for the second LED channel.  The LED's will alternate, 1st will be LED1, 2nd will be LED2, 3rd will be LED1, 4th LED2, 5th LED1, etc..  I used a common ground path back to the Arduino which shouldn't cause any major issues.

LED#                    Cat5e wire color
------------------------------------------------
LED1 - Red       - Orange
LED1 - Green   - Green
LED1 - Blue      - Blue
LED1 - Ground - Brown
LED2 - Red       - White/Orange
LED2 - Green   - White/Green
LED2 - Blue      - White/Blue
LED2 - Ground - Brown
(unused)           - White/Brown
(my picture actually shows LED2 on LED1 pins and vice versa but it doesn't really matter)

For wiring, I decided to use Cat5e as I have a few thousand feet of it around and use it with lots of Arduino projects.  I cut strips about 10" long so I would have enough to play with, as you need 2 extra inches per piece to get up and through the wreath, and the wire is so thin and malleable that you can twist it around pretty easy to hide it behind the wreath.  I went with white but use any color that will not stick out through the thin wreath.  After you have cut as many pieces for which you have LEDs, you will need to strip off about 1" off the end of each cable, untwist the wires, and strip the jacket off of each wire. 

If I had it to do over again, I would not cut strips of wire at all.  I could measure and mark the lengths I wanted on a solid piece of cable, and carefully strip back the jacket at the marks and slide it down a bit.  Then I could just cut the 4 wires I needed to strip back and solder to an LED (Or, Gr, Bl, Br, or W/Or, W/Gr, W/Bl, Br depending on the channel) and there would be a lot less soldering, and no dolphin clips would be required. But the way I did it, with strips of wire, I had to twist each wire with the same color on the next piece so I had a long cable with 7 spots of exposed wire.  About an hour or more extra work.  It works fine but there is a lot more potential for error this way in my opinion.

PRO-TIP:  If you are using superior essex cat5e with the lighter solid colored wire (instead of striped white/green, it is more a light green, same with all colors): Before you start wiring, in a well lit area, cut off ALL the white/brown wires that we won't be using.  White/Brown and White/Orange are almost identical in this brand of cable.  I did miswire a white/br to white/or in the middle which I didn't notice until the next day when I realized some of my reds were missing in one channel.  Luckily I used way too much wire and was able to strip back and peel the correct White/Orange out of cable and solder them back together.  Then I wrote the RGBtest() routine which would show each separate color in each channel to make sure its wired right.  When you first wire it up and load up the arduino with my code, you will see this test.  If you dont see (LED1: Red, Green Blue, then LED2: Red, Green, Blue)  you know your pins are off, or you have miswired something.  Start at the arduino and check your wiring the whole way down.  Even with just 7 leds, you end up with 63 solder points including the arduino header pins (if you use these)!


Step 3: Construction: Soldering

Set up your soldering station.  I use the little 'helping hands with magnifying glass' to hold components in place for me.  I used to have my wife hold stuff for me when I began soldering in my first apartment.  Having two of these 'helping hands' is really convenient.  I have to clamp them to my workspace to keep them from tipping with the weight of wire and components on them, they are light.  A decent adjustable light with a magnifying glass built in is nice as well.  Somewhere around $25 at Fry's Electronics.  No I don't have my resistor color codes memorized still.  Learned them too late in life I guess. 

Bend the leads of the LEDs apart a bit so you have some room to work.  Bend the wire around to meet the LED legs.  Make sure to heat both parts of the solder joint for 1 second before you apply a liberal amount of solder.

Step 4: Construction: Soldering Part 2

9v battery clip and optional power switch are next.  Very simple, cut the red wire on the battery clip.  Attach the side with the battery to the middle conductor of the switch.  Connect the other side to either other conductor of the switch (or the only other conductor if you use a SPST switch).  Solder these guys and either tape or dolphin clip them apart from each other.

Step 5: Construction: Gluing, Sanding

Now, heat up the hot glue gun.  I decided that if I am shoving these LED's in possible tight spots in a wreath, if the conductors touch I could blow LED's or short them out, etc.  So I decided to hot glue all the conductive areas from my wires towards the top of the LED.  Bend the legs of the LEDs back close to one another like they were when you bought it (careful they aren't touching!).  Once you get enough hot glue out on the wires, it will be messy and wanting to fall thru the cracks.  Go slow and kind of drip it back onto itself (turn it upside down when it starts to drip, and repeat until it stays).  Cover the solder joints and the wire all the way to the jacket.

Also if you want to diffuse the LED (make it so you can't see the separate elements inside, make more of a dull colorized glow), you can sand the tops of your LEDs.  I didn't do this because they are mostly inside a wreath and I don't mind the clear look.  If your LED's are not perfectly clear don't worry about this step, they are already diffused.

Yes my workspace is small and very messy at the moment.

Step 6: Final: Attach to Wreath

At this point, all solder connections and wiring connections should be complete.  I would plug everything in and turn it on and run the patterns to make sure everything looks right.  At least run the RGBtest() to make sure your LEDs are in the correct sequence, etc.  Turn your wreath over and stick the LEDs in it wherever you like.  At this point I realized using 7 LEDs sucks because there is a point where both sequential LEDs are the same channel.  But whatever, its just a quick basic project and if I ever make one again, I will know to use an even number.

I used black tiewraps to ziptie the cable to the wreath.  I also used black electric tape to semi-conceal (and seal) my arduino on this step, except for the USB port so I can program new patterns, after all, I'm a tinkerer..  Luckily an 8" ziptie fit around the arduino, if yours doesn't fit, just use two in series.  Also you can ziptie the battery alongside it.  I just let the switch hang down just beneath the arduino.

Step 7: Testing, Done!

Put your wreath up and see how it looks.  Test out your patterns and make sure everything still works.  This is where I noticed I had miswired a White/Orange to a White/Brown and had cut out the other White/Orange, thus all of my other Red wires on this channel were open. 

Hopefully your wreath doesn't sit too far off the wall and all of the wires and connectors concealed well.  You can see it if you look close, but my wreath has just enough going on that you couldn't really see much.

Now enjoy the fruits of your effort.  I had a couple more ideas to mod this guy out, such as an LDR to turn off the lights in the daytime (make sure to get it far enough away from the bright LED's so it doesnt turn itself off!), a pot to control the speed of how fast the patterns change (I would tie it to the cycles variable), and a pot to control the speeds of the pauses to make the effects faster or slower.

Other ideas:  Use a rugged audio shield and/or a little speaker to play a few xmas songs, or make an aux input and time it to xmas music playing off your receiver or something. 

I'm not sure how long the battery will last for this project, these little LEDs probably use quite a bit of juice since they are like 3 led's in one.  I just made it yesterday, and haven't even bought a fresh battery for it yet, so we will see.  Good luck!
<p>Hi! How about using Commun anode led ??</p><p>thank you!</p><p>marC:)</p>
It's beautiful! Do you think you could provide a link to which RGB LEDs you used? I have tried to use some, and have had varying luck with them.
Thanks! I ordered these from Sparkfun: https://www.sparkfun.com/products/9853 <br>Be careful because the pinout is different on one of the pages, the Ground is the longest pin.

About This Instructable

3,705views

29favorites

License:

Bio: i like to build things, fix things, create things, and find out how things work in general.
More by amplex:Arduino RGB LED Christmas Wreath 
Add instructable to: