RGB LED Controller

ESP32 Project

Five-Channel RGB LED Controller

In this project, I build a five-channel RGB LED controller using two ESP32 boards, PWM output stages, an ILI9341 touchscreen display, and I2C communication between the two controllers.

The controller can drive five separate RGB LED channels. Each RGB channel needs three individual outputs for red, green, and blue, so the final controller uses 15 PWM outputs in total.

DIY ElektroBox five-channel RGB LED controller with touchscreen display
Master ESP32Handles the ILI9341 touchscreen interface and sends selected RGB values over I2C.
Slave ESP32Receives channel and color data, then controls the RGB PWM output stages.
Output channelsFive separate RGB LED channels with 15 PWM outputs in total.

1. Required Parts

Controllers2 ESP32 development boards.
DisplayILI9341 touchscreen display module.
PrototypeBreadboard, Dupont wires, resistors, and test LEDs.
Output stageTransistors or suitable logic-level MOSFETs.
Final lightingRGB LED strips and external power supply.
OptionalCustom PCB, display housing, electronics housing, and screws.

2. Required Tools

  • Soldering iron
  • Solder wire
  • Wire cutter
  • Wire stripper
  • Multimeter
  • Computer with Arduino IDE
  • USB cables for the ESP32 boards
  • Optional PCB design software and 3D printer

3. Project Structure

For more complex projects, I like to start with simple subsystem prototypes. This makes the project easier to debug because every function can be tested separately before everything is combined.

PWM color and brightness control
Transistor or MOSFET output stage
Touchscreen display test
I2C communication between two ESP32 boards
Final five-channel RGB controller
PCB and housing design

4. Test the PWM Color Control

The brightness of each LED color is controlled with PWM. PWM stands for Pulse Width Modulation. The ESP32 switches the output on and off very quickly. By changing the duty cycle, the average power delivered to the LED changes and the LED appears brighter or darker.

For the first prototype, connect one red, one green, and one blue LED to three transistor output stages. In this example, the ESP32 uses GPIO16 for red, GPIO17 for green, and GPIO5 for blue.

PWM test code
ESP32 RGB PWM test

5. Output Stage

LED strips need more current than an ESP32 pin can provide. The ESP32 PWM pins should only control the gate or base of the output stage. The LED strip current flows through the external transistor or MOSFET.

For reliable operation, use suitable logic-level MOSFETs and make sure the LED power supply is dimensioned for all channels at full brightness.

RGB LED controller prototype with touchscreen

Prototype setup with touchscreen control and RGB output testing.

Important: The ESP32 and LED strip power supply must share a common ground. Without a shared ground, the PWM signal does not have a stable reference.

6. Touchscreen Interface

The master ESP32 handles the touchscreen display. It shows the user interface and allows selecting channels, colors, and brightness values.

7. I2C Communication

Because the touchscreen already uses many pins, I split the system into two controllers. The master ESP32 sends the selected channel and RGB values to the slave ESP32 over I2C. The slave ESP32 then updates the PWM outputs.

I2C data concept

A simple message can contain the selected channel number and three color values. For example: channel 3, red 120, green 40, blue 255.

Example I2C payload

8. Final Software Structure

The final controller uses two separate Arduino sketches. The Master ESP32 runs the touchscreen menu, stores the RGB values for five independent channels, converts the selected color into RGB565, and sends the active channel data to the slave controller over I2C.

The Slave ESP32 listens as an I2C receiver at address 0x42. It receives three bytes from the master, converts the RGB565 color back into 8-bit red, green, and blue values, and updates the PWM outputs for the selected RGB LED channel.

Master sketch Touchscreen user interface, tab menu, RGB sliders, RGB565 conversion, and I2C transmission.
Slave sketch I2C reception, RGB565 decoding, five-channel color storage, and 15 PWM outputs.
I2C message The master sends three bytes: channel index, RGB565 high byte, and RGB565 low byte.
Touch input → Master ESP32 updates the selected channel and slider values
Master ESP32 → converts the selected RGB color into RGB565
I2C message → channel index + RGB565 high byte + RGB565 low byte
Slave ESP32 → decodes RGB565 back to red, green, and blue
PWM outputs → drive the selected RGB LED channel through the output stage
LED_Controller_Master.ino

Upload this sketch to the ESP32 connected to the ILI9341 touchscreen. This board is the user interface controller and sends the selected channel color to the slave ESP32.

LED_Controller_Master.ino
LED_Controller_Slave.ino

Upload this sketch to the ESP32 connected to the RGB output stages. This board receives the selected color and updates the PWM pins for the five RGB LED channels.

LED_Controller_Slave.ino

9. Common Problems

The LED strip does not light up

Check the power supply, shared ground, MOSFET wiring, and LED strip polarity.

The colors are swapped

Check the channel order. Some LED strips or wiring layouts use a different RGB order.

The touchscreen works but the LEDs do not react

Check the I2C wiring, addresses, pull-up resistors, and whether both ESP32 boards are powered.

10. Final Result

The final controller uses a touchscreen as the user interface and a second ESP32 for the RGB output channels. This keeps the project modular and makes the wiring easier to understand.

The design can be expanded with saved presets, animations, Wi-Fi control, or a custom PCB for a cleaner final build.