Mission 07 · Stage 1

RGB LED Basics

three digital outputs for RGB channels

Turn red, green, and blue channels on and off with digitalWrite().

RGB LED Basics 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

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 story

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.

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

Red channel

Only the red pin is HIGH; green and blue stay off — pure red light.

allOff();
digitalWrite(PIN_R, HIGH);
delay(500);
2

Green channel

Same idea: one channel on at a time with digitalWrite, not brightness yet.

allOff();
digitalWrite(PIN_G, HIGH);
delay(500);
3

Blue channel

Blue turn, then loop() starts the red cycle again.

allOff();
digitalWrite(PIN_B, HIGH);
delay(500);

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 — colors should change one at a time: red, green, blue.
  • Only one channel is on at each step.

Peek at code

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().

Show full sketch (rgb-led-basics.ino)
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);
}

Quick quiz

Q1. Where does repeating work belong?

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

Q2. How many output pins drive the RGB LED here?

  • A. Three (R, G, B)
  • B. One shared pin
  • C. Zero — it is automatic
Why: Correct — three digitalWrite() pins control R, G, and B.

Code lab — try on your own

  1. Show each color quicker — change every delay(500) to delay(250).

    Hint: Three delay lines in loop(), one after each color.

  2. Add a comment on the red digitalWrite line.

    Hint: The line right after the first allOff() 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

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);