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
| Qty | Part | What it does |
|---|---|---|
| 1 | Arduino Uno | the microcontroller board |
| 1 | RGB LED | Three LEDs in one, sharing COM. Mix colours with PWM on R, G and B. |
| 3 | 220 Ω resistor | Limits current. 220 Ω in series with an LED; 10 kΩ as a pull-up or pull-down. |
| 1 | Slide Switch | The middle pin 2 connects to pin 1 or pin 3, depending on the lever. Click to flip. |
Wiring
| # | From | To |
|---|---|---|
| 1 | Arduino Uno pin 9 | 220 Ω resistor (rR) leg 1 |
| 2 | 220 Ω resistor (rR) leg 2 | RGB LED R |
| 3 | Arduino Uno pin 10 | 220 Ω resistor (rG) leg 1 |
| 4 | 220 Ω resistor (rG) leg 2 | RGB LED G |
| 5 | Arduino Uno pin 11 | 220 Ω resistor (rB) leg 1 |
| 6 | 220 Ω resistor (rB) leg 2 | RGB LED B |
| 7 | Arduino Uno GND | RGB LED COM |
| 8 | Arduino Uno pin 2 | Slide Switch 2 |
| 9 | Arduino Uno GND | Slide Switch 1 |
Step by step
- Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the Arduino Uno. No install or account is needed.
- Add the parts. Add an RGB LED, three 220 Ω resistors and a slide switch from the parts palette.
- Wire 1. Connect Arduino Uno pin 9 to 220 Ω resistor (rR) leg 1.
- Wire 2. Connect 220 Ω resistor (rR) leg 2 to RGB LED R.
- Wire 3. Connect Arduino Uno pin 10 to 220 Ω resistor (rG) leg 1.
- Wire 4. Connect 220 Ω resistor (rG) leg 2 to RGB LED G.
- Wire 5. Connect Arduino Uno pin 11 to 220 Ω resistor (rB) leg 1.
- Wire 6. Connect 220 Ω resistor (rB) leg 2 to RGB LED B.
- Wire 7. Connect Arduino Uno GND to RGB LED COM.
- Wire 8. Connect Arduino Uno pin 2 to Slide Switch 2.
- Wire 9. Connect Arduino Uno GND to Slide Switch 1.
- Paste the Arduino C++ code. Paste the Arduino C++ code below into the code editor.
- 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
- Arduino LED Blink: Wiring, Code and Simulator
- Arduino LDR Light Sensor: Wiring, Code and Simulator
- Arduino NTC Thermistor Thermometer: Wiring, Code and Simulator
- Arduino PWM to Analog RC Filter: Wiring, Code and Simulator
- Arduino Capacitance Meter: Wiring, Code and Simulator
- Arduino DC Motor PWM Speed Control with MOSFET: Wiring, Code and Simulator