Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Voltaat Arduino Ultimate Kit
60 min
Share

Light up beautiful colors using the RGB LED

The RGB LED has a wide range of applications, including outdoor decoration lighting, stage lighting designs, house decoration lighting, LED matrix display, and others.

Project Video

Overview

In this tutorial, we will use the RGB LED to smoothly fade from one color to the next.

Getting the Items

Arduino Uno R3 (Voltaat Version)
Get Item
RGB LED Common Cathode (3 Pack)
Get Item
1/4 Watt Resistor (20 Pack)
Get Item
Half-size Breadboard
Get Item
Jumper Wires - Male to Male (40 Pack)
Get Item

Steps

Wiring it Up

Connect the wires between the RGB led and the Arduino as shown in the image below.


 Connections from the Arduino to the breadboard:


     • Arduino pin GND → Breadboard ground line


    • Arduino pin 5V → Breadboard 5V line



 Connections from the RGB LED:


    • Red led pin→220-ohm resistor→ Arduino pin 3


     • Negative pin→ Breadboard ground line


     • Green led pin→ 220-ohm resistor → Arduino pin 5


    • Blue led pin→ 220-ohm resistor → Arduino pin 6

Coding


/*
 Voltaat learn:
 Link for full tutorial:

 Tutorial: Light up beautiful colors using the RGB LED

 The purpose of this sketch is to control the RGB LED using PWM signals and Arduino
 to modify the intensity of each LED using loops to gracefully fade from one color to the other.

 Connections from the Arduino to the breadboard:
 • Arduino pin GND → Breadboard ground line
 • Arduino pin 5V → Breadboard 5V line

 Connections from the RGB LED:
 • Red led pin→220-ohm resistor→ Arduino pin 3
 • Negative pin→ Breadboard ground line
 • Green led pin→ 220-ohm resistor → Arduino pin 5
 • Blue led pin→ 220-ohm resistor → Arduino pin 6

*/



//LEDs must be connected to the PWM pins of the Arduino to control them
//Red led is connected to arduino pin 3
#define RED  3
//Green led is connected to arduino pin 5
#define GREEN  5
//Blue led is connected to arduino pin 6
#define BLUE  6

//Commands inside void setup run once
void setup() {
 //Set RED,GREEN,BLUE pins as output
 pinMode(RED, OUTPUT);
 pinMode(GREEN, OUTPUT);
 pinMode(BLUE, OUTPUT);
}

//Commands inside void loop run forever
void loop() {

 //Fade from RED to GREEN
 for (int i = 0; i < 255; i++) {
   //Turn RED LED initially OFF
   analogWrite(RED, 255 - i);
   //Turn GREEN LED initially ON
   analogWrite(GREEN, i);
   //Wait for 3 ms
   delay(3);
 }

 //Fade from GREEN to BLUE
 for (int i = 0; i < 255; i++) {
   //Turn GREEN LED initially OFF
   analogWrite(GREEN, 255 - i);
   //Turn BLUE LED initially ON
   analogWrite(BLUE, i);
   //Wait for 3 ms
   delay(3);
 }

 //Fade from BLUE to RED
 for (int i = 0; i < 255; i++) {
   //Turn BLUE LED initially OFF
   analogWrite(BLUE, 255 - i);
   //Turn RED LED initially ON
   analogWrite(RED, i);
   //Wait for 3 ms
   delay(3);
 }


}

Testing it Out

When you upload the code to your Arduino, you will notice the RGB LED rapidly fading from red to green, then to blue, and again back to red; the colors are so beautiful!

Resources

No items found.