TinySkiff ESP32-S3 Lab · Day 9 of 30

Mix any colour
from three lights

Today the board becomes a painter. You wire one small dome that holds three lights — red, green, and blue — to three PWM pins, then upload a sketch that sets each brightness and lets your eye blend them into a single colour.

About 25 minutesArduino firstMicroPython optionalNo electronics assumed
Agent assist code TSK-DAY09-RGB

Hand this to an agent so it can pull the lesson packet and coach you step by step.

01 First, know the pieces

What you need

Six things, most of them small. Tap Define on any part you haven't met — the answer opens as a field note you can read and dismiss without losing your place.

Official manual photo of the ESP32-S3 development board.
Manual photo

ESP32-S3 board

The brain that runs your uploaded sketch.

Official manual image of the ESP32-S3 GPIO extension board.
Manual photo

GPIO extension board

Spreads the pins into rows you can reach and label.

Official manual photo of an RGB LED showing its long common pin and three colour legs.
Manual photo

RGB LED

Three lights — red, green, blue — in one dome with a shared pin.

Official manual photo of a resistor with coloured value bands.
Manual photo

3 × 220 Ω resistors

One in series with each colour leg to keep the current gentle.

Official manual image of a jumper wire.
Manual photo

Jumper wires

Temporary, solder-free connections.

Official manual screenshot of the Arduino IDE interface.
Manual screenshot

Arduino IDE

Uploads the sketch to the board.

02 Make the physical circuit

Chart the circuit

The official Freenove diagram is your chart — schematic on top, the same circuit built on a breadboard below. Click it to enlarge. Each connection tells you where the wire goes and why.

Official Freenove circuit — C Tutorial, Chapter 5 (RGB LED), page 72.
Red leg (via 220 Ω) GPIO 38 One PWM channel sets how much red shows.
Green leg (via 220 Ω) GPIO 39 One PWM channel sets how much green shows.
Blue leg (via 220 Ω) GPIO 40 One PWM channel sets how much blue shows.
Common (long) pin 3.3V All three share this positive pin so a colour lights when its pin goes LOW.

The common pin goes to 3.3V. This is a common-anode LED, so the long common pin goes to 3.3V and not to ground — the opposite of a single LED. Each colour leg reaches its own GPIO through a 220 Ω resistor. Unplug USB before you move any wire.

03 One action at a time

Build it

This is the main path — you can finish the day without opening a single field note. Tap each step as you go to keep your place.

0 / 9 done
  1. Seat the ESP32-S3 on the GPIO extension board and keep USB unplugged while you wire.

  2. Find the RGB LED's long pin — that's the common one shared by all three colours.

  3. Wire the red leg through a 220 Ω resistor to GPIO 38.

  4. Wire the green leg through a 220 Ω resistor to GPIO 39.

  5. Wire the blue leg through a 220 Ω resistor to GPIO 40.

  6. Run the long common pin to 3.3V, not to ground.

  7. Compare every wire to the chart before you plug in USB.

  8. Open Sketch_05.1_RandomColorLight.ino in Arduino IDE and upload it.

  9. Watch the dome change colour again and again.

One dome, every colour.

The board is mixing red, green, and blue for you now. Head to Test & debug to confirm the colours keep changing.

04 Read just enough code

Read the code

The sketch sets up three PWM channels, then paints a colour by giving each one a brightness. Switch to MicroPython if you'd rather see the same idea in Python — the wiring never changes.

Sketch_05.1_RandomColorLight.ino
const byte ledPins[] = {38, 39, 40};   // R, G, B
const byte chns[]    = {0, 1, 2};

void setup() {
  for (int i = 0; i < 3; i++) {
    ledcAttachChannel(ledPins[i], 1000, 8, chns[i]);
  }
}

void loop() {
  int red   = random(0, 256);
  int green = random(0, 256);
  int blue  = random(0, 256);

  ledcWrite(ledPins[0], 255 - red);    // common anode: LOW = brighter
  ledcWrite(ledPins[1], 255 - green);
  ledcWrite(ledPins[2], 255 - blue);
  delay(200);
}
const byte ledPins[] = {38, 39, 40}The three pins are the red, green, and blue legs in that order.
ledcWrite(ledPins[0], 255 - red)Writes 255 minus the value because this common-anode LED lights when its pin goes LOW.
red = random(0, 256)Each colour gets a fresh brightness from 0 to 255, and setting all three at once mixes the shade.

05 Understand, don't memorise

One colour from three primaries

There's no trick here — three small lights sit close together and PWM sets how bright each one glows.

Three lights

One dome

Red green and blue sit side by side under one lens.

Set levels

PWM each

A PWM channel dials each colour from off to full.

Blend

Your eye

The three glows overlap and read as one colour.

All full

White

Red green and blue at full together look white.

The model colour = red + green + blue at chosen brightnesses

Why the code inverts each value

The common pin sits at 3.3V, so a colour is brightest when its own pin is pulled LOW. Writing 255 minus the brightness flips the scale so bigger still means brighter.

Three lights in one part

An RGB LED is three coloured LEDs packaged together, each with its own leg and a shared common pin.

06 Know it worked

Test & debug

Nothing prints to the screen today — the proof is the colour in the dome.

What you should see
RGB LED
  • The RGB LED glows a colour.
  • Every fraction of a second it jumps to a new random colour.
  • It keeps changing for as long as the board has power.

The colours look random on purpose — each one is a fresh mix of red, green, and blue.

If it doesn't
  • Only one colour ever appears? Check that colour's 220 Ω resistor and its GPIO wire — the other two legs may not be reaching their pins.
  • Nothing lights at all? Check the common pin — it goes to 3.3V, not to ground.
  • A colour is stuck full-on? Suspect the common-anode wiring or the wrong leg on that pin.
  • Upload fails? Swap in a data-capable USB cable.

07 Make the idea yours

Try this: choose a status colour

Same working circuit, one design choice: picking a colour that carries meaning. It fits inside today's 25 minutes.

Name a colour

Decide on a colour that would read as ready or as a warning, then write down the red, green, and blue numbers from 0 to 255 that would make it.

Let it drift

Upload the gradient variant Sketch_05.2_GradientColorLight.ino and watch the colour slide smoothly instead of jumping.

Logbook

08 Learn it with a hand on the tiller

Coach me through it

Every lesson ships with a code and a machine-readable packet, so an agent can guide you with full context.

Lesson code

TSK-DAY09-RGB

How the agent should behave: guide one physical connection at a time, wait for you to confirm, explain the common-anode inversion on request, and always check the common pin, wiring, board, and USB before changing code.

Field note

Shortcut

Prompt copied