General Pinout of an RGB LED

All RGB LEDs come with 4 pins: one each for the red, green, and blue LEDs, and one
“common” pin that might have + or - polarity. It is not easy to tell by inspection
which variety you might have. The best way is to test it (see below).

RGB Led (the long pin might be either + or -)

Common Anode RGB LEDs

This type of RGB LED is more common, so if you have no knowledge about which
type of RGB LED you have, it’s reasonably likely that it’s a common anode type.
In this case, use the circuit below, where the long (common) pin is
attached to the red (power) rail of your breadboard.

Circuit for an RGB common anode LED

In the circuit shown above, the 3 shorter pins are attached to pins 9,
10, and 11 on an Arduino Nano. Why these 3? Because:

  1. They are all “special” digital output pins, capable of producing voltages
    between 0 and 5v, unlike many of the other digital output pins; and
  2. They are immediately next to one another, making it easy to attach the
    3 legs of the RGB LED to them.

You can check which pins of your Arduino board are capable of producing voltages
intermediate between 0 and 5V by looking at their “pinout” diagrams. Look for
pins labelled PWM (which means “pulse width modulation”). A list of
pinout diagrams for common Arduino boards is given here.

Common Cathode RGB LEDs

If your RGB LED doesn’t work with the circuit above, then it may be a
common cathode LED, in which case you should use the circuit below, where the
long (common) pin is attached to any GND pin on the Arduino, or to
the GND rail or your breadboard:

| |