Devices & Components
Arduino Uno Rev3
RGB Diffused Common Cathode
Breadboard (generic)
Jumper wires (generic)
Software & Tools
Arduino IDE
Project description
Code
Code
c_cpp
This is the code for interfacing Arduino Uno with RGB led.
1// Interfacing RGB led with Arduino Uno 2int redPin = 5;// Red pin to digital pin 5 of arduino 3int greenPin = 12;// Green pin to digital pin 12 of arduino 4int bluePin = 3;// Blue pin to digital pin 3 of arduino 5 6//uncomment this line if using a Common Anode LED 7//#define COMMON_ANODE 8 9void setup() 10{ 11 pinMode(redPin, OUTPUT); 12 pinMode(greenPin, OUTPUT); 13 pinMode(bluePin, OUTPUT); 14} 15 16void loop() 17{ 18 setColor(255, 0, 0); // red 19 delay(1000); 20 setColor(0, 255, 0); // green 21 delay(1000); 22 setColor(0, 0, 255); // blue 23 delay(1000); 24 setColor(255, 255, 0); // yellow 25 delay(1000); 26 setColor(80, 0, 80); // purple 27 delay(1000); 28 setColor(0, 255, 255); // aqua 29 delay(1000); 30} 31 32void setColor(int red, int green, int blue) 33{ 34 #ifdef COMMON_ANODE 35 red = 255 - red; 36 green = 255 - green; 37 blue = 255 - blue; 38 #endif 39 analogWrite(redPin, red); 40 analogWrite(greenPin, green); 41 analogWrite(bluePin, blue); 42} 43
Code
c_cpp
This is the code for interfacing Arduino Uno with RGB led.
1// Interfacing RGB led with Arduino Uno 2int redPin = 5;// Red pin to 3 digital pin 5 of arduino 4int greenPin = 12;// Green pin to digital pin 12 of 5 arduino 6int bluePin = 3;// Blue pin to digital pin 3 of arduino 7 8//uncomment 9 this line if using a Common Anode LED 10//#define COMMON_ANODE 11 12void setup() 13{ 14 15 pinMode(redPin, OUTPUT); 16 pinMode(greenPin, OUTPUT); 17 pinMode(bluePin, 18 OUTPUT); 19} 20 21void loop() 22{ 23 setColor(255, 0, 0); // red 24 delay(1000); 25 26 setColor(0, 255, 0); // green 27 delay(1000); 28 setColor(0, 0, 255); // 29 blue 30 delay(1000); 31 setColor(255, 255, 0); // yellow 32 delay(1000); 33 34 setColor(80, 0, 80); // purple 35 delay(1000); 36 setColor(0, 255, 37 255); // aqua 38 delay(1000); 39} 40 41void setColor(int red, int green, int 42 blue) 43{ 44 #ifdef COMMON_ANODE 45 red = 255 - red; 46 green = 255 - 47 green; 48 blue = 255 - blue; 49 #endif 50 analogWrite(redPin, red); 51 52 analogWrite(greenPin, green); 53 analogWrite(bluePin, blue); 54} 55
Downloadable files
Image
Image
Image
Circuit diagram
This is the circuit diagram for interfacing Arduino Uno with RGB led.
Circuit diagram

Pin diagram
Pin diagram of RGB led
Pin diagram

Image
Image
Image

Image
Image
Image
Pin diagram
Pin diagram of RGB led
Pin diagram

Circuit diagram
This is the circuit diagram for interfacing Arduino Uno with RGB led.
Circuit diagram

Comments
Only logged in users can leave comments