RGB LED Control Using Arduino | Beginner Arduino RGB LED Project
RGB LED Control Using Arduino
RGB LED Control Using Arduino is one of the best beginner-friendly Arduino projects to understand PWM pins, color mixing, and LED brightness control. In this project, we will learn how to connect an RGB LED with Arduino and generate different colors using simple Arduino code.

What is an RGB LED?
An RGB LED is a special type of LED that contains three LEDs inside one package: Red, Green, and Blue. By controlling the brightness of these three colors, we can create many different colors such as yellow, cyan, purple, white, orange, and more.
Types of RGB LED
There are mainly two types of RGB LEDs:
- Common Cathode RGB LED: The common pin is connected to GND.
- Common Anode RGB LED: The common pin is connected to 5V.
In this tutorial, we are using a common cathode RGB LED. If you are using a common anode RGB LED, the code logic will be slightly reversed.
Components Required
| Component | Quantity |
|---|---|
| Arduino Uno | 1 |
| RGB LED | 1 |
| 220Ω Resistors | 3 |
| Breadboard | 1 |
| Jumper Wires | As Required |
| USB Cable | 1 |
RGB LED Pin Configuration
A normal 4-pin RGB LED has one common pin and three color pins. The longest pin is usually the common pin.
| RGB LED Pin | Connection |
|---|---|
| Red Pin | Arduino PWM Pin 9 through 220Ω resistor |
| Green Pin | Arduino PWM Pin 10 through 220Ω resistor |
| Blue Pin | Arduino PWM Pin 11 through 220Ω resistor |
| Common Cathode Pin | GND |
Circuit Connections
- Connect the common cathode pin of the RGB LED to Arduino GND.
- Connect the red pin of RGB LED to Arduino pin 9 using a 220Ω resistor.
- Connect the green pin of RGB LED to Arduino pin 10 using a 220Ω resistor.
- Connect the blue pin of RGB LED to Arduino pin 11 using a 220Ω resistor.
Why Use PWM Pins?
Arduino PWM pins allow us to control LED brightness using values from 0 to 255. A value of 0 means the LED is OFF, and 255 means the LED is fully ON. By changing PWM values for red, green, and blue colors, we can create different color combinations.
Arduino Code for RGB LED Control
int redPin = 9;
int greenPin = 10;
int bluePin = 11;
void setup() {
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop() {
setColor(255, 0, 0); // Red
delay(1000);
setColor(0, 255, 0); // Green
delay(1000);
setColor(0, 0, 255); // Blue
delay(1000);
setColor(255, 255, 0); // Yellow
delay(1000);
setColor(0, 255, 255); // Cyan
delay(1000);
setColor(255, 0, 255); // Purple
delay(1000);
setColor(255, 255, 255); // White
delay(1000);
setColor(0, 0, 0); // OFF
delay(1000);
}
void setColor(int redValue, int greenValue, int blueValue) {
analogWrite(redPin, redValue);
analogWrite(greenPin, greenValue);
analogWrite(bluePin, blueValue);
}
How the Code Works
In this Arduino RGB LED project, pins 9, 10, and 11 are used as PWM output pins. These pins control the brightness of red, green, and blue colors. The setColor() function receives three values: red, green, and blue. Each value can be between 0 and 255.
For example, setColor(255, 0, 0) turns ON only the red LED, so the RGB LED glows red. Similarly, setColor(255, 255, 0) turns ON red and green together, which creates yellow color.
RGB Color Combination Table
| Color | Red Value | Green Value | Blue Value |
|---|---|---|---|
| Red | 255 | 0 | 0 |
| Green | 0 | 255 | 0 |
| Blue | 0 | 0 | 255 |
| Yellow | 255 | 255 | 0 |
| Cyan | 0 | 255 | 255 |
| Purple | 255 | 0 | 255 |
| White | 255 | 255 | 255 |
| OFF | 0 | 0 | 0 |
Common Anode RGB LED Code Note
If you are using a common anode RGB LED, connect the common pin to 5V. In this case, the PWM values work in reverse. For example, 0 means fully ON and 255 means OFF.
// For common anode RGB LED, use this inside setColor function:
analogWrite(redPin, 255 - redValue);
analogWrite(greenPin, 255 - greenValue);
analogWrite(bluePin, 255 - blueValue);
Applications of RGB LED with Arduino
- Arduino mood lamp project
- Smart home indicator light
- Color changing decoration light
- Temperature-based color indicator
- IoT notification light
- DIY gaming setup lighting
- Arduino learning projects for beginners
Troubleshooting Tips
| Problem | Possible Solution |
|---|---|
| RGB LED not glowing | Check the common pin connection and Arduino GND. |
| Wrong color is showing | Check red, green, and blue pin connections. |
| LED is too dim | Check resistor value and PWM values in code. |
| LED gets hot | Use proper current-limiting resistors. |
| Common anode LED not working properly | Reverse the PWM logic in the code. |
Safety Tips
- Always use resistors with RGB LED pins.
- Do not connect LED pins directly to 5V without a resistor.
- Check the RGB LED type before making connections.
- Use Arduino PWM pins for smooth brightness control.
- Disconnect USB power before changing circuit connections.
Frequently Asked Questions
Can I use any Arduino board for this RGB LED project?
Yes, you can use Arduino Uno, Nano, Mega, or any compatible board that has PWM pins.
Why do we use three resistors with an RGB LED?
Each color inside the RGB LED needs current limiting. Using one resistor for each color pin provides better protection and stable brightness.
Can I control RGB LED brightness using Arduino?
Yes, you can control brightness using Arduino PWM pins and the analogWrite() function.
What is the difference between common anode and common cathode RGB LED?
In a common cathode RGB LED, the common pin is connected to GND. In a common anode RGB LED, the common pin is connected to 5V.
Conclusion
RGB LED Control Using Arduino is a simple and useful project for beginners who want to learn about PWM, color mixing, and Arduino output control. By changing the red, green, and blue values in the code, you can create many beautiful colors and use this concept in smart lighting, indicators, decorative lights, and IoT projects.
If you are learning Arduino step by step, this RGB LED project is a great next project after basic LED blinking.