Wiring guide

How to wire an RGB LED to an Arduino Nano

To wire an RGB LED to an Arduino Nano, connect R to pin 9, G to pin 10, B to pin 11 and C to GND. Each color has its own 220 ohm resistor, so every pin drives only a few milliamps at 5 V; this is a common cathode part, so HIGH lights a color. The sketch below uses no library beyond what the board includes. It steps through red, green, blue and white, printing the name of each.

  • 5 V logic
  • Library: none
  • 4 wires, 3 helper parts
Arduino Nano · RGB LEDlive0.000 s 0.00x
Click to open it in the editor
The circuit itself, running on the simulator with the sketch below. Press what can be pressed; click anything else to open it in the editor.
Pin to pin

RGB LED to Arduino Nano wiring table

Every wire in the circuit above, with the part’s pin names and the board’s own labels. The wire colors are the ones the circuit uses; on a real bench any colors work.

RGB LED pinArduino Nano pinWire colorWhy
R (red)pin 9, through R1 (220 Ω)redThe red anode, through its own 220 ohm resistor. The pin must be able to do PWM.
G (green)pin 10, through R2 (220 Ω)greenThe green anode, through its own resistor.
B (blue)pin 11, through R3 (220 Ω)blueThe blue anode, through its own resistor.
C (common cathode)GNDgrayThe longest leg joins all three cathodes and goes to ground.
Three 220 ohm resistorsOne in each color leadn/aEach color is its own LED and needs its own resistor.

Helper parts

The extra parts in the circuit above, and where their wires go:

FromToWire color
R1 (220 Ω) pin 19red
R2 (220 Ω) pin 110green
R3 (220 Ω) pin 111blue
Voltage

Power and logic levels for RGB LED and Arduino Nano

Logic level

The Arduino Nano’s pins are 5 V logic. A 5 V part can drive them directly; a part whose signal pins are limited to 3.3 V needs a level shifter.

This pair

Each color is a separate LED behind its own 220 ohm resistor, so each pin drives only a few milliamps at 5 V. This is a common cathode part: HIGH lights a color. A common anode part has its long leg on 5V and lights on LOW, so analogWrite values must be inverted.

Pins to leave alone

A6 and A7 are analog only: pinMode(A6, OUTPUT) does nothing and digitalRead(A7) is not there to call. D0 and D1 are the USB serial port.

The sketch

The working code for the Arduino Nano

Library: none, the sketch mixes the colors with analogWrite(). This is the sketch the circuit above runs.

RGB LED on Arduino Nano pin 9, pin 10, pin 11
const int RED_PIN = 9;     // pin 9
const int GREEN_PIN = 10;   // pin 10
const int BLUE_PIN = 11;    // pin 11

void setColor(int r, int g, int b, const char* name) {
  analogWrite(RED_PIN, r);
  analogWrite(GREEN_PIN, g);
  analogWrite(BLUE_PIN, b);
  Serial.println(name);
  delay(400);
}

void setup() {
  Serial.begin(9600);
  pinMode(RED_PIN, OUTPUT);
  pinMode(GREEN_PIN, OUTPUT);
  pinMode(BLUE_PIN, OUTPUT);
}

void loop() {
  setColor(255, 0, 0, "Red");
  setColor(0, 255, 0, "Green");
  setColor(0, 0, 255, "Blue");
  setColor(255, 255, 255, "White");
}
Output

What you should see

The LED shows red, then green, then blue, then white, about 400 ms each, and starts again. The serial monitor, at 9600 baud, prints the name of the color as it is set.

If the colors look inverted, the part is common anode: its long leg goes to the supply, and the values in the sketch must be inverted.

The serial monitor prints this, recorded from the circuit above running for two seconds:

Red
Green
Blue
White
Red
Green
Pitfalls

Common mistakes wiring an RGB LED to an Arduino Nano

Using one resistor for all three colors

The three LEDs have different voltage drops, so on one shared resistor the color that drops least takes most of the current and the mix looks wrong. Give each color its own resistor.

Mixing up common cathode and common anode

A common cathode part has its long leg on ground and lights when a pin goes HIGH. A common anode part has its long leg on 5V and lights when a pin goes LOW. With the wrong type everything looks inverted: white when you wanted off.

Choosing pins without PWM

analogWrite() only makes a smooth brightness on pins with PWM hardware. On a pin without it the color is either fully on or fully off. On the Arduino Nano these three pins are PWM pins.

Build your own RGB LED project

Open this circuit in the editor, change the wiring or the code, and keep your version in a free account.