What is an RGB LED and What Are We Building Here?
An RGB LED is a special type of LED that contains three LEDs inside one package — Red, Green, and Blue.
Using these three colours, the Arduino can blend them at different brightness levels to produce hundreds of colours like yellow, cyan, purple, pink, white, sky-blue, etc.
In this example, we are using a Common-Cathode RGB LED, which means:
- All three LEDs share one common negative (–) pin
- The individual colour pins (R, G, B) must be connected through 220Ω resistors
- The Arduino controls brightness using PWM pins
- Red → D3
- Green → D5
- Blue → D6
This forms the basis for colour-mixing projects used in IoT, indicators, robots, and UI feedback systems.
Below, you can see the circuit wiring diagram, the mBlock representation, and the equivalent Arduino IDE code.
Finally, you can flash the firmware directly from this page using ExaSub’s online uploader — no Arduino IDE installation required.
Arduino IDE CODE
// RGB LED with Arduino Nano
// Common Cathode RGB LED
// R -> D3, G -> D5, B -> D6
int redPin = 3;
int greenPin = 5;
int bluePin = 6;
void setup() {
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop() {
setColor(255, 0, 0); // Red
delay(800);
setColor(0, 255, 0); // Green
delay(800);
setColor(0, 0, 255); // Blue
delay(800);
setColor(255, 255, 0); // Yellow (Red + Green)
delay(800);
setColor(80, 0, 255); // Purple
delay(800);
setColor(0, 255, 255); // Cyan (Green + Blue)
delay(800);
setColor(255, 255, 255); // White
delay(800);
setColor(0, 0, 0); // Off
delay(800);
}
// Function to mix RGB
void setColor(int r, int g, int b) {
analogWrite(redPin, 255 - r); // common cathode → invert logic
analogWrite(greenPin, 255 - g);
analogWrite(bluePin, 255 - b);
}
Mblock Code

Flash Arduino UNO/Nano Directly From Browser Click on Button
Note: Nano with old bootloader is not supported. Use the code with the arduino IDE for the Nano with old bootloader.

Leave a Reply