Example Code for Arduino - Control the light strip
Last revision 2026/02/05
Hardware Preparation
ESP32-S3-Based DMX512 Smart Lighting Controller x 1
Function Description
Controlling the light strip requires the use of a DMX512 driver. The main function of the driver is to drive the light strip to emit light. DMX512 can be cascaded to form light strips with more channels. Furthermore, multiple drivers can be controlled by a single DMX512 programming controller.
DMX512 driver instructions and settings
The driver used in this WIKI example is a 24-channel LED light strip or 8-channel RGB light strip driver. You can also cascade multiple drivers using the RJ45 port or XLR port, with a maximum of 21 drivers cascaded to form 512 LED light strips or 170 RGB light strips.
This device can be connected to a DMX512 programming controller via a three-pin XLR port to receive DMX512 control signals, thereby controlling the lighting effects.
The use of other drivers is similar to the example in the routine. For specific usage, please refer to the corresponding driver manual.
Functional Indicator Diagram



Controller to Driver Wiring Diagram
The DMX512 interface internally uses an RS485 bus. Whether the interface is connected to IN or OUT, the effect is the same, and there is no need to distinguish between them. You can choose to plug the male or female head based on the connectors of your connecting cable.
The driver needs to be powered separately to function properly. The operating voltage of the driver is between 5V and 24V. It is important to note that the power supply voltage must match the rated voltage of the light strip. For example, if the light strip is 12V, the power supply voltage of the driver must be 12V.

LED Light Strip Wiring Diagram

RGB Light Strip Wiring Diagram
The driver used in this example supports common anode RGB light strips. RGB light strips are divided into common anode and common cathode types, depending on whether the common pole is the positive pole (common anode) or the negative pole (common cathode). Pay attention to this distinction when purchasing light strips.

Driver Address Setting
RGB light strips consist of three different colored lights: red, green, and blue. Each color is connected to a separate channel on the driver, so one RGB light strip occupies three channel addresses.
Since the drivers can be cascaded, each channel has its own channel address. After setting the address for the first channel, the addresses for the subsequent channels are incremented by 1.
The channel address setting method is as follows:
- Press and hold the "A: Address" button or the "H: Mode" button. The brightness of the digital tube will increase.
- Press "-" to decrease the address or "+" to increase it. The address range is 1-512.
- Set the starting address to A001.
Complete the starting address setting.
** As shown in the figure: **


Software Preparation
-
Use a Type-C USB cable to connect the USB interface on the back of the controller to the computer.
-
Open Arduino IDE.
-
From the IDE menu, select: Tools > Board > ESP32S3 Dev Module.
-
From the IDE menu, select: Tools > Port > The port corresponding to the development board (e.g., COM3 in the figure, the port number may vary on different computers).
-
download and import the DMX512 library. Here is the link to the library: https://github.com/DFRobot/DFRobot_DMX512


Below are three methods to turn on and off the light strip, demonstrating the functionality and usage of three APIs.
Write Data to a Specified Address
API Prototype: dmx512.write(DMX512 Address, Data to be Written)
API Description: This is the most basic command for writing data to a DMX512 address. Based on this command, almost all DMX512 control functions can be achieved.
Data Range:
- DMX512 Address:1-512
- Data to be Written:0-255
Arduino Code
#include "DFRobot_DMX512.h"
DFRobot_DMX512 dmx512;
void setup() {
Serial.begin(115200);
while(dmx512.begin() != 0){ //Initialize DMX512
Serial.println("init error");
delay(1000);
}
Serial.println("init OK");
}
void loop() {
dmx512.write(1,255); //Assign a value of 255 to channel 1.
delay(1000); //Delay one second.
dmx512.write(1,0); //Assign a value of 255 to channel 0.
delay(1000); //Delay one second.
}
Result: Turn on the first LED light strip and blink at intervals of 1 second.
LED Light Control
API Prototype: dmx512.LEDLight( Starting Address, The number of LED lights, Brightness)
API Description: This command is specifically for controlling LED light strips. Based on this command, it is very convenient to control the LED light strips.
Data Range:
- Start Address: 1-512
- Number of LED Lights: 1-512
- Brightness: 0-255
Arduino Code
#include "DFRobot_DMX512.h"
DFRobot_DMX512 dmx512;
void setup() {
Serial.begin(115200);
while(dmx512.begin() != 0){ //Initialize DMX512.
Serial.println("init error");
delay(1000);
}
Serial.println("init OK");
}
void loop() {
dmx512.LEDLight(1,8,255); //Starting from channel 1, light up a total of 8 channels of LEDs with maximum brightness.
delay(1000); //delay 1s
dmx512.LEDLight(1,8,0); //Turn off the first to the eighth LED light strips.
delay(1000); //delay 1s
}
Result: Light up the first to the eighth LED light strips and make them blink at 1-second intervals.
RGB Light Control
API Prototype: dmx512.RGBLight(Start Address, Number of RGB Lights, Red Channel, Green Channel, Blue Channel)
API Description: Each RGB light strip will occupy 3 channels, which is inconvenient for calculation. To facilitate use, a command specifically designed to control RGB light strips has been developed. Based on this command, it is very convenient to control RGB light strips. Data Range:
- Start Address: 1-512
- Number of RGB Light Strips: 1-170
- RGB Channel Value: 0-255
Arduino Code
#include "DFRobot_DMX512.h"
DFRobot_DMX512 dmx512;
void setup() {
Serial.begin(115200);
while(dmx512.begin() != 0){ //Initialize DMX512
Serial.println("init error");
delay(1000);
}
Serial.println("init OK");
}
void loop() {
dmx512.RGBLight(1,8,0,0,255); //Starting from address 1, light up a total of 8 RGB light strips, with the RGB light strips displaying blue.
delay(1000); //Delay 1s
dmx512.RGBLight(1,8,0,0,0); //Turn off a total of 8 RGB light strips starting from address 1.
delay(1000); //Delay 1s
}
Result: Light up the first to the eighth RGB light strips, displaying the color blue, and make them blink at 1-second intervals.
Was this article helpful?
