Example Code for Arduino - moving head beam light

Last revision 2026/02/05

The "moving head beam light" is a common type of stage lighting fixture that uses the DMX512 protocol and can rotate 360 degrees in both the X and Y directions. While the specific instructions for different manufacturers' moving head beam lights may vary, the overall method of use is consistent. The example below will illustrate how to control a moving head beam light.
moving head beam light

Hardware Preparation

ESP32-S3-Based DMX512 Smart Lighting Controller x 1

Control Commands for Moving Head Beam Light

The following is an example illustrating the control commands for moving head beam lights, as shown in the table below:

Channel/Address Data Function Description
1 0-255 X-Axis Rotation
2 0-255 Y-Axis Rotation
3 0-7 Turn Off Light
8-134 Overall Dimmer
135-239 Strobe
240-255 Turn On Light
4 0-255 Red Light Value
5 0-255 Green Light Value
6 0-255 Blue Light Value

Different moving head beam lights have different functions and control commands. It is essential to refer to the moving head beam light's function description for proper operation and control.

Hardware Connection

Both the DMX512 controller and the moving head beam lights require independent power supplies. They only need one XLR connection cable for communication. Additionally, the moving head beam lights can be cascaded with light strip controllers or other DMX512 devices for simultaneous control.
moving head beam lights

Program Writing

If you have not yet downloaded and imported the DMX512 library, please download it from this link and import it: https://github.com/DFRobot/DFRobot_DMX512

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");
    dmx512.write(3,255); //Turn On the Light
}

void loop() {
    dmx512.write(1,255); //Assign a value of 120 to channel 1, adjusting the angle on the X-axis.
    dmx512.write(2,50); //Assign a value of 50 to channel 2, adjusting the angle on the Y-axis.
    dmx512.write(4,200); //Assign a value of 200 to channel 4, adjusting the red value of the light.
    dmx512.write(5,100); //Assign a value of 100 to channel 5, adjusting the green value of the light.
    dmx512.write(6,120); //Assign a value of 120 to channel 6, adjusting the blue value of the light.
    delay(1000);
    dmx512.write(1,120); //Assign a value of 30 to channel 1 to adjust the X-axis angle.
    dmx512.write(2,150); //Assign a value of 150 to channel 2 to adjust the Y-axis angle.
    dmx512.write(4,50); //Assign a value of 50 to channel 4 to adjust the red value of the light.
    dmx512.write(5,160); //Assign a value of 160 to channel 5 to adjust the green value of the light.
    dmx512.write(6,40); //Assign a value of 40 to channel 6 to adjust the blue value of the light.
    delay(1000);
}

Result: The following program demonstrates how to control the light and angle of the moving head beam lights. The program changes the angle and color of the light projection every second.

Was this article helpful?

TOP