Addressable LED strips such as the WS2812B use a single data wire to control each LED individually in colour and brightness. This article shows how to connect a WS2812B strip to an M-Duino or ESP32 PLC and control it using the Adafruit NeoPixel library in the Arduino IDE.
What you need
- M-Duino PLC o ESP32 PLC
- WS2812B addressable LED strip (or compatible, such as NeoPixel)
- 5 V power supply for the LED strip (separate from the PLC supply if the strip draws significant current)
Wiring the LED strip
Most WS2812B strips have three connections: power (5 V), GND, and data input. Connect GND to the same ground as the PLC. Connect the data wire to one of the direct PLC pins listed below.
Pin options on the M-Duino (5 V logic)
| M-Duino PLC label | Arduino pin number |
|---|---|
| RX0 | 0 |
| TX0 | 1 |
| RX1 | 19 |
| TX1 | 18 |
| SO | 50 |
| SI | 51 |
| SCK | 52 |
| Pin 2 | 2 |
| Pin 3 | 3 |
Pin options on the ESP32 PLC (3.3 V logic, except SCL and SDA)
The ESP32 GPIO pins operate at 3.3 V. WS2812B strips typically accept a 3.3 V data signal with 5 V power without issues, but check the datasheet for your specific strip. The SCL and SDA pins are 5 V tolerant on the IS ESP32 PLC.
| ESP32 PLC label | ESP32 GPIO |
|---|---|
| SO | 19 |
| SI | 23 |
| SCK | 18 |
| TX1 | 17 |
| SCL * | 22 |
| SDA * | 21 |
* SCL and SDA operate at 5 V on the IS ESP32 PLC.
Software setup
Install the Adafruit NeoPixel library from the Arduino IDE Library Manager (Tools > Manage Libraries, search "NeoPixel"). Also install the Industrial Shields boards package for your PLC:
Arduino sketch: LED colour cycle
The sketch below lights each LED green sequentially with a 500 ms delay between them. Adjust PIN to match your wiring and NUMPIXELS to the number of LEDs in your strip.
#include <Adafruit_NeoPixel.h>
#define PIN 0 // Pin de datos conectado a la tira LED
#define NUMPIXELS 3 // Número de LEDs en la tira
#define DELAYVAL 500 // Retardo entre LEDs en ms
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
pixels.begin();
}
void loop() {
pixels.clear(); // Apaga todos los LEDs
for (int i = 0; i < NUMPIXELS; i++) {
pixels.setPixelColor(i, pixels.Color(0, 50, 0)); // Verde
pixels.show();
delay(DELAYVAL);
}
}The pixels.Color() function accepts RGB values from 0 to 255. To choose a different colour, change the three arguments: red, green, blue. For example, pixels.Color(255, 0, 0) produces red and pixels.Color(0, 0, 255) produces blue. Use pixels.clear() to turn off all LEDs.

Controlling addressable LED strips with M-Duino and ESP32 PLC