Skip to content

RGB LED Color Mixing on ESP32

Beginning of the lesson

RGB LED Color Mixing on ESP32

One tiny plastic dome. Sixteen million colors. In this lesson you will make a single RGB LED glow red, green, blue, warm orange, electric cyan, hot magenta and pure white — and then fade smoothly from one color to the next, all controlled by your ESP32.

The secret is that an RGB LED is really three separate LEDs (Red, Green, Blue) packed into one body. If you can control how bright each of the three is, you can mix them into almost any color your eye can see. The ESP32's built-in LEDC PWM system gives us exactly that brightness control — on three pins at once. Let's build it up step by step.

What you will be able to do

  • Explain what an RGB LED is and how additive color mixing makes new colors from red, green and blue light.
  • Tell a common cathode RGB LED apart from a common anode one, and understand why the code logic flips between them.
  • Drive all three color channels with the ESP32 LEDC PWM system using duty values from 0 to 255.
  • Calculate the correct resistor for each color channel from its forward voltage on 3.3 V logic.
  • Produce named colors (yellow, cyan, magenta, orange, white) from RGB value triples, and write a smooth color fade loop.
  • Diagnose the three classic problems: wrong common pin, swapped channels, and colors that are too dim.

1. What exactly is an RGB LED?

A normal LED (Light Emitting Diode) is a tiny electronic component that gives off light when current flows through it the correct way. It has only one color.

Continue this lesson on YourAIZone

The full lesson has the complete explanation, worked examples, common mistakes, tests with instant checking and an AI tutor. Start right away as a guest, or create an account to keep your progress.

In the full lesson

  • The complete explanation
  • Worked examples
  • Common mistakes and how to avoid them
  • Test questions: 15
  • AI tutor that answers questions about the topic
  • Progress tracking for students, parents and teachers