Arduino Mood Light Project (Continued)


So my 5050 lights came in and they are a little bigger than I thought they would be. So now I had to remove the second RGB lights I had put in. I did find a small error with the power supply. It was hooked up backwards. Glad I triple checked that.

I also double checked my code and found out that I had done something a little wrong. I needed to switch the positive to negative as the RGB was as common Anode not Cathode. So I quickly fixed some code and tested it on my bread board. Once the transition was nice and smooth I tested it on my new MC chip. Once all was well it was time to get this made.

I sent away for the boards to be made now.. After I get them back I will start the final part of the project the stand.

UPDATE 12/20/13:
I received my initial boards back from the fabricator and unfortunately I made a mistake. My original design called for a common anode RGB LED. But my RGB LED’s never showed up, so I had to order common cathode RGB LED’s. This was all ok how ever I forgot to change my schema to a common ground from common power. So.. it didn’t work.

However, I sent away for new boards to be made with this problem corrected along with a few minor alignment issues and WALLA! It works!

SO HOW DID I DO IT?
This project is pretty simple really. I just made a few dumb mistakes that could have been avoided if i was a little more experienced. If you read my other post I started off with much larger board and a little less integrated power supply. In this version I rectified the power and reduced the size by half. This was a product of both cost and functionality. The cost to have the boards made was cut in half when I reduced it. I also challenged myself with almost all SMD parts. This also made for a nicer compact application.

ARDUINO CODE
This first part is just the set up. The controller is based off the ATMega88p see boot loading an ATMEL ATMega88p for help on that. You can get these on Ebay cheap (I paid $10 for 6) and they are great!

#define RED_PIN  9       //13
#define GREEN_PIN  10    //14
#define BLUE_PIN  11     //15
    

void setup() {
  //Serial.begin(9600);
  // put your setup code here, to run once:
  pinMode(RED_PIN, OUTPUT);
  pinMode(GREEN_PIN, OUTPUT);
  pinMode(BLUE_PIN, OUTPUT);
}

void loop() { 
  showSpectrum();
}

void showSpectrum()
{
  int allLights = 765;
  //loop 256  * 3 times RGB
  for (int x = 0; x < allLights; x++)
  {
    showRGB(x); 
    delay(100);   // Delay for 10 ms (1/100th of a second)
  }
}

This function is the main RGB loop. Define the variables

/**
* common anode scale
*/
void showRGB(int color)
{
  int redIntensity;
  int greenIntensity;
  int blueIntensity;
 

I have two ways to do this. One uses a common Anode RGB which is commented here.

/* COMMON ANDODE
  if (color <= 255)                                              // RED TO BLUE (ON IS ZERO OFF IS 255)
  {
    //Serial.println("*************************** RED TO BLUE ***************************");
    redIntensity = color;                                        // red is going off 0 - 255
    greenIntensity = 255;                                        // green goes always off 255
    blueIntensity = constrain(255 - color, 0, 255);              // blue is coming up 255 - 0
  }
  else if (color <= 510)                                         // BLUE TO GREEN  (ON IS ZERO OFF IS 255)
  {
    //Serial.println("*************************** BLUE TO GREEN ***************************");
    redIntensity = 255;                                          // red is off 255
    greenIntensity = constrain(255 - (color - 255), 0 ,255);     // greeen is coming up 255 - 0
    blueIntensity =  constrain((color - 255), 0 , 255);          // blue is going off 0 - 255
  }
  else                                                           // GREEN TO RED (ON IS ZERO OFF IS 255)
  {
    //Serial.println("*************************** GREEN TO RED ***************************");
    redIntensity = constrain(255 - (color - 510), 0, 255);       // red is coming up 255 - 0 
    greenIntensity = constrain((color - 510), 0, 255);           // green is going off 0 - 255
    blueIntensity = 255;                                         // blue is always off 255
  }
 */

One uses a common cathode RGB which is the one I used.

  // COMMON CATHODE
  if (color <= 255)          // zone 1
  {
    redIntensity = 255 - color;    // red goes from on to off 255 - 0
    greenIntensity = color;        // green goes from off to on 0 - 255
    blueIntensity = 0;             // blue is always off 0
  }
  else if (color <= 511)     // zone 2
  {
    redIntensity = 0;                     // red is always off 0
    greenIntensity = 255 - (color - 256); // green on to off 255 - 0
    blueIntensity = (color - 256);        // blue off to on 0 - 255
  }
  else // color >= 512       // zone 3
  {
    redIntensity = (color - 512);         // red off to on 0 - 255
    greenIntensity = 0;                   // green is always off 0
    blueIntensity = 255 - (color - 512);  // blue on to off 255 - 0
  }

Some debug code used when breadboarding

 /* DEBUG CODE
   // print the three numbers in one string as hexadecimal:
    Serial.print("RED: ");
    Serial.println(redIntensity);
    Serial.print("GREEN: ");
    Serial.println(greenIntensity);
    Serial.print("BLUE: ");
    Serial.println(blueIntensity);
*/

Then write to the LEDs

  analogWrite(RED_PIN, redIntensity);
  analogWrite(GREEN_PIN, greenIntensity);
  analogWrite(BLUE_PIN, blueIntensity);
}

THE SCHEMA

GET THE SOURCE CODE
The Code

PARTS
- Power Converter
- ATMEL ATMega88p
- Common Anode RGB LED
- 100ohm -120ohm 0805 SMD Resistor
- Power Switch
- 6mm Momentary Switch
- 2.1mm SMD Barrel Plug

Loading Facebook Comments ...