How to connect and control a Raspberry Pi WS2801 RGB LED Strip

One of the many Raspberry Pi projects is the lighting of rooms or objects. LED strips are particularly suitable for this purpose, because many individual LEDs are aligned and each individual LED can display all RGB colors. Thus, some projects such as room lighting, Ambilight or e.g. a Christmas tree lighting can be realized. The effects of the colorful lights are impressive.

This article shows the general usage of the WS2801B on the Raspberry Pi. In doing so, we create an example in which LEDs of the strip are set (rainbow colors) and the brightness is dimmed. In the video at the end of the tutorial you can see the whole thing in action.



The RGB LED strips require an input voltage of 5V. The most favorable variant with 32 LEDs per meter has a distance between the LEDs of only 2.5 cm:

  • WS2801B LED strip with 32 LEDs per meter (US / UK)

There are also versions available that are dust and water-resistant (IP67). Each of the individual LEDs has a current consumption of about 60 mA. At one meter this is almost 2A. This is quite more than the GPIOs of Raspberry Pi can deliver. We therefore need an external current source that supplies power to the RGB stripe. Depending on how long your strip is, the maximum current must be higher. The power supply should therefore be able to supply 10A at 5 meters.
You have the choice between two possibilities:

DC Steckeradapter

With a plug adapter and power supply, the plus and minus poles can be easily connected to the LED strips.

  • For beginners: Power adapter (US / UK) + plug-in connector (US / UK) (c.f. picture on the right)
  • For experienced: Switching power supply (US / UK) + power cord (US / UK)

The difference is that a power cable has to be disconnected and then connected to the switching power supply. Since working with high voltage is dangerous, this is not recommended for beginners. For a power supply (similar to the laptop chargers) you only need an additional Power Jack adapter, so that you can detach the two voltage poles.

Last but not least jumper cables and a breadboard (US | UK) are required.


WS2801B vs. WS2812B

The WS2812 LED strips are often found on the Internet, which are also somewhat cheaper than the WS2801 models. However, these are not all too good for the Raspberry Pi, since the onboard audio output of the Raspberry Pi can not be used anymore. However, I will write another tutorialon how to use the WS2812 LED strips.

WS2801B strips have two data lines (data and clock), whereby individual LEDs can be addressed via the integrated SPI bus of the Raspberry Pi. This is different for the WS2812B models. These strips have only a single data pin, which is why before sending a lot more has to be calculated. For this reason the WS2801B RGB LED strips are preferable to the WS2812 for use on the Raspberry Pi, despite their supposedly smaller “serial number”.


Connect the switching power supply to the WS2801

Before we start, we have to connect the current source (only for the plug-in power supply). If you have selected the first variant – a charger-like power supply – you can jump to the next point. You only need to clamp the plug adapter to the power supply and loosen the screws.

Netzkabel für Raspberry Pi WS2801

Ensure that the power cord is compatible with 10A.

First of all: Working with 230V voltage can be deadly! While you make changes, all connections to the socket must be disconnected! Be careful and only work with it if you are sure of your cause. If this is not the case, I recommend the first power supply.

We start by cutting the power cord (e.g. old PC power cable). There are two or three cables inside. These must be carefully separated by about 1cm from the insulation, so that only the wire is visible in the cables. The switching power supply has three connections on the left side. On the one hand, “L” (phase / outer conductor) and “N” (neutral conductor), which are marked with AC (alternating current) and a grounding symbol. If your cable only contains two smaller cables, they will be connected to the AC connectors. If there are three, you must also identify the earth cable and connect it to the earthing symbol / “PE” connector.

Since the colors of the inner cables differ with older power cables, here is a brief overview, what color comes:

  • The black or brown cable comes to the outer conductor “L“.
  • The blue cable is connected to the neutral conductor “N“.
  • The green-yellow cable is connected to the protective conductor “PE” or grounding symbol.
Aufgeschnittenes Netzkabel mit abgetrennter Isolation

Cut-out two-core power cable with separated insulation.

For connecting the cables, the screws of the power supply must be loosened. Then place the wires under the screws. Make sure that they are well screwed and that the cables can not come loose. Normally, these devices still have a small protective flap, so that you don’t touch them accidentally. If you want to be safe, you can also wrap insulation tape around the sensitive spots.

