Friday, December 9, 2011

Circuit 12 - RGB LEDs

Purpose: To use an RGB led to make a rainbow of colours

Equipment:

  • Arduino x 1
  • Breadboard x 1
  • Arduino Holder x 1
  • CIRC - 12 Breadboard Sheet x 1
  • RGB LED x 1
  • 330 Ohm Resistor x 3 
  • Wire x 6

References:


Program Details:
In this circuit a new piece of hardware is introduces, an RGB led. The RGB led is basically three led's put together, a red, a green and a blue stuck inside a small package. And to create different colours, it uses a combination of all 3 LED's. This is done because red, green and blue are the primary colours of light and all different shades of light can be created by mixing those three colours. 

The programming aspect is quite simple in this exercise; no new concepts are introduced. First, all three LED's are declared and initialized. Then, by using a for loop, the program cycles colours (in increments of 5) between red and green, then between green and blue and finally between blue and red. Each increment/decrement has a 100 millisecond delay between it. 


Time to Complete: 5 mins to assemble
                                10 mins to code

Results: The RGB LED worked perfectly the first time. 

Photo: 



Video: 

Tips:
  • Place RGB leads correctly, the correct side can be adjusted by looking at the flat side
  • Both the program and the setup is very easy 

Further Work: I will change the colours more rapidly or make different colours than the ones that were created through this experiment.

Program Modifications: 
This program is almost the same as the one in the link below:

Program:
// declares which pins are connected to which leads
const int RED_LED_PIN = 9;
const int GREEN_LED_PIN = 10;
const int BLUE_LED_PIN = 11;

// stores intensity level of the leds
int redIntensity = 0;
int greenIntensity = 0;
int blueIntensity = 0;

int time = 100; // time between each interval of colour change

void setup()    // no setup
{
}

void loop() 
{
  // Changes the colour from red to green in increments of 5 every 100 milliseconds
  for (greenIntensity = 0; greenIntensity <= 255; greenIntensity+=5) {
        redIntensity = 255-greenIntensity;
        analogWrite(GREEN_LED_PIN, greenIntensity);
        analogWrite(RED_LED_PIN, redIntensity);
        delay(time);
  }

  // Changes the colour from green to blue in increments of 5 every 100 milliseconds
  for (blueIntensity = 0; blueIntensity <= 255; blueIntensity+=5) {
        greenIntensity = 255-blueIntensity;
        analogWrite(BLUE_LED_PIN, blueIntensity);
        analogWrite(GREEN_LED_PIN, greenIntensity);
        delay(time);
  }
  
  // Changes the colour from blue to red in increments of 5 every 100 milliseconds
  for (redIntensity = 0; redIntensity <= 255; redIntensity+=5) {
        blueIntensity = 255-redIntensity;
        analogWrite(RED_LED_PIN, redIntensity);
        analogWrite(BLUE_LED_PIN, blueIntensity);
        delay(time);
  }
}// end loop

No comments:

Post a Comment