Light up beautiful colors using the RGB LED 🟥 🟩 🟦

Do you know how your gaming mouse lights up in multiple bright colors that change over time?


Well, it uses a special LED called the RGB LED, which is similar to a regular LED but it is made up of three smaller ones. It is called an RGB LED because it has three LEDs with three colors: red, green, and blue.


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

Overview


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


RGB LEDs are classified into two types: common anode LEDs and common cathode LEDs. For this tutorial, we will use the common cathode.


In the RGB Common Cathode LED, the three LEDs share the same GND connection (cathode). and there are now still three pins for each small LED. That’s why it has four pins.


You can light up red, green, or blue light with an RGB LED. You can also light up any other color by adjusting the intensity of each LED to combine colors together.


Let's find out more!

 

Getting the items


For this project you will need the following components: 

Sale Off
Voltaat Arduino Uno R3 (Voltaat Version)
45 QAR
Sale Off
Voltaat RGB LED Common Cathode (3 Pack)
1 QAR
Sale Off
Voltaat 1/4 Watt Resistor (20 Pack)
2 QAR

Make sure you also have a breadboard and jumper wires to connect everything together

Sale Off
Voltaat Full-size Breadboard
20 QAR
Sale Off
Voltaat Jumper Wires - Male to Male (40 Pack)
10 QAR

Wiring it up


To set up the RGB LED in the correct way, follow the instructions below. The image demonstrates how to connect the wires between the RGB LED and the Arduino. Once the RGB LED and the Arduino are connected to each other, connect the Arduino to your computer using the USB cable.


The pins should be connected in the following order: Blue, Green, Cathode, and Red, with the LED facing you and the cathode (the longest pin) being the second from the right.

 

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


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. It is very easy and amazing. Let’s see!


/*
Voltaat learn (https://www.voltaat.com/pages/voltaat-learn)
Link for full tutorial: https://bit.ly/3MMJvEv

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 


Arduino Code

Fritzing Wiring file

Related Tutorials


Have you ever wondered how your TV or air conditioner remote works? This is exactly what we will discover in this tutorial.


LCDs are used in a range of everyday applications, including the automobile radio and the house air conditioning remote. They display data and let you control it through menus.


In this tutorial, we will use the Arduino to read the resistance of an LDR and detect darkness. This project may be expanded to control an LED to turn on when the light goes out and off when it comes back, similar to how a street light works!