Arduino: Color Changing LEDs

Sure you could multiple LEDs to get color combinations.  OR you could use just one LED that has color changing.

You can control multiple colors and the delay between colors.

Want MORE colors?  Click here. 

The circuit diagram is below.

The sample code is below the circuit.  Copy/paste the ENTIRE PROGRAM into tinkercad.com.

After you get your LED working then setup a new sequence with at least five NEW colors (see the chart linked above) and a different interval between each color.  Show me this for credit.

Extension activity: add a button that will trigger the color changing sequence.

ingredients

1 RGB three color LED – this has FOUR legs.  The long leg is the ground.

2 220 ohm resistors (red red brown)

4 jumper wires

the recipe

arduinoRGB

/*
Adafruit Arduino – Lesson 3. RGB LED
*/

int redPin = 11;
int greenPin = 10;
int bluePin = 9;

//uncomment this line if using a Common Anode LED
//#define COMMON_ANODE

void setup()
{
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}

void loop()
{
setColor(255, 0, 0); // red
delay(1000);
setColor(0, 255, 0); // green
delay(1000);
setColor(0, 0, 255); // blue
delay(1000);
setColor(255, 255, 0); // yellow
delay(1000);
setColor(80, 0, 80); // purple
delay(1000);
setColor(0, 255, 255); // aqua
delay(1000);
}

void setColor(int red, int green, int blue)
{
#ifdef COMMON_ANODE
red = 255 – red;
green = 255 – green;
blue = 255 – blue;
#endif
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}

Leave a Reply

Your email address will not be published. Required fields are marked *