On the other side, there are outgoing 5V voltage (+V) and the ground connections (-V or COM). As a test, you can use a Multimeter to measure the voltage as shown here:

Multimeter am Schaltnetzteil des WS2801 LED Strip

The output voltage of the switching power supply should be about 5V.


Wiring between Raspberry Pi, WS2801 and current source

Normally, the LED strips come with soldered plugs, which are intended for connecting several WS2801 strips. In addition, there is usually also a plug, which can be put on a Breadboard (4 connected cables). Furthermore, two additional cables for the external power connection from the LED Strip (red and black) are often used.

Since the color of the cable does not necessarily correspond to the standards, you should pay attention exactly which cable leads to which connection on the strip. Incorrect wiring on the Raspberry Pi could result in overheating or a short-circuit.

WS2801 RGB LED Streifen

The LEDs on one meter are numbered (1 – 32). The WS2801 RGB LED strip has 2 data pins (here: CK and SI) as well as the 5V connector and GND.

If you are aware of which cable leads to which connection, we can connect it. The Raspberry Pi should be switched off and the switching power supply should not be connected to the socket. The cables are connected as follows:

WS2801 LED Stripe Raspberry Pi (Switching-) Power Supply
 5V  —  +V
 CK / CI  Pin 23 (SCKL)  —
 SI / DI  Pin 19 (MOSI)  —
 GND  Pin 6 (GND)  -V or COM

For the connection to the switching power supply you can also use the two additional cables (if available). It is important that GND / ground is connected to both the Raspberry Pi and the external power supply. The structure now looks as follows:

Raspberry Pi WS2801B RGB LED Stripe Schaltplatine



Installing the Raspberry Pi WS2801 RGB LED Library

To control the LED strip we use a Python library from Adafruit. This special Raspberry Pi WS2801 library includes some functions for controlling the individual LEDs. The good thing is that each LED can be addressed individually and any RGB color is possible.

The library requires the SPI bus, which we have to activate (if not already done). We call the following:

sudo raspi-config

Under “Advanced Option” there is a point for “SPI”. We enable it and exit the configuration menu.

The installation now works quite simply via the Python package manager from the normal console / terminal. Preventively, we are first updating the package sources and installing PIP (this is not included on the Raspbian Lite versions by default):

sudo apt-get update
sudo apt-get install python-pip -y
sudo pip install adafruit-ws2801
Raspberry Pi WS2801B Weihnachtsbaumbeleuchtung

Christmas tree lighting with the WS2801.

If you have a lite version or SpiDev is not installed on your system, please follow this guide to install and activate it. On newer Raspbian versions, however, it should already be pre-installed.

Since the given example of the developers apparently does not work on all (fresh) Raspbian versions, I have changed that and expanded.



Sample code for brightness dimming of the WS2801 LEDs

The following example can be used and extended for your own projects. Here, a few colors (rainbows) are first switched in series, whereupon the brightness of the individual colors is dimmed. For this, it must be said that the brightness of a color can also be defined with the RGB value (see RGB Color Picker for this).

So let’s create a file:

sudo nano

The following content should be inserted:

In line 11 you have to specify the number of LEDs that are on the connected strip. This should be 32 meters. You can save the file with CTRL + O and close the editor with CTRL + X.

Here is the promised video with the different effects from the file:


I would be interested in what projects do you plan to do (Advent lighting, Christmas tree decoration, spice up rooms, “Infinite Mirror Table”, etc.)? Are there any requests for specific tutorials related to the Raspberry Pi WS2801B controller? I already have some ideas, but would also like to hear your opinion 🙂


