lewiskell
Published © GPL3+

Common Anode RGB LED

A short, simple project to make a common anode RGB LED illuminate the colours of the visual light spectrum.

BeginnerFull instructions provided6,493
Common Anode RGB LED

Things used in this project

Hardware components

Arduino Leonardo
Arduino Leonardo
In this project I used the ProMicro, a small clone of the Leonardo.
×1
Resistor 220 ohm
Resistor 220 ohm
×3
RGB Diffused Common Anode
RGB Diffused Common Anode
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Story

Read more

Schematics

CA_RGB_LED

Breadboard diagram for LED circuit

Code

CA_RGB_LED

Arduino
// LEDs must be connected to arduino PWM pins - see board pinout
#define RED  6   // pin that red led is connected to    
#define GREEN  5 // pin that green led is connected to     
#define BLUE  3  // pin that blue led is connected to    
#define DELAY  20  // internal delay in ms

void setup() { 
  // LED connection pins to be set as an output
  pinMode(RED, OUTPUT);
  pinMode(GREEN, OUTPUT);
  pinMode(BLUE, OUTPUT);
}

void loop() {
  // fade from red to green
  for(int i=0; i<255; i++) {
    analogWrite(RED, i); // red initially ON
    analogWrite(GREEN, 255-i); // green initially OFF
    analogWrite(BLUE, 255); // blue OFF
    delay(DELAY); // wait before next transition
  }

  // fade from green to blue
  for(int i=0; i<255; i++) {
    analogWrite(RED, 255); // red OFF
    analogWrite(GREEN, i); // green initially ON
    analogWrite(BLUE, 255-i); // blue initially OFF
    delay(DELAY);
  }

  // fade from blue to red
  for(int i=0; i<255; i++) {
    analogWrite(RED, 255-i); // red initially OFF
    analogWrite(GREEN, 255); // green OFF
    analogWrite(BLUE, i); // blue initially ON
    delay(DELAY);
  }
}

Credits

lewiskell

lewiskell

0 projects • 2 followers

Comments