YKR038 COURSE · MODULE 2 · LESSON 10

Create Colors with an RGB LED

Mix red, green, and blue channels with PWM to create custom colors.

30 minComplete beginnerLEDs, Sound & Display
BUILD WITHRGB LED
PROGRAMESP32
ACHIEVEThe RGB LED produces several programmed…
Written for complete beginners

Follow the numbered steps in order. Do not connect USB power until the wiring step tells you to. Compare every pin label before continuing.

LESSON GOAL

What you will build and learn

In this lesson, you will learn additive color mixing and multi-channel PWM. By the end, the RGB LED produces several programmed colors.

  • Recognize the purpose of each required part.
  • Make the connections in a safe, repeatable order.
  • Upload or run the lesson procedure and verify the expected result.
  • Use observable evidence to fix common problems.
Real YKR038 wiring photo reserved

A close, labeled photograph of this exact experiment will be added here. Until then, use the written pin-by-pin connection list below.

STEP-BY-STEP GUIDE

Build the experiment

1

Understand the target result

Mix red, green, and blue channels with PWM to create custom colors. The expected result is: The RGB LED produces several programmed colors.

2

Prepare the board and parts

Disconnect the ESP32 from USB. Put the ESP32, breadboard, jumper wires, and the listed lesson parts in front of you. Straighten bent pins gently and never force a module into the breadboard.

3

Make each connection with power off

  1. Red channel → 220Ω resistor → GPIO 25.
  2. Green channel → 220Ω resistor → GPIO 26.
  3. Blue channel → 220Ω resistor → GPIO 27.
  4. Connect the common cathode to GND. If your LED is common-anode, connect it to 3.3V and invert PWM values.

Power check: confirm that no 5V signal goes directly into an ESP32 GPIO and that 3.3V is not connected to GND.

4

Install any library and upload the code

No additional Arduino library is required for this starter sketch. Select your ESP32 board and serial port before clicking Upload.

Arduino sketchCheck the pin constants against your wiring
const int R = 25, G = 26, B = 27;

void setColor(int red, int green, int blue) {
  ledcWrite(R, red); ledcWrite(G, green); ledcWrite(B, blue);
}

void setup() {
  ledcAttach(R, 5000, 8); ledcAttach(G, 5000, 8); ledcAttach(B, 5000, 8);
}

void loop() {
  setColor(255, 0, 0); delay(1000);
  setColor(0, 255, 0); delay(1000);
  setColor(0, 0, 255); delay(1000);
  setColor(255, 80, 0); delay(1000);
}
5

Power the circuit and observe

Connect USB power only after the wiring check. Open Serial Monitor at 115200 baud when the sketch prints data. Watch the circuit for at least 20 seconds and compare it with this expected behavior: The RGB LED produces several programmed colors.

6

Change one value and test again

Make one small change—such as a delay, threshold, brightness, or displayed message—then upload again. This confirms that you understand which part of the program controls the result.

WHY IT WORKS

The key idea

This experiment demonstrates additive color mixing and multi-channel PWM. The ESP32 repeatedly reads or updates the connected hardware, applies the program logic, and produces the observable result. Changing one input or one code value helps you see that relationship directly.

Input or instructionESP32 logicMeasured result or output

TROUBLESHOOTING

If the experiment does not work

Nothing powers on

Disconnect USB. Check the USB cable, 3.3V/5V selection, GND rail, and breadboard row placement.

Upload fails

Confirm the board and port. Close other serial programs, reconnect USB, and hold BOOT only if your board requires it.

Result is unstable

Shorten jumper wires, confirm a shared ground, and verify that input pins are not floating.

Lesson-specific check

Confirm whether the supplied RGB LED is common-anode or common-cathode.

VIDEO WALKTHROUGH

Hands-on lesson video reserved

The final video will show the real YKR038 parts, every wire connection, the upload process, and the expected result.