How to control a RGB LED Strip Light with a Raspberry Pi Zero W

In this guide, you'll learn how to wire a 12 V RGB LED strip light to your Raspberry Pi Zero W and then control each color channel both from the command line and with Python.

What you'll need

What you are going to build

Wiring schematic

Wiring schematic showing the connections between power supply, Raspberry Pi, TIP120 transistors, and RGB LED strip light

1. Identify the LED strip light's wires

At one end of the LED strip light you'll see four leads or pads, typically labeled:

12V  G   R   B

2. Wire the TIP120 transistors

For each color channel:

Tip: insert a ~1 kΩ resistor between each GPIO pin and its transistor base. The base resistor protects both your Pi and the transistor, while still allowing enough current to switch the LED strip light fully on.

3. Tie all grounds together

Connect the Raspberry Pi's GND pin and the 12 V supply's negative terminal to the same ground rail. That way, the TIP120 emitters and the Raspberry Pi share a common reference.

4. Assign GPIO pins

Raspberry Pi Zero GPIO Pinout

Raspberry Pi Zero GPIO Pinout

On the Pi Zero's 40-pin header, pick three GPIOs for your colors. I'm using the following GPIO pin mapping:

And use any GND pin to complete the common ground.

5. Power up and test

  1. Power your 12 V supply (which now feeds +12 V to the strip and ground to the TIP120s).
  2. Boot the Raspberry Pi normally.
  3. First you will need to start the pigpiod daemon which is required for GPIO control:
    sudo pigpiod
  4. Now that everything is wired up, you can control the LED strip using the pigs command (from the pigpio library), which allows PWM control of GPIO pins.
  5. PWM value range:
  6. Example: Set strip to orange (RGB 255, 165, 0):
    pigs p 27 255   # Red to full
    pigs p 17 165   # Green to medium
    pigs p 22 0     # Blue off
    This will mix red and green to produce orange.

6. Python code

The python code for controlling the LED strip light is available in the GitHub repository https://github.com/janrothen/ledstriplight.