I've been thinking of setting up lighting in my server rack for a while and bought a cheap neopixel-type LED strip on Amazon a few months ago that I just left and haven't really touched. I recently bought a few Raspberry Pi Picos for $2/each when they were on sale and decided to finally put one to use.

Here is what I ended up with (no fancy animations yet), lighting up when the door to the server rack is opened, triggered by an infrared motion sensor:

I wired this up with a buck convertor so it can accept any input voltage 5v to 24v and output a stable 5v for all the components. See more info about that convertor in the parts list below.


Raspberry Pi Pico Neopixel Controller w/ Motion Detection Trigger

Here are some notes about the schematic - this is a pretty common build:

  • 1000 microfarad capacitor (from this set) is added across the +/- terminals of the LED strip - this helps provide a more stable current to prevent damaging the pixels
  • 470 ohm resistor (from this set) between the digital connection of the LED strip and the microcontroller - this is not listed in some schematics - but I saw lots of errors and weird behavior without it, so I would definitely include it
  • External power supply vs USB power: depending on the length of the LED strip/power draw of your animations you might be able to power it by USB, but it isn't recommended, as if you are pulling too much power you might damage a USB port if it isn't adequately protected

The Build

Power Supply and Case

The case was salvaged from a defective PoE splitter - I removed the actual components to use elsewhere and had a nice-sized case for a microcontroller left over.

Raspberry Pi Pico Neopixel Controller w/ Motion Detection Trigger

I hot-glued in the jack and pins, soldered the convertor and then hot-glued that in.

Then I fit the Pico microcontroller on the other side and hot-glued that. I wanted to be able to access the pins and USB port cleanly while the device is sealed up.

Installing and Wiring the Microcontroller

Raspberry Pi Pico Neopixel Controller w/ Motion Detection Trigger

I wired up and soldered the following connections per the schematic:

  • 1000 microfarad capacitor +/- to external pin 1 and 3
  • 5V and GND from convertor out to external pin 1 and 3
  • Digital Out from Pico PIO 0 to external pin 2
  • 5V and GND from convertor out to external pin 4 and 6
  • Digital Out from Pico GPIO 22 to 470 ohm resistor to external pin 5
  • 5V and GND from convertor out to VSYS and GND of Pico

Please take note as the wiring here is written out respectively - for example, 5v and GND to 1 and 3 means 5V to 1 and GND to 3. Make sure not to confuse polarity (matching +/-) in your circuit so you don't burn your components.

Testing it out, looking fancy with the lights working!

Raspberry Pi Pico Neopixel Controller w/ Motion Detection Trigger

Add in a resistor between the Digital out of the LED strip and the MCU. As mentioned above, this circuit can work without a resistor, but I believe it can damage the GPIO pin (not sure about this) but does seem to lead to errors and weird behavior without it.

Raspberry Pi Pico Neopixel Controller w/ Motion Detection Trigger

Setting up the development environment

I found a guide by Chris Wood for developing with MicroPython for the Raspberry Pi Pico using his VSCode extension. It was extremely helpful and got me up and running quickly - this was my first go at using MicroPython.

Once you get set up with your development environment and can push code to the Pico, move on to the next step:

Writing the code for a motion-sensor trigger

Disclaimer: the code here was just hacked together to allow fade-in and fade-out of a white light, and isn't optimized in any way. Eventually if I improve it or optimize it, I'll update that here.

Luckily, there is a neopixel (ws2812b) example listed on the Raspberry Pi Pico getting started page, so it was really easy to get up and running. See the repo here.

The important takeaway from here is to add the ws2812b.py file to your project root.

See the code at the end of this article.

To install in the rack, I stuck the LED strip to a strip of cardboard and hot-glued that to the top of the rack. I then hot glued the IR sensor to the top right corner of the rack so it would be able to detect when the door is closed. Since the door is black and cool, the IR sensor didn't detect it until I taped a white piece of paper right where it meets with the sensor.

Raspberry Pi Pico Neopixel Controller w/ Motion Detection Trigger

Parts List

Please note that I only link products that I have bought and tested myself, and some of the links above are Amazon affiliate links, which I earn a commission from (at no additional cost to the buyer).

Microcontroller Code

Here is the trigger fade in/fade out on motion detection script: