RGB LEDs (Common Anode / Common Cathode)

An RGB LED is a single output component that contains three separate light-emitting diodes—Red, Green, and Blue—housed within a single 4-pin enclosure.

Actuators7 blocksMicroPythonC++
RGB LED

At a glance

Pins and properties exactly as the circuit editor and simulator define this part. The text below explains how to use them.

Pinout

Pinout of the RGB LED, drawn as in the circuit editor. Select a label to see that pin in the table below.

Pins

Pins of this part
PinLabelType
RRSignal in
K-Bidirectional
GGSignal in
BBSignal in

Properties

What you can change in the Property Inspector.

Properties of this part
PropertyRange or choicesDefault
TypeCommon Cathode (−), Common Anode (+)Common Cathode (−)
Max If0.005 to 0.05 A0.02 A

An RGB LED is a single output component that contains three separate light-emitting diodes—Red, Green, and Blue—housed within a single 4-pin enclosure. By using Pulse Width Modulation (PWM) to vary the duty cycle (intensity) of each color channel, you can mix colors to display millions of custom light shades.


1. Schematic Symbol

Three diodes (Red, Green, Blue) sharing a single common cathode bus — matching how the OMS component itself is wired internally (see the real limitation noted in Section 7):

R G B K

2. Common Cathode (CC) vs. Common Anode (CA) Wiring

RGB LEDs are manufactured in two internal electrical wiring layouts, which determine how you control them in code:

  • Common Cathode (CC):
    • The negative terminals of all three internal LEDs are tied together to a single Common Ground Pin.
    • Wiring: Connect the Common pin to the microcontroller's GND rail. Connect the R, G, and B pins to digital PWM pins through individual series resistors.
    • Control Logic: Active-High. Writing a 255 (100% duty cycle) turns a channel fully ON; writing 0 turns it OFF.
  • Common Anode (CA):
    • The positive terminals of all three internal LEDs are tied together to a single Common VCC Pin.
    • Wiring: Connect the Common pin to the microcontroller's 5V or 3.3V power rail. Connect the R, G, and B pins to digital PWM pins through individual series resistors.
    • Control Logic: Active-Low (Current Sinking). To turn an LED ON, you must pull its pin LOW. Writing 0 turns a channel fully ON; writing 255 turns it OFF. The OMS block library automatically handles this inversion once you configure the LED type.

3. Layout & Pin Map

A standard physical through-hole RGB LED contains 4 pins of varying lengths:

  • Pin 1 (Red): Controls the Red LED channel.
  • Pin 2 (Common): The longest physical lead. Connected to VCC (Common Anode) or GND (Common Cathode).
  • Pin 3 (Green): Controls the Green LED channel.
  • Pin 4 (Blue): Controls the Blue LED channel.

Breadboard Placement Guide:

  1. Orient the RGB LED so the flat side of the dome faces you.
  2. Insert the LED into the breadboard with all 4 leads spanning 4 separate rows.
  3. The longest lead (Pin 2, Common) should go into row +. This is the easiest way to identify it.
  4. Counting from the longest lead: the lead to the left is Red (Pin 1), the first lead to the right is Green (Pin 3), and the second lead to the right is Blue (Pin 4).
  5. Connect each colour pin (Red, Green, Blue) to a separate PWM-capable GPIO pin on your microcontroller, each through its own series current-limiting resistor.
  6. Connect the Common pin to GND (for CC) or to the 3.3V / 5V power rail (for CA).

4. Core Calculations & Critical Warnings

[!IMPORTANT] Use Three Separate Resistors: You must place a current-limiting resistor on each of the Red, Green, and Blue control lines individually. Do not place a single resistor on the Common pin.

  • Why? If you share a single resistor on the Common pin, turning on multiple channels (e.g. Red + Green to make Yellow) splits the current between the two LEDs. Because Red has a lower forward voltage (~2.2V) than Green (~3.2V), current will flow disproportionately through the Red channel, skewing the mixed color toward red instead of a clean Yellow.

Real per-channel voltages (OMS's RGB LED component is modeled on a real Kitronik 5mm common-cathode RGB LED — Red is an AlGaInP die at ~1.9–2.5V, Green/Blue are InGaN dies at ~2.9–3.5V. Green and Blue genuinely overlap here — that's the real datasheet, not a typo):

  • Calculating Resistors:

    RRed=Vcc−2.2VIfR_{Red} = \frac{V_{cc} - 2.2\text{V}}{I_f} (typically 220 Ω220\ \Omega to 330 Ω330\ \Omega)

    • RGreen=Vcc−3.2VIfR_{Green} = \frac{V_{cc} - 3.2\text{V}}{I_f} (typically 100 Ω100\ \Omega to 150 Ω150\ \Omega)

    • RBlue=Vcc−3.2VIfR_{Blue} = \frac{V_{cc} - 3.2\text{V}}{I_f} (typically 100 Ω100\ \Omega to 150 Ω150\ \Omega)


5. Component Properties (Property Inspector)

When you select an RGB LED on the canvas, you can modify the following parameters in the Property Inspector panel:

  • Type (type): Switches the simulated diode direction to match how you've wired the Common pin (K) — this is what actually makes Common Anode wiring behave correctly in the circuit simulation (see Section 7).
    • Default: CC (Common Cathode)
    • Options: CC (Common Cathode −), CA (Common Anode +)
  • Max Forward Current (If_max): Sets the maximum safe forward current (in amperes) allowed for any single internal LED channel before burnout.
    • Default: 0.02 A (20 mA)
    • Range: 0.005 A to 0.05 A (5 mA to 50 mA) (step size 0.005 A)

6. Supported Blockly Blocks

Drawing the blocks…

7. Simulator Behavior

  • Real-time Mixing: Active channels blend on the canvas as a live rgb(r,g,b) color, each channel's brightness driven directly by its simulated forward current (not a CSS-side blend of separate PWM duty values — the component computes one combined RGB color from all three channels' real current levels).
  • CC/CA is a real circuit setting, not just a code-generation choice: the RGB LED component has its own Type property (Property Inspector, Section 5) that switches the simulated diode direction to match — Common Cathode ties all 3 diode cathodes to K (channel pins sink current when driven HIGH); Common Anode reverses it, tying all 3 diode anodes to K (channel pins sink current from K when driven LOW). Set this to match how you've wired K (to GND for CC, to VCC for CA) — it's independent of the rgb_led_setup Blockly block's own TYPE dropdown, which separately controls the generated C++/Python driver code for real hardware. Keep both settings consistent (component Type + block TYPE) so the simulated behavior matches what the generated code will actually do on a real board.
RGB LEDs (Common Anode / Common Cathode) — OMS Parts