Introduction
Have you ever wanted to create colorful light effects with an RGB LED but didn’t have the components handy? With Velxio, you can simulate the entire circuit and code right in your browser. In this tutorial, we’ll build a simple RGB LED color cycler that displays red, green, blue, yellow, cyan, magenta, and white in sequence. You’ll learn how to use PWM (Pulse Width Modulation) to mix colors and how to wire a common-cathode RGB LED to an Arduino Uno.
Circuit Walkthrough
Let’s start by placing the components on the Velxio canvas. You’ll need an Arduino Uno and an RGB LED. The RGB LED has four pins: one common cathode (COM) and three anodes for red (R), green (G), and blue (B).

Here’s the wiring:
- Connect the R pin of the RGB LED to Arduino pin 9 (red wire).
- Connect the G pin to Arduino pin 10 (green wire).
- Connect the B pin to Arduino pin 11 (blue wire).
- Connect the COM pin to Arduino GND (black wire).
In Velxio, you can drag wires from one pin to another. The colors of the wires in the simulation match the pin functions: red for red, green for green, blue for blue, and black for ground. This makes it easy to follow the connections.
Code Walkthrough
Now let’s write the Arduino sketch. Open the code editor in Velxio and enter the following:

// RGB LED Color Cycling
// Display different colors
const int RED_PIN = 9;
const int GREEN_PIN = 10;
const int BLUE_PIN = 11;
void setup() {
pinMode(RED_PIN, OUTPUT);
pinMode(GREEN_PIN, OUTPUT);
pinMode(BLUE_PIN, OUTPUT);
}
void setColor(int red, int green, int blue) {
analogWrite(RED_PIN, red);
analogWrite(GREEN_PIN, green);
analogWrite(BLUE_PIN, blue);
}
void loop() {
// Red
setColor(255, 0, 0);
delay(1000);
// Green
setColor(0, 255, 0);
delay(1000);
// Blue
setColor(0, 0, 255);
delay(1000);
// Yellow
setColor(255, 255, 0);
delay(1000);
// Cyan
setColor(0, 255, 255);
delay(1000);
// Magenta
setColor(255, 0, 255);
delay(1000);
// White
setColor(255, 255, 255);
delay(1000);
}
How It Works
- Pin Definitions: We define constants for the three PWM pins:
RED_PIN = 9,GREEN_PIN = 10,BLUE_PIN = 11. These pins supportanalogWrite()for PWM output. - setup(): Sets all three pins as outputs.
- setColor(): A helper function that takes three values (0-255) for red, green, and blue, and writes them to the respective pins using
analogWrite(). This creates a voltage between 0 and 5V, controlling the LED brightness. - loop(): Calls
setColor()with different combinations to produce colors. Each color is displayed for 1 second (delay(1000)).
Key Concepts
PWM (Pulse Width Modulation)
PWM is a technique where a digital pin rapidly switches between HIGH and LOW to simulate an analog voltage. The duty cycle (percentage of time HIGH) determines the perceived brightness. Arduino’s analogWrite() outputs a PWM signal with a frequency of about 490 Hz on pins 9, 10, and 11.
RGB Color Mixing
An RGB LED contains three separate LEDs (red, green, blue) in one package. By varying the brightness of each, you can create millions of colors. For example:
- Red + Green = Yellow
- Green + Blue = Cyan
- Red + Blue = Magenta
- Red + Green + Blue = White
Common Cathode vs Common Anode
This tutorial uses a common-cathode RGB LED, where the COM pin is connected to ground. To turn on a color, you apply a HIGH signal to its anode. If you have a common-anode LED, you would connect COM to VCC and use inverted logic (LOW to turn on).
Common Pitfalls and Debugging Tips
- Wrong Pin Numbers: Double-check that you’ve connected the R, G, B pins to the correct Arduino pins (9, 10, 11). A swapped wire will produce wrong colors.
- Missing Ground: The COM pin must be connected to GND. Without it, the LED won’t light.
- PWM vs Digital:
analogWrite()only works on PWM-capable pins (marked with ~ on the Uno). Using a non-PWM pin will result in only full on/off. - Delay Timing: The
delay(1000)pauses the entire program. For more responsive projects, consider usingmillis()for non-blocking timing. - Simulator Issues: If the LED doesn’t light, check the wiring in Velxio. Use the canvas toolbar to zoom in and verify connections.


Suggested Extensions
Once you have the basic color cycler working, try these enhancements:
- Fade Between Colors: Instead of jumping, use a loop to gradually change PWM values for smooth transitions.
- Button Control: Add a push button to cycle colors manually.
- Potentiometer Input: Use a potentiometer to select a color from a palette.
- Serial Control: Send color values over the serial monitor to set custom colors.
- Multiple LEDs: Chain several RGB LEDs for a light show.
To add new components, use the component picker:

If you need additional libraries, the library manager makes it easy:

Call to Action
Ready to see it in action? Open the live example on Velxio and start experimenting: RGB LED Color Cycling on Velxio. No downloads, no hardware – just pure learning. Happy tinkering!