Working Principle

The ESP32 controls the RGB LED by independently adjusting the red, green, and blue channels. Instead of simply switching each channel ON or OFF, the ESP32 uses Pulse Width Modulation (PWM) to control the amount of power delivered to each LED channel. This changes its apparent brightness.
Each color channel can be assigned a different PWM duty cycle. When only the red channel is activated, the LED produces red light; activating only the green or blue channel produces green or blue light. By adjusting the brightness of these three channels, the ESP32 can create a wide range of colors.
For example, combining red and green produces yellow, while combining red and blue produces purple or magenta. Combining green and blue produces cyan. When red, green, and blue are all set to high brightness, the three colors combine to produce white light.
This project demonstrates the basic principle of RGB color mixing and PWM control. Students can experiment with different PWM values to create their own colors and understand how a microcontroller can control LED brightness and color electronically.