Runs your sketch
Arduino
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 |
Three pins, three colors!
Turn red, green, and blue channels on one at a time with digitalWrite().
RGB LEDs mix colors in screens and mood lights.
The problem
One color channel is not enough — an RGB LED has three inputs.
Think of it like
Like three light switches — one for red, green, and blue.
Runs your sketch
Arduino
Brain
Three color channels in one bulb
RGB LED
Color light
Protects the red channel
Red resistor
Safety
Protects the green channel
Green resistor
Safety
Protects the blue channel
Blue resistor
Safety
Red channel
Only the red pin is HIGH; green and blue stay off — pure red light.
allOff(); digitalWrite(PIN_R, HIGH); delay(500);
Green channel
Same idea: one channel on at a time with digitalWrite, not brightness yet.
allOff(); digitalWrite(PIN_G, HIGH); delay(500);
Blue channel
Blue turn, then loop() starts the red cycle 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!
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.
Three channel pins
const int PIN_R = 9; const int PIN_G = 10; const int PIN_B = 11;
An RGB LED needs three separate digital outputs — one per color.
allOff() helper
void allOff() {
digitalWrite(PIN_R, LOW);
digitalWrite(PIN_G, LOW);
digitalWrite(PIN_B, LOW);
}Turns all three channels LOW so the next color starts clean.
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 delay().
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. Where does repeating work belong?
Q2. How many output pins drive the RGB LED here?
Show each color quicker — change every delay(500) to delay(250).
Hint: Three delay lines in loop(), one after each color.
Add a comment on the red digitalWrite line.
Hint: The line right after the first allOff() in loop().
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
Turn red, green, and blue channels on and off with digitalWrite().
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 allOff() {
digitalWrite(PIN_R, LOW);
digitalWrite(PIN_G, LOW);
digitalWrite(PIN_B, LOW);
}setup()
Technical
Runs one time when the board turns on.
In this project
Sets up pins and libraries for RGB LED Basics.
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 LED Basics.
Why here
Repeating work (blink, read sensors) goes here.
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 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 LED Basics 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 LED Basics.
Why here
Goes in loop() so it can keep changing while the program runs.
digitalWrite(PIN_R, LOW);
delay
Technical
Waits for some time. Nothing else runs during the wait.
In this project
Controls speed so you can see RGB LED Basics in the simulator.
Why here
Right after an action that should stay the same for a moment.
delay(500);