RGB LED Color Changer

by Supernova09 in Circuits > Arduino

124 Views, 1 Favorites, 0 Comments

RGB LED Color Changer

ChatGPT Image Jun 25, 2026, 11_41_37 PM.png
RGB LED Color Changer #IoT #ArduinoIDE #arduino #arduinoproject #schoolprojects #circuit

Have you ever wondered how RGB LEDs create millions of different colors? In this beginner-friendly Arduino project, we'll learn how to control an RGB LED using PWM (Pulse Width Modulation) and automatically cycle through multiple colors.

This project is perfect for beginners who want to understand:

  1. RGB LEDs
  2. PWM signals
  3. Color mixing
  4. Arduino programming fundamentals

By the end of this tutorial, your RGB LED will smoothly change between Red, Green, Blue, Yellow, Cyan, Magenta, and White.

Supplies

Gather the Components:

QuantityComponent

1 Arduino Uno

1 RGB LED (Common Cathode)

1 220Ω Resistors

1 Breadboard

Several Jumper Wires

1 USB Cable

Understanding RGB LEDs

An RGB LED contains three LEDs inside a single package:

  1. Red
  2. Green
  3. Blue

By adjusting the brightness of each LED, different colors can be produced.

Example Color Mixing



Identify RGB LED Pins

For a Common Cathode RGB LED:

Flat Side Facing You

Pin 1 → Red
Pin 2 → Common Cathode (-)
Pin 3 → Green
Pin 4 → Blue

Note: RGB LED pinouts may vary by manufacturer. Check your LED datasheet if colors don't behave correctly.

Circuit Diagram Arduino UNO

Screenshot 2026-06-25 234058.png

Arduino UNO


D11 ---- 220Ω ---- Red Pin


D10 ---- 220Ω ---- Green Pin


D9 ----- 220Ω ---- Blue Pin


GND ---------------- Common Cathode

Install Arduino IDE

If not already installed:

  1. Download Arduino IDE.
  2. Install it on your computer.
  3. Connect Arduino Uno using USB.


Configure Arduino IDE

Open Arduino IDE and select:

Tools → Board → Arduino Uno

Then select:

Tools → Port → COM Port

Choose the port corresponding to your Arduino.

Upload the Code

Paste the following code into Arduino IDE.


// RGB LED Color Changer

const int RED = 11;
const int GREEN = 10;
const int BLUE = 9;

void setup()
{
pinMode(RED, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(BLUE, 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); // Magenta
delay(1000);

setColor(255, 255, 255); // White
delay(1000);
}

void setColor(int redValue, int greenValue, int blueValue)
{
analogWrite(RED, redValue);
analogWrite(GREEN, greenValue);
analogWrite(BLUE, blueValue);
}

Click:

Verify ✓

Then:

Upload →

Wait until the upload completes.

Observe the Output

18399f3a-aa5f-4aac-911a-540f2977b18e.png

How PWM Creates Colors

The function:


analogWrite(pin, value);

controls LED brightness.

Range:

0 = OFF
255 = Maximum Brightness

Example:


setColor(255, 100, 0);

Produces an orange color by mixing:

  1. Full Red
  2. Medium Green
  3. No Blue


Create Your Own Colors

Try these values:

Orange


setColor(255, 80, 0);

Purple


setColor(150, 0, 255);

Pink


setColor(255, 20, 147);

Sky Blue


setColor(0, 191, 255);

Warm White


setColor(255, 180, 100);

Experiment and discover your favorite colors.

Smooth Color Fading

Replace the loop with this code:


for(int i=0;i<=255;i++)
{
analogWrite(RED,i);
delay(10);
}

This creates a smooth fade effect instead of sudden color changes.

Troubleshooting

RGB LED Doesn't Light

  1. Verify wiring.
  2. Check resistor connections.
  3. Confirm common cathode is connected to GND.

Wrong Colors Appear

  1. RGB LED pin order may differ.
  2. Swap Red, Green, and Blue connections.

Upload Fails

  1. Verify COM port.
  2. Verify Arduino Uno board selection.


Future Improvements

You can enhance this project by adding:

  1. Potentiometers for manual color control
  2. Bluetooth control using ESP32
  3. IR remote control
  4. Sound-reactive color effects
  5. Color fading animations
  6. Smart home lighting projects


Conclusion

You have successfully built an RGB LED Color Changer using Arduino Uno. This project introduces PWM control, RGB color mixing, and Arduino programming concepts that are widely used in lighting systems, IoT devices, decorative electronics, and smart automation projects.

Happy Making! 🚀🔴🟢🔵