It thinks and mixes the colors for the light.
Arduino
The brain
combining channel values for colors
Mix RGB channels to make yellow, cyan, magenta, and white.

Pin connections
| Part 1 | Part 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 |
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 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!
It thinks and mixes the colors for the light.
Arduino
The brain
One little bulb that holds red, green, and blue together.
RGB LED
The color light
Keeps the red color safe from too much power.
Red resistor
The protector
Keeps the green color safe from too much power.
Green resistor
The protector
Keeps the blue color safe from too much power.
Blue resistor
The protector
Just red
Only the red color is on, so the light glows red.
setChannels(HIGH, LOW, LOW);
Red + green = yellow
Turn on red and green together and you get yellow — your first color mix!
setChannels(HIGH, HIGH, LOW);
Just green
Now only green is on, so the light glows green.
setChannels(LOW, HIGH, LOW);
Green + blue = cyan
Green and blue together make a cool sky-blue color called cyan.
setChannels(LOW, HIGH, HIGH);
Just blue
Now only blue is on, so the light glows blue.
setChannels(LOW, LOW, HIGH);
Red + blue = magenta
Red and blue together make a pretty pink-purple color called magenta.
setChannels(HIGH, LOW, HIGH);
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
Follow these steps in order. Match the wires to the colors shown.
Place Arduino
Place the Arduino (uno) on the breadboard.
Arduino placed — ready to build!
Place RGB LED
Place the RGB LED (rgb1) on the breadboard.
Place Red resistor
Place the Red resistor (rr) on the breadboard.
Place Green resistor
Place the Green resistor (rg) on the breadboard.
Place Blue resistor
Place the Blue resistor (rb) on the breadboard.
Connect Arduino pin 9 to Red resistor (rr) 1
Connect Arduino pin 9 to Red resistor (rr) 1.
Connect Red resistor (rr) 2 to RGB LED (rgb1) R
Connect Red resistor (rr) 2 to RGB LED (rgb1) R.
Connect Arduino pin 10 to Green resistor (rg) 1
Connect Arduino pin 10 to Green resistor (rg) 1.
Connect Green resistor (rg) 2 to RGB LED (rgb1) G
Connect Green resistor (rg) 2 to RGB LED (rgb1) G.
Connect Arduino pin 11 to Blue resistor (rb) 1
Connect Arduino pin 11 to Blue resistor (rb) 1.
Connect Blue resistor (rb) 2 to RGB LED (rgb1) B
Connect Blue resistor (rb) 2 to RGB LED (rgb1) B.
Connect RGB LED (rgb1) COM to Arduino GND
Connect RGB LED (rgb1) COM to Arduino GND.
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.
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);
}
Q1. Which part runs again and again?
Q2. Which two colors mix to make yellow?
Cycle the colors faster — change every delay(600) to delay(300).
Hint: Many delay lines share the same number inside loop().
Add a little note (comment) on the line that makes yellow.
Hint: It is the second setChannels line in loop().
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);