It thinks and tells the light which color to show.
Arduino
The brain
three digital outputs for RGB channels
Turn red, green, and blue channels on and off with digitalWrite().

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 make a color-changing light!
One tiny light can glow red, then green, then blue, like magic.
Color lights are in phone screens, TVs, and fun party lamps!
The problem
A normal light only shows one color. This special light hides three colors inside!
Think of it like
It's like having three light switches in one bulb — one for red, one for green, one for blue.
It thinks and tells the light which color to show.
Arduino
The brain
One little bulb that can glow red, green, or blue.
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
Glow red
Turn all the colors off first, then turn on only red. The light glows red!
allOff(); digitalWrite(PIN_R, HIGH); delay(500);
Glow green
Red turns off and green comes on. Only one color glows at a time.
allOff(); digitalWrite(PIN_G, HIGH); delay(500);
Glow blue
Green turns off and blue glows. Then loop() jumps back to red and starts again!
allOff(); digitalWrite(PIN_B, HIGH); delay(500);
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 three color nicknames
const int PIN_R = 9; const int PIN_G = 10; const int PIN_B = 11;
This light has three colors inside, so it needs three pins — one for red, one for green, one for blue.
The allOff() helper
void allOff() {
digitalWrite(PIN_R, LOW);
digitalWrite(PIN_G, LOW);
digitalWrite(PIN_B, LOW);
}This little helper turns all three colors off, so each new color starts fresh.
The color cycle
void loop() {
allOff();
digitalWrite(PIN_R, HIGH);
delay(500);
allOff();
digitalWrite(PIN_G, HIGH);
delay(500);
allOff();
digitalWrite(PIN_B, HIGH);
delay(500);
}loop() shows red, then green, then blue, each with the same short wait. Then it starts over!
const int PIN_R = 9;
const int PIN_G = 10;
const int PIN_B = 11;
void allOff() {
digitalWrite(PIN_R, LOW);
digitalWrite(PIN_G, LOW);
digitalWrite(PIN_B, LOW);
}
void setup() {
pinMode(PIN_R, OUTPUT);
pinMode(PIN_G, OUTPUT);
pinMode(PIN_B, OUTPUT);
}
void loop() {
allOff();
digitalWrite(PIN_R, HIGH);
delay(500);
allOff();
digitalWrite(PIN_G, HIGH);
delay(500);
allOff();
digitalWrite(PIN_B, HIGH);
delay(500);
}
Q1. Which part runs again and again?
Q2. How many pins does this color light need?
Show each color quicker — change every delay(500) to delay(250).
Hint: There are three delay lines inside loop(), one after each color.
Add a little note (comment) on the line that turns red on.
Hint: It is the line right after the first allOff() inside 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 special light glows red, then green, then blue, forever.
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 allOff() {
digitalWrite(PIN_R, LOW);
digitalWrite(PIN_G, LOW);
digitalWrite(PIN_B, LOW);
}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 changes color from red to green to blue.
Why here
Things that repeat go inside loop().
void loop() {
allOff();
digitalWrite(PIN_R, HIGH);
delay(500);
allOff();
digitalWrite(PIN_G, HIGH);
delay(500);
allOff();
digitalWrite(PIN_B, HIGH);
delay(500);
}
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
ON lights up a color, OFF turns it dark. Here it turns the red color off.
Why here
It goes in loop() so the colors can keep changing.
digitalWrite(PIN_R, LOW);
delay
Big idea
delay means wait. Nothing else happens while it waits.
In this project
It keeps each color glowing long enough for you to see it.
Why here
Right after we turn a color on.
delay(500);