RGB LED Interfacing With Arduino
RGB LED Interfacing With Arduino
This is a basic tutorial for using Common Anode RGB LED Strip, PWM, and switch. By the
end, you will have single switch to control colors of the LED strip. Connect the LED’s anode
lead to +12V and connect the 3 RGB cathode leads to digital pins 9, 10, 11 through ULN2003
respectively.
To drive complete RGB LED Strip we have used ULN2003 as a driver circuit, LED strip works
at 12V. You can combine ULN2003 driver outputs to get more current.
RGB LED Arduino Interfacing Circuit
//
=========================================================================
// circuits4you.com
//
=========================================================================
int color=0;
//
=========================================================================
// SETUP
//
=========================================================================
void setup() {
pinMode(BLUEledPin, OUTPUT);
pinMode(REDledPin, OUTPUT);
pinMode(GREENledPin, OUTPUT);
pinMode(buttonPin, INPUT);
//
=========================================================================
// LOOP
//
=========================================================================
void loop(){
buttonState = digitalRead(buttonPin);
if (buttonState == LOW) {
delay(300);
color++;
if(color>10)
{color=0;}
}
//Set different color values refer HTML Color codes
switch (color)
case 0:
SetColor(255,0,0);
break;
case 1:
SetColor(255,255,0);
break;
case 2:
SetColor(0,0,255);
break;
case 3:
SetColor(128,128,20);
break;
case 4:
SetColor(0,255,255);
break;
case 5:
SetColor(55,100,100);
break;
case 6:
SetColor(0x00,0xA8,0xA9);
break;
case 7:
SetColor(0xCC,0x66,0x66);
break;
case 8:
SetColor(0x12,0xA2,0x7E);
break;
case 9:
SetColor(0xF0,0x80,0x32);
break;
case 10:
SetColor(0x30,0xFF,0xFF);
break;
//
=========================================================================
//
=========================================================================
analogWrite(REDledPin,R);
analogWrite(GREENledPin,G);
analogWrite(BLUEledPin,B);
}
Results
Press switch and see that we have around ten different colors; You can change the color using
SetColor(R,G,B). try different values of RGB.
Related