Arduino RGB LED Colour Mixer: Wiring, Code and Simulator

To build this Arduino RGB LED Colour Mixer project you need an Arduino Uno and an RGB LED, three 220 Ω resistors and a slide switch. PWM on pins 9, 10 and 11 mixes an RGB LED through a 220 Ω resistor per colour; a slide switch on pin 2 picks warm or cool. Make the 9 connections in the wiring table, upload the Arduino C++ code, and click the slide switch to flip between a warm orange and a cool blue.

Open this circuit in the free Arduino Uno simulator

Parts list

QtyPartWhat it does
1Arduino Unothe microcontroller board
1RGB LEDThree LEDs in one, sharing COM. Mix colours with PWM on R, G and B.
3220 Ω resistorLimits current. 220 Ω in series with an LED; 10 kΩ as a pull-up or pull-down.
1Slide SwitchThe middle pin 2 connects to pin 1 or pin 3, depending on the lever. Click to flip.

Wiring

#FromTo
1Arduino Uno pin 9220 Ω resistor (rR) leg 1
2220 Ω resistor (rR) leg 2RGB LED R
3Arduino Uno pin 10220 Ω resistor (rG) leg 1
4220 Ω resistor (rG) leg 2RGB LED G
5Arduino Uno pin 11220 Ω resistor (rB) leg 1
6220 Ω resistor (rB) leg 2RGB LED B
7Arduino Uno GNDRGB LED COM
8Arduino Uno pin 2Slide Switch 2
9Arduino Uno GNDSlide Switch 1

Step by step

  1. Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the Arduino Uno. No install or account is needed.
  2. Add the parts. Add an RGB LED, three 220 Ω resistors and a slide switch from the parts palette.
  3. Wire 1. Connect Arduino Uno pin 9 to 220 Ω resistor (rR) leg 1.
  4. Wire 2. Connect 220 Ω resistor (rR) leg 2 to RGB LED R.
  5. Wire 3. Connect Arduino Uno pin 10 to 220 Ω resistor (rG) leg 1.
  6. Wire 4. Connect 220 Ω resistor (rG) leg 2 to RGB LED G.
  7. Wire 5. Connect Arduino Uno pin 11 to 220 Ω resistor (rB) leg 1.
  8. Wire 6. Connect 220 Ω resistor (rB) leg 2 to RGB LED B.
  9. Wire 7. Connect Arduino Uno GND to RGB LED COM.
  10. Wire 8. Connect Arduino Uno pin 2 to Slide Switch 2.
  11. Wire 9. Connect Arduino Uno GND to Slide Switch 1.
  12. Paste the Arduino C++ code. Paste the Arduino C++ code below into the code editor.
  13. Run it. Press Run. Click the slide switch to flip between a warm orange and a cool blue.

Arduino C++ code

// RGB colour mixer: a slide switch picks warm or cool, PWM mixes the colour.
// Common-cathode RGB LED on pins 9 (red), 10 (green), 11 (blue); switch on pin 2.
const int R = 9, G = 10, B = 11, SW = 2;

void setup() {
  pinMode(SW, INPUT_PULLUP);
  Serial.begin(9600);
}

void loop() {
  bool warm = digitalRead(SW) == LOW;
  if (warm) {
    analogWrite(R, 255); analogWrite(G, 80); analogWrite(B, 0);
  } else {
    analogWrite(R, 0); analogWrite(G, 120); analogWrite(B, 255);
  }
  static bool last = !warm;
  if (warm != last) {
    Serial.println(warm ? "warm" : "cool");
    last = warm;
  }
  delay(20);
}

What to try

Click the slide switch to flip between a warm orange and a cool blue.

Frequently asked questions

How do I wire the RGB LED Colour Mixer project on an Arduino Uno?

Make 9 connections: Arduino Uno pin 9 to 220 Ω resistor (rR) leg 1; 220 Ω resistor (rR) leg 2 to RGB LED R; Arduino Uno pin 10 to 220 Ω resistor (rG) leg 1; 220 Ω resistor (rG) leg 2 to RGB LED G; Arduino Uno pin 11 to 220 Ω resistor (rB) leg 1; 220 Ω resistor (rB) leg 2 to RGB LED B; Arduino Uno GND to RGB LED COM; Arduino Uno pin 2 to Slide Switch 2; Arduino Uno GND to Slide Switch 1.

What parts do I need for this Arduino project?

An Arduino Uno and an RGB LED, three 220 Ω resistors and a slide switch.

Can I simulate this Arduino project online for free?

Yes. The BitForBytes Embedded Lab runs this exact circuit and Arduino C++ code in your browser for free, with no install and no hardware. The sketch is compiled with the real Arduino toolchain and runs on an emulated ATmega328P.

What does the code do?

PWM on pins 9, 10 and 11 mixes an RGB LED through a 220 Ω resistor per colour; a slide switch on pin 2 picks warm or cool.

More Arduino Uno projects