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 🙂


84 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. 🙂

      • I have powered lots of projects from desktop psu’s there is no need to have it under load if it is a modern one then you have to bridge two of the lines to get the psu to power up I have used one to build a bench power supply which had 3.3v 5v 12 v and one adjustable output that could be adjusted for either constant current or constant voltage which I used for charging batteries with.

  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?

      • I’ve got this problem too… wiring is correct (same as yours – though with different colours, I had to read the small print to confirm which was which!), voltage is OK… same supply as I’ve use with a string of 150 WS2811 LEDs. Code runs, but no LEDs. I’ve spent several hours swapping components in and out but no joy.
        Other than what is discussed in the article, are there any other settings on the Pi that might need changing? I (and Google) and are completely out of ideas. 🙁

      • I figured it out…
        I’ve got the waterproof version where the circuit boards are encased in plastic. It turns out I was mis-reading the distorted letters on the PCB and had the lights connected the wrong way round.
        Maybe I just need glasses…
        So, ignoring my little problem, this article is the best on the web to explain how to do this. Thanks!

  18. Thank you. It functions as described at the first attempt.
    Very important point: You wrote: “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.” I had to remove the shrink tubing to find, that the green and the red cable had been soldered together”!
    I am a beginner, how do I see in the program, that Pins 19 and 23 should be used?

    • I had that problem, too. After removing the shrink, it was clear to me. I use spidev0.0, which needs MOSI (Pin 19) and SCLK (Pin 23).

  19. Thank you for this tutorial! I have used it as a starting point to create an extension for the Scratch programming language. Now my children (and, in fact, many other kids in the school they are attending) can program the led strip. It’s so great to see the fun they’re having with it. I have uploaded the stuff I created to Github: The README on this page also refers to your tutorial. Again, many thanks!

  20. Thanks for the great tutorial. I have the LED and have ordered the PI.

    My goal is to put these LEDs on my motorcycle. There will strips of LEDs placed in various places on the bike. I understand I need to keep the wires going from one strip to the next in series. That will take some doing, but not a big problem. My concern is the timing. Is there going to be an issue with the length of wire between the strips of LEDs causing a timing issue?

  21. Hi! Very cool project, this is what I needed! But i have a question. Is it possible to run on Windows 10 IoT Core? Or import the library on Visual studio to run it in C#

  22. Hey, will this same schematic and programming work with the WS2811 leds? I would like to create a panel of pixels where I can display different pictures and even animate text. Is this possible with what you have done here? If not, would you consider doing that tutorial? Thanks!

  23. I was looking for information on using WS2812B LEDs connecting to audio output plug and read “onboard audio output of the Raspberry Pi can not be used anymore” I was curious as to why??

  24. The power supply that you say is the best can only be used in UK if it is inside a case which has a cover over the terminals that can only be accessed either by unscrewing it or unlocking it you are not allowed to use anything that a child could get their fingers to the live terminals.
    Except for that this is a great tutorial many thanks for your work.

  25. Hey,

    Appreciate the time you have taken with this. I am currently working my way through it. I have a question about the code

    The Wheel() function takes r,g,b values that it generates and turns them in to a single value color with Adafruit_WS2801.RGB_to_color(). Then that single value color is passed to Adafruit_WS2801.setpixel() which splits the color out into separate R,G,B values and then passes those to Adafruit_WS2801.set_pixel_rgb().

    Is there a good reason for taking the seperate values into one, then immediately splitting back out like this? On the face of it it seems inefficient but maybe it’s just easier… i dont know.



  26. Thanks a load for this article. With it’s wonderful and complete description, I was able to build a 120 pixel LED light string and with playing around with the code, I learned sooo much.

  27. The Adafruit_WS2801 library is now deprecated.

    Quote: This library has been archived and replaced by a new library that is Python 3 compatible and works with a wide range of Linux/hardware
    This library is no longer supported. Please use the new library

    Could you update the example and library usage please?

    • Hi,

      This seems to work to set it up on a Pi;

      # Simple demo of of the WS2801/SPI-like addressable RGB LED lights.
      import time
      import board

      # Import the WS2801 module.
      import adafruit_ws2801

      # Configure the count of pixels:
      pixel_count = 160

      pixels = adafruit_ws2801.WS2801(board.SCLK, board.MOSI, pixel_count * 3, brightness=0.8, auto_write=False)

      Good luck!

  28. Hi,
    is it possible to install multiple led strips on the same board and control them from the rpi ?

  29. Hi,

    Thank you for this helpful tutorial. While I can digest and understand the code fairly well, I am a total newbie when it comes to understanding what’s going on with the wiring.

    Could someone explain why I need to also setup a ground on the Pi as well?

    Thank you, Felix!

  30. How many unique light strings can the base Raspberry Pi control? If more accessory hardware is purchased to provide more SPI busses, what is the theoretical limit of unique light strings that the Raspberry Pi can control?
    Thank you.

  31. Great work! This is an excellent introductory post for LED control. Any guides on integration with the Amazon Alexa module? i.e. having the LED strip turn on once the Alexa wake-word is activated.

  32. Is there a preference to what kind of Power Adapter I should get? As well as for the Plug in Connector because right now I am scrolling around Amazon trying to find ???? so is there a preference.

  33. Hi
    great tutorial, very useful but I’m after running more LED’s 600, but can only get the first 160 to run, anyone any ideas

  34. This is great, thank you so much!! I set up a small nodejs server on my pi and then control the leds with websockets. Probably the coolest thing ive done with the pi yet. Cheers!


Leave a Comment

Your email address will not be published.

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