Wiring WS2813 Addressable LED Strips to the Raspbery Pi

Are you a beginner in Raspberry Pi and don’t know how to control WS2813 Addressable LED Strips with the help of Raspberry Pi? Please check the following passage, which will explain everything you want to know. 

1. Tools Preparation

Raspberry Pi board

The Raspberry Pi is a tiny computer with all important parts built onto one single circuit board, which is filled with the CPU, graphics chip, memory (RAM), USB ports, an HDMI port , an SD card slot which holds the operating system and some extra pins for connecting electronics (GPIO).

At first, Raspberry Pi is used mainly as a tool for learning programming and electronics in schools. Because it’s become really affordable and easy to get, people now use it for lots of other activities. You’ll find it running home media centers, being used to test new ideas (prototyping), and in all sorts of DIY projects like building robots, smart home gadgets or old-school game consoles. Raspberry Pi is handy as a simple and low-cost server for different tasks and the versatility makes it super popular with hobbyists, students, and professionals alike.

DC5V LED Driver

  • Output voltage: DC5V
  • Power: 400W
  • Input voltage: AC220V~230V

If you have interests in waterproff power supply, please check our page: Waterproof LED Driver.

Arduino 5V LED Power Supply
converter

The 4-level converter, as a power electronic topology, is widely used in high-voltage domains such as HVDC system and industrial motor drives. It differs from simpler two-level converters by producing four distinct output voltage levels. By intelligently coordinating multiple semiconductor switches and DC voltage sources and capacitors, it achieves a staircase waveform. The converter has some key advantages such as less harmonic distortion in output voltage, lower component burden and improved efficiency. All of these features help with enhanced power supply performance in high-power applications.

DA3 5V WS2813

Paramaters:

  • IC: WS2813 
  • Voltage: DC5V
  • Feature: This WS2813 LED Strip uses built-in WS2813 LED IC. Besides, WS2813 led strip has dual data lines, which meas it supports breakpoint resume transmission. The LED density is various such as 30led, 60led, 96led, 144led per meter. If you are interested in difference between WS2813 IC and other WS IC such as WS2814 and WS2815, please check this blog: WS2813 vs WS2814 vs WS2815.

2. Raspberry Pi 4B Control Board and WS2813 LED Strip Wiring Diagram

Raspberry Pi WS2813 wire diagram

Notice:

1. The current of the light strip is too large, please use an external power supply topower the light strip;

2. The DC3.3/5V interface is the output voltage port of the control board, which can’t be connected to the power supply;

3. The control board is powered by a dedicated power supply, and the light strip ispowered by DC5V, Please note that the GND is shared;

4. The similarity in wiring between RGB and RGBW does not extend to their programs, which cannot be shared.

5. The more points, the lower the refresh rate;

6. Before connecting light strip signal pins, convert Raspberry Pi 4B’s 3.3V GPIO levels using 74HCT125 or MOSFET circuits.

3. Raspberry Pi WS2813 LED Connection Diagram

Raspberry Pi WS2813 connection

Please connect all the wires according to the connection diagram. Please pay attention to the V+ PIN  and don’t mix them up. 

4. Programming

Raspberry Pi programming
				
					#!/usr/bin/env python3
from rpi_ws281x import PixelStrip, Color
import time
import math
import signal
import sys

# === LED strip setup ===
LED_COUNT = 100        # LED quantity
LED_PIN = 18          # GPIO18
LED_FREQ_HZ = 800000  # signal frequency(Hz)
LED_DMA = 10          # DMA channel
LED_BRIGHTNESS = 150  # brightness(0-255)
LED_INVERT = False    # signal reverse
LED_CHANNEL = 0       # PWM channel

# format led strip
strip = PixelStrip(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL)
strip.begin()

# === color generation function ===
def wheel(pos):
    """change the value of0-255 into rainbow color(red→green→b→→lue recycle)"""
    pos = 255 - pos  # reverse color direction(optional)
    if pos < 85:
        return Color(pos * 3, 255 - pos * 3, 0)
    elif pos < 170:
        pos -= 85
        return Color(255 - pos * 3, 0, pos * 3)
    else:
        pos -= 170
        return Color(0, pos * 3, 255 - pos * 3)

def smooth_wheel(pos):
    """more smooth rainbow color transition(trigonometric function version)"""
    r = int(255 * (0.5 + 0.5 * math.sin(pos * 0.0245)))
    g = int(255 * (0.5 + 0.5 * math.sin(pos * 0.0245 + 2.094)))  # +120°
    b = int(255 * (0.5 + 0.5 * math.sin(pos * 0.0245 + 4.188)))  # +240°
    return Color(r, g, b)

# === main effect function ===
def rainbow_flow(speed_ms=20, smooth=True):
    """recycle full color running effect
    :param speed_ms: basic speed(ms)
    :param smooth: whether USE_SMOOTH_COLOR
    """
    step = 0
    try:
        while True:
            # dynamic_speed control(optional)
            dynamic_speed = speed_ms * (0.8 + 0.2 * math.sin(step * 0.01))
            
            for i in range(strip.numPixels()):
                # calculate color_phase(form flow effect)
                hue = int((i * 256 / strip.numPixels()) + step) % 256
                color = smooth_wheel(hue) if smooth else wheel(hue)
                strip.setPixelColor(i, color)
            
            strip.show()
            time.sleep(dynamic_speed / 1000.0)
            step += 1
    except KeyboardInterrupt:
        pass

# === escape safely ===
def signal_handler(sig, frame):
    print("\n close LED...")
    for i in range(strip.numPixels()):
        strip.setPixelColor(i, Color(0, 0, 0))
    strip.show()
    sys.exit(0)

signal.signal(signal.SIGINT, signal_handler)

# === main program ===
if __name__ == '__main__':
    print("=== addressable LED strip full color flow effect ===")
    print("Ctrl+C close program")
    
    # parameter setup
    USE_SMOOTH_COLOR = True  #  USE_SMOOTH_COLOR
    BASE_SPEED_MS = 15       # basic flow speed(ms)
    
    rainbow_flow(speed_ms=BASE_SPEED_MS, smooth=USE_SMOOTH_COLOR)
				
			

5. Video

The following video will show you the lighting effect of the WS28131 LED Strip after we finish all steps introduced in the former passage. 

After the whole introduction of the wire connection, I believe you can have a basic command of the Raspberry Pi. You can create the lighting effect you need by programming. 

If you are interested in how to control WS2813 LED Strip via other single-board controller, please check this blog: How to Program WS2813 Addressable LED Strips with ESP32.

Feel Free To Contact Us

We will reply your email within 12 hours.

Ask For A Quote