58 Responses

  1. Hi guys, firstly well done getting your LED strip to work. Now I have spent days (literally ) looking at websites, level convertors, multimeter test, circuits and rxtx libraries, software like Glediator the whole kaboodle. The wife will raise eyebrows at the paypal account I can tell you. Currently trying to run a WS2801 strip with 160 rgb leds and if i’m lucky i’ll get three to light up. Is there a forum that will help me step by step?

  2. Hello !

    Nice work, can we use this setup to create an ambilight like for TV and HDMI Sources ?

    if Yes, I am noobie, would love to have a tutorial !!!


  3. Awesome, I can translate the website !

    Thanks for your answer.

    Is it possible to do ambilight for HD sources with a WS2812B only using a Rapsberry pie 3 and Hyperion (without adruino)? This way, I can use the WS2801 tutorial you did (if it’s exactly the same steps), using my WS2801B.

    Thanks for the awesome work !

  4. Ow, so the thing is : I can’t get ambilight for hdmi sources using Ws2812B without Andruino ?

    If there’s any way to make my Tv look awesome like yours, I would really appreciate your help !
    Thanks !!

    • Maybe you can, but I haven’t tried yet. If you use an external audio card, you can use the WS2812 on a Raspberry Pi (tutorial on my german site)

      • You can use spi with ws2812 and then onboard audio works fine.

  5. Hi Felix, thank you so much for this great guide, well explained!
    I have 2 questions :
    1 – If I use th “Switching power supply” solution, will it be possible to use it to power up the raspberry via tha GPIO pins (5v & Ground)? I read that if so there would not have any over current/voltage
    protection? seems dangerous! (source:
    2 – I’m writing a custom library in NodeJS to control the RGB strip, to reduce the size of the installation I would like to use the small Pi Zero board, The purpose is to update each led of the strip at a 50ms frequency. Do you think the GPIO bandwidth & the CPU of the Pi would handle such a frequency?

    Thank you again!

    • Hi Bilel,
      1 – it’s only an option but yes, you are wright.
      2 – you have to know that the Pi does not operate in real time like an Arduino, so it could be possible, that the frequency will vary. But actually, the Pi Zero can do that (see my YT channel, where I used a Pi Zero and WS2812).
      Best regards,

      • Thks for the quick answer Felix, the video answers my 2 questions!
        Is the lack of the over current/tension protection so important?

        I also seen your try with the Pi Zero is very very responsive, hope it will act the same way with a 5 meter 2801 strip xD

  6. Hi, what components such as resistors did you use on your breadboard? Also, I can somewhat make out the wire connections in the video , but It’s not a precise top down view, which would of been easier. If possible is there a schematic of the wires from the pi , leds, and external power going into the breadboard slots. Would make my life a lot easier. Been trying to figure this out for months. Thanks

      • Maybe you didn’t see what I was talking about but very clearly in the video, the one linked in this post, there are 3 resistors on the breadboard he is using. I just don’t know what ohm rating to get for the resistors, that’s the only thing left I need to do.

      • These aren’t resistors, these are diods, but I am not using them (had something else connected before and just forget to remove them).

  7. Very cool, thanks for sharing!! I’m a newbie to all this trying to keep up with my kid. Some projects we’re looking to do together are build a sound reactive lightning simulator as well as Christmas tree lights synchronized to music (so those are my tutorial suggestions ;)).

    • I’m looking for a tutorial to connect multiple WS2801B strips for a Christmas lights projects using the lightshowpi project. Any luck?

  8. Fantastic tutorial. I’m using AlexaPi and the Magic Mirror platform and will have these led’s built into the frame of the mirror. I would like these to be triggered when Alexa is summoned similar to an Echo. This would imitate the blue light moves around the Echo when it hears the trigger word. How would I program that scheme?

  9. I’m looking to connect multiple WS2801B strips for a christmas lights project. From the research i’ve done, it seems like I need a port expander like the MCP23S17. But I couldn’t find a wiring diagram. Can you point me in the right direction? Thanks!

      • Thank you so much for the reply. I think your blog is an excellent resource for learning. I really appreciate it.
        In your tutorial, you have a single long strip. I’m looking to connect 3+ strips simultaneously, use the lightshowpi project to control the lights and play music at the same time. I’ll power the three strips using three 5v-10A power supplies. Correct me if I’m wrong, but would I have to daisy chain the CK / CI Pin 23 (SCKL) and SI / DI Pin 19 (MOSI) from one strip to the next in order to achieve this?

  10. For a switching PS….couldn’t one use a PS from a PC. I mean it has 3.5 5.0 and 12 volts…and most of easy delivers 30 amp i think i have a china RGB chain that needs 12v – but i cant really remember anyways thats not the question…the question is about he PC PS….and wouldnt you be able to draw the 5 volts for your raspberry from same PS – as far as i know – ih has 2 or 3 or sometimes 4 channels with 5 volts…..even if there was a fluktuation wich i dont think there is…the PS should swich off – isn’t that right?

    Thanks in advance

    • I have a 12 volt 30 amp supply and I just connect a car USB charger to it in order to power my pi. I have used PC supplies in similar fashon which failed prematurely. I’ve been told they are designed to be fully loaded so leaving the other rails, 3.3v and -12v, unloaded causes it to prematurely fail (improper heat distribution stresses solder joints). Plus, some supplies have multiple 12v rails which equals the rated current so if it were rated at 35 amps, it may have two 12 volt, 15 amp rails and one 12 volt, 5 amp rail. Then again, I could just be buying cheep PC power supplies. 🙂

  11. Great turtorials and awesome work. I went thru the ws2812 turtorial and I am stumped. I keep getting an error saying ws.ws2811_init failed with -5 (mmap(), #something I can’t remember#). Needless to say, it won’t control my light strip, 308 channels using program I’m a noob to raspi. I’ve installed it on a raspberry pi 3 model B #I think#. I am using the 7″ touchscreen so could that be causing the issue? Any help would be greatly appreciated.

    • I figured it out. After careful debugging it was discovered that I am an idiot. I missed the step where virtual pin 18 is physical pin 12 on the IO header. Works almost flawlessly after that. Now I just have to figure out why the very first channel of an update string is slightly different than the rest. Example:

      for i in range(0, 19):
      strip.setPixelColor(133 + i, Color(200, 0, 0)
      strip.setPixelColor(133 – i, Color(200, 0, 0)

      As it runs, the first channel updated, ex. 133 – i, will be a different color than it should be. If blue it will be redish, if red it will be green and green works fine. Its almost as if the code doesn’t terminate properly at the end and it affects the first channel of the command at the end. Anyone have any thoughts?

    • And I just realized I am on the imcorrect tutorial page. Sorry. Should have been the ws281x tutorial. 🙁

  12. This was really helpful but wanted to note that – for raspian at least – SPI is enabled by editing \boot\conflig.txt and making sure that dtparam=spi=on isn’t commented out …

  13. How many LEDs is raspberry able to address from SPI? I hope it will not have problem with 320 LEDs. Thank you!

      • I tried it and have enough power. First 160 LEDs are working and other 160 LEDs not. It all lights randomly when I connect it and then when I send signal I can controll only first half. I do not know what to do with that, it is strange.

  14. so hi. Love the effort and taking the time to share. I’m very new. Like new-new. I can’t seem to get anything to work. I’m wondering if you could break it down a little more. I run the file and after about a minute I get the last LED to light up very dimly. That’s about all I got. I had it at 33 LEDs and thought I should shorten it I’m using a 5V 3A power supply so that should be more than enough for 16. Could you write a very simple script to just light up 1 LED? I’m not a python guy. I’m taking tutorials but not yet to the level I need to be to read all that is going on here. Also any other sources you can post would be helpful. Thanks Jesse

  15. I need some help with creating the file in the nano editor. When I open the file with “sudo nano” , an empty file opens in the terminal window but the text in your sample file is not there. I know this is a novice error but what am I missing? Thanks

    • Can someone tell me what directory the file should reside to make it run?
      It appears that changes in the Raspberry config have been made since this was
      written. The various interfaces can be enabled and disabled from the GUI.

      • %Run
        Traceback (most recent call last):
        File “/home/pi/”, line 6, in
        import Adafruit_WS2801
        ImportError: No module named ‘Adafruit_WS2801’

        This the error msg I get.

  16. I have it working!!! The whole problem all along was my lack of experience with Linux/Python in general. I had downloaded the Adafruit library from github, extracted the zip file but apparently I did not get it in the correct location under /home/pi/. This time I opened the file and followed the instructions in there for installing the library. I then opened a terminal and executed the file “”. And to my amazement it worked fine!! However, I still can’t get it to run from a GUI interface without getting error msgs. I am now troubleshooting a problem on the strip itself. The very first led stays red all the time while it is powered and not running. It doesn’t seem to be effected during the execution cycle.

  17. Hi, I bought a 5m strip of ws2801, wired it together, and nothing happens when I run the script. The led strip isn’t on at all. How would you debug this?


Leave a Comment

Your email address will not be published.

Subscribe to Raspberry Pi Tutorials and don't miss any new Tutorial!