Mission 08 · Stage 1

RGB Color Mixer

combining channel values for colors

Mix RGB channels to make yellow, cyan, magenta, and white.

RGB Color Mixer circuit diagram

Pin connections

Part 1Part 2

Arduino

pin 9

Red resistor

pin 1

Red resistor

pin 2

RGB LED

red (R)

Arduino

pin 10

Green resistor

pin 1

Green resistor

pin 2

RGB LED

green (G)

Arduino

pin 11

Blue resistor

pin 1

Blue resistor

pin 2

RGB LED

blue (B)

RGB LED

common (COM)

Arduino

GND

See it

Mix channels to make new colors!

Turn two or three channels ON together — yellow, cyan, white, and more.

Screens mix red, green, and blue to paint every color.

The story

The problem

Single channels give basic colors — combinations make more.

Think of it like

Like mixing paint — red plus green makes yellow.

Meet the parts

Runs your sketch

Arduino

Brain

Loading part…

Three color channels in one bulb

RGB LED

Color light

Loading part…

Protects the red channel

Red resistor

Safety

Loading part…

Protects the green channel

Green resistor

Safety

Loading part…

Protects the blue channel

Blue resistor

Safety

Loading part…

How it works

1

Pure red

Only the red channel is on.

setChannels(HIGH, LOW, LOW);
2

Yellow mix

Red and green together look yellow — two channels ON at once.

setChannels(HIGH, HIGH, LOW);
3

Pure green

Just green this time.

setChannels(LOW, HIGH, LOW);
4

Cyan mix

Green plus blue makes cyan.

setChannels(LOW, HIGH, HIGH);
5

Pure blue

Blue alone.

setChannels(LOW, LOW, HIGH);
6

Magenta mix

Red plus blue makes magenta.

setChannels(HIGH, LOW, HIGH);
7

White — all on

All three channels together look white, then loop() repeats.

setChannels(HIGH, HIGH, HIGH);

Then loop back to step 1

Build the circuit

Follow these steps in order. Match the wires to the colors shown.

  1. 1

    Place Arduino

    Place the Arduino (uno) on the breadboard.

    Arduino placed!

    Loading part…
  2. 2

    Place RGB LED

    Place the RGB LED (rgb1) on the breadboard.

    Loading part…
  3. 3

    Place Red resistor

    Place the Red resistor (rr) on the breadboard.

    Loading part…
  4. 4

    Place Green resistor

    Place the Green resistor (rg) on the breadboard.

    Loading part…
  5. 5

    Place Blue resistor

    Place the Blue resistor (rb) on the breadboard.

    Loading part…
  6. 6

    Connect Arduino pin 9 to Red resistor (rr) 1

    Connect Arduino pin 9 to Red resistor (rr) 1.

  7. 7

    Connect Red resistor (rr) 2 to RGB LED (rgb1) R

    Connect Red resistor (rr) 2 to RGB LED (rgb1) R.

  8. 8

    Connect Arduino pin 10 to Green resistor (rg) 1

    Connect Arduino pin 10 to Green resistor (rg) 1.

  9. 9

    Connect Green resistor (rg) 2 to RGB LED (rgb1) G

    Connect Green resistor (rg) 2 to RGB LED (rgb1) G.

  10. 10

    Connect Arduino pin 11 to Blue resistor (rb) 1

    Connect Arduino pin 11 to Blue resistor (rb) 1.

  11. 11

    Connect Blue resistor (rb) 2 to RGB LED (rgb1) B

    Connect Blue resistor (rb) 2 to RGB LED (rgb1) B.

  12. 12

    Connect RGB LED (rgb1) COM to Arduino GND

    Connect RGB LED (rgb1) COM to Arduino GND.

Try it

  • Run and call out each color name as it changes.
  • Notice when two channels are on — that is a mix!

Peek at code

setChannels()

void setChannels(int r, int g, int b) {
  digitalWrite(PIN_R, r);
  digitalWrite(PIN_G, g);
  digitalWrite(PIN_B, b);
}

One function sets all three pins at once — easier than three separate digitalWrite lines each time.

Setup RGB pins

void setup() {
  pinMode(PIN_R, OUTPUT);
  pinMode(PIN_G, OUTPUT);
  pinMode(PIN_B, OUTPUT);
}

All three color pins are configured as outputs in setup().

Color mixing loop

void loop() {
  setChannels(HIGH, LOW, LOW);
  delay(600);
  setChannels(HIGH, HIGH, LOW);
  delay(600);
  setChannels(LOW, HIGH, LOW);
  delay(600);
  setChannels(LOW, HIGH, HIGH);
  delay(600);
  setChannels(LOW, LOW, HIGH);
  delay(600);
  setChannels(HIGH, LOW, HIGH);
  delay(600);
  setChannels(HIGH, HIGH, HIGH);
  delay(600);
}

Each setChannels call is a different recipe. Combining channels is how new colors appear.

Show full sketch (rgb-color-mixer.ino)
const int PIN_R = 9;
const int PIN_G = 10;
const int PIN_B = 11;
void setChannels(int r, int g, int b) {
  digitalWrite(PIN_R, r);
  digitalWrite(PIN_G, g);
  digitalWrite(PIN_B, b);
}
void setup() {
  pinMode(PIN_R, OUTPUT);
  pinMode(PIN_G, OUTPUT);
  pinMode(PIN_B, OUTPUT);
}
void loop() {
  setChannels(HIGH, LOW, LOW);
  delay(600);
  setChannels(HIGH, HIGH, LOW);
  delay(600);
  setChannels(LOW, HIGH, LOW);
  delay(600);
  setChannels(LOW, HIGH, HIGH);
  delay(600);
  setChannels(LOW, LOW, HIGH);
  delay(600);
  setChannels(HIGH, LOW, HIGH);
  delay(600);
  setChannels(HIGH, HIGH, HIGH);
  delay(600);
}

Quick quiz

Q1. Where does repeating work belong?

  • A. loop()
  • B. setup()
  • C. pinMode only
Why: Correct—loop() runs again and again.

Q2. Which channels are ON to make yellow?

  • A. Red and green
  • B. Red and blue
  • C. Green and blue only
Why: Correct — red and green together look yellow on an RGB LED.

Code lab — try on your own

  1. Cycle colors faster — change delay(600) to delay(300) throughout loop().

    Hint: Many delay lines share the same number.

  2. Add a comment on the yellow setChannels(HIGH, HIGH, LOW) line.

    Hint: It is the second setChannels call in loop().

Code walkthrough

A line-by-line tour of the sketch — the same steps as in Robo Gurukul Studio.

Program overview

Technical

Sketches have globals, then setup() once, then loop() forever.

In this project

Mix RGB channels to make yellow, cyan, magenta, and white.

Why here

Read from top to bottom. Hover words or lines for help!

const int PIN_R = 9;
const int PIN_G = 10;
const int PIN_B = 11;
void setChannels(int r, int g, int b) {
  digitalWrite(PIN_R, r);
  digitalWrite(PIN_G, g);
  digitalWrite(PIN_B, b);
}

setup()

Technical

Runs one time when the board turns on.

In this project

Sets up pins and libraries for RGB Color Mixer.

Why here

One-time setup belongs here—not in loop().

void setup() {
  pinMode(PIN_R, OUTPUT);
  pinMode(PIN_G, OUTPUT);
  pinMode(PIN_B, OUTPUT);
}

loop()

Technical

Runs again and again after setup() is done.

In this project

This is the main action you see in RGB Color Mixer.

Why here

Repeating work (blink, read sensors) goes here.

void loop() {
  setChannels(HIGH, LOW, LOW);
  delay(600);
  setChannels(HIGH, HIGH, LOW);
  delay(600);
  setChannels(LOW, HIGH, LOW);
  delay(600);
  setChannels(LOW, HIGH, HIGH);
  delay(600);
  setChannels(LOW, LOW, HIGH);
  delay(600);
  setChannels(HIGH, LOW, HIGH);
  delay(600);
  setChannels(HIGH, HIGH, HIGH);
  delay(600);
}

Try this: Change numbers in loop(), then compile and run the simulator.

pinMode

Technical

Tells a pin if it listens or drives something.

In this project

Gets the RGB Color Mixer circuit ready in the simulator.

Why here

Goes in setup() because we only set pins once at the start.

  pinMode(PIN_R, OUTPUT);

digitalWrite

Technical

Turns a pin ON or OFF.

In this project

Controls lights, motors, or buzzers in RGB Color Mixer.

Why here

Goes in loop() so it can keep changing while the program runs.

  digitalWrite(PIN_R, r);

delay

Technical

Waits for some time. Nothing else runs during the wait.

In this project

Controls speed so you can see RGB Color Mixer in the simulator.

Why here

Right after an action that should stay the same for a moment.

  delay(600);