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

Let's mix our own colors!

Turn on two colors at once and a brand new color appears, like mixing paint!

TVs and phone screens make every color by mixing red, green, and blue!

The story

The problem

One color at a time is fun, but mixing colors lets us make so many more.

Think of it like

It's like mixing paint — red and green together make yellow!

Meet the parts

It thinks and mixes the colors for the light.

Arduino

The brain

Loading part…

One little bulb that holds red, green, and blue together.

RGB LED

The color light

Loading part…

Keeps the red color safe from too much power.

Red resistor

The protector

Loading part…

Keeps the green color safe from too much power.

Green resistor

The protector

Loading part…

Keeps the blue color safe from too much power.

Blue resistor

The protector

Loading part…

How it works

1

Just red

Only the red color is on, so the light glows red.

setChannels(HIGH, LOW, LOW);
2

Red + green = yellow

Turn on red and green together and you get yellow — your first color mix!

setChannels(HIGH, HIGH, LOW);
3

Just green

Now only green is on, so the light glows green.

setChannels(LOW, HIGH, LOW);
4

Green + blue = cyan

Green and blue together make a cool sky-blue color called cyan.

setChannels(LOW, HIGH, HIGH);
5

Just blue

Now only blue is on, so the light glows blue.

setChannels(LOW, LOW, HIGH);
6

Red + blue = magenta

Red and blue together make a pretty pink-purple color called magenta.

setChannels(HIGH, LOW, HIGH);
7

All three = white

All three colors on at once look white! Then loop() jumps back to red and starts again.

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 — ready to build!

    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

  • Press the green Run button — call out each color name as it changes.
  • When two colors are on together, that is a mix — watch for the new color!

Peek at code

The setChannels helper

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

This little helper turns all three colors on or off at once. It makes mixing colors easy.

Get the colors ready

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

setup() gets all three color pins ready so we can light any of them.

The 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 line is a color recipe. Turning on two or three colors together makes brand new colors.

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. Which part runs again and again?

  • A. loop()
  • B. setup()
  • C. pinMode only
Why: Yes! loop() runs again and again, forever.

Q2. Which two colors mix to make yellow?

  • A. Red and green
  • B. Red and blue
  • C. Green and blue
Why: Yes! Red and green together make yellow.

Code lab — try on your own

  1. Cycle the colors faster — change every delay(600) to delay(300).

    Hint: Many delay lines share the same number inside loop().

  2. Add a little note (comment) on the line that makes yellow.

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

Code walkthrough

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

Program overview

Big idea

Every Arduino program has a top part, a setup() part that runs once, and a loop() part that runs again and again.

In this project

One light mixes its three colors to make new colors, over and over.

Tip

Read from the top to the bottom. Tap any word or line if you need 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()

Big idea

setup() runs one time when the board turns on.

In this project

It gets pins 9, 10, and 11 ready for the red, green, and blue colors.

Why here

Things we do only once go inside setup().

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

loop()

Big idea

loop() runs again and again, forever.

In this project

This is where the light mixes colors and shows them one by one.

Why here

Things that repeat go inside 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);
}

Try this: Change a delay number inside loop(), then press Run to make each color last longer.

pinMode

Big idea

pinMode tells a pin if it will listen or push power out.

In this project

It makes pin 9 ready to push power to the red color.

Why here

It goes in setup() because we only set it once.

  pinMode(PIN_R, OUTPUT);

digitalWrite

Big idea

digitalWrite turns a pin ON or OFF.

In this project

It turns each color on or off to make the mix. Here it sets the red color.

Why here

It goes in loop() so the colors can keep changing.

  digitalWrite(PIN_R, r);

delay

Big idea

delay means wait. Nothing else happens while it waits.

In this project

It keeps each mixed color glowing long enough for you to see it.

Why here

Right after we make a color.

  delay(600);