Built-in project · Arduino Uno R3

RGB colors on pins 11, 10 and 9, on an Arduino Uno

An RGB LED with red on pin 11, green on 10 and blue on 9, each through 220 ohm: analogWrite shows seven colors in turn and names each one. The whole build, an Arduino Uno and 4 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.

Teaching? Assign it to your class in one click.

Beginner Runs in your browser. Free, and no account needed.

RGB colors on pins 11, 10 and 9 · Arduino Uno R3live0.000 s 0.00x
Click to open it in the editor
The circuit itself, running here on the simulator. Press what can be pressed; click anything else to open it in the editor.

The code

The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.

sketch.ino · Arduino Uno R3
// An RGB LED on pins 11, 10 and 9: seven colors, one after another.
//
//   pin 11 -> 220 ohm -> red leg      pin 10 -> 220 ohm -> green leg
//   pin 9  -> 220 ohm -> blue leg     the long leg (common cathode) -> GND
//
// analogWrite() sets each color from 0 to 255. Mixing them makes the rest:
// red and green make yellow, green and blue cyan, red and blue magenta.

const int RED_PIN = 11;
const int GREEN_PIN = 10;
const int BLUE_PIN = 9;

struct Color {
  const char *name;
  uint8_t r, g, b;
};

const Color COLORS[] = {
    {"red", 255, 0, 0},     {"green", 0, 255, 0},   {"blue", 0, 0, 255},     {"yellow", 255, 255, 0},
    {"cyan", 0, 255, 255},  {"magenta", 255, 0, 255}, {"white", 255, 255, 255},
};

void setup() {
  pinMode(RED_PIN, OUTPUT);
  pinMode(GREEN_PIN, OUTPUT);
  pinMode(BLUE_PIN, OUTPUT);
  Serial.begin(9600);
  Serial.println("Mokxi Uno: RGB LED on pins 11, 10 and 9");
}

void loop() {
  for (const Color &c : COLORS) {
    analogWrite(RED_PIN, c.r);
    analogWrite(GREEN_PIN, c.g);
    analogWrite(BLUE_PIN, c.b);
    Serial.println(c.name);
    delay(1000);
  }
}

Parts list

6 parts, plus the jumper wires. Every one is in the editor's parts bin.

How it is wired

7 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.

  • Arduino Uno R3 pin 11; Resistor, 220 Ω (3) pin 1
  • Arduino Uno R3 pin 10; Resistor, 220 Ω (2) pin 1
  • Arduino Uno R3 pin 9; Resistor, 220 Ω (1) pin 1
  • Ground: Arduino Uno R3 pin GND; RGB LED pin C
  • RGB LED pin R; Resistor, 220 Ω (3) pin 2
  • RGB LED pin G; Resistor, 220 Ω (2) pin 2
  • RGB LED pin B; Resistor, 220 Ω (1) pin 2

Change it and keep it

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