NeoPixel Christmas Tree Lights Controlled by a Raspberry Pi - Raspberry Pi Projects, Tutorials, Learning DIY Electronics - Makergenix



NeoPixel Christmas Tree Lights Controlled by a Raspberry Pi

This project does not cover home network security; nonetheless, you should use passwords and ensure that your network is adequately protected from outside access.

NeoPixel Christmas Tree Lights Controlled by a Raspberry Pi

Without any formal IT experience, I was able to accomplish this in a short amount of time because to all of the amazing open source contributions that I have linked throughout the project.

If you have any new light modes, please share them in the comments; I'll be working on a twinkle function next.

Parts Needed for the Project:

  • Raspberry Pi is a small computer that runs on the (I am using a Zero V2 however any Pi with WiFi will work)
  • String of NeoPixels (I am using 5x50 strings joined together)
  • 5 volt power supply (make sure it has a high enough power output for the number of LEDs you have, I am using multiple USB chargers I had around the house)
  • Green electrical tape (quantity) (used to hide the red, green and white wires on the lights)
  • To put it all together, you'll need a case.

Step 1: Set up the Raspberry Pi

  • To set up your Pi and install Node-RED and the essential packages, do the following.
  • Set up your Pi; if you're doing a headless setup, ensure sure SSH and/or VNC are enabled.
  • You can use whichever method you choose to get at your pi (SSH is the easiest at this point on a headless set up)
  • Your Raspberry Pi should be updated.
  • Use the following command to install Node-RED:
				bash <(curl -sL
Set Node-RED to start automatically when the computer boots up:
sudo systemctl enable nodered.service

If you want to use LED HAT for the lights

Install PiCube 4x4x4 LED cube HAT for Raspberry Pi a 64 monochromatic (Red, Blue, Green) LED device


  • Stack PiCube on Raspberry Pi 40 Pin GPIO header.
  • Open Git Bash Terminal and clone/download the repository by typing the below command in the terminal:
git clone
Your code will be downloaded to the '/home/pi' directory. Use the 'ls' command to check the list of directories and the 'cd' command to enter the directory.
cd PiCube
    • '' is an example code for PiCube. Run test file and play with PiCube by running below python command.

    It will run a different LED pattern on PiCube. You can also modify this code to put your own creativity.

    Step 2: Set Up Node-RED

    Set Up Node-RED

    We may access our server through the Pi it is installed on (http://localhost:1880) or any computer on your local network now that your Pi is set up and we should have a functional Node-RED Server. When surfing from a different computer, use the Pi's hostname or IP address: http://hostname>:1880. Running hostname -I on the Pi will provide the IP address.

    We'll need to add additional modules now so that we can build our flow, interact with it, and communicate with our LEDs. We're going to add two more:
    • node-red-dashboard
    • node-red-node-pi-neopixel
    If you want to use the command line to add them, simply follow the links to locate the command; just make sure you're in the right directory so Node-RED can discover them. Alternatively, you can just add them using the UI on the page you just visited:
    • In the upper right corner, click the "Menu" button (three horizontal bars).
    • choose "Manage palette" from the drop-down menu.
    • pick the "Install" tab from the drop-down menu.
    • in the search field, type "node-red-dashboard"
    • Choose "install" from the top-level option.
    • Enter "node-red-node-pi-neopixel" once it's finished.
    • Choose "install" from what should be the sole choice available.
    • "Close" is the option to choose.
    Node-RED should now have all of the necessary modules to power our LEDs and UI. The flow that describes the inputs and outputs between the use, the Pi, and the LEDs may now be added.
    • In the upper right corner, click the "Menu" button (three horizontal bars).
    • pick "Import" from the drop-down menu.
    • Fill in the blanks in the box that should now be open:
    [{"id":"85fce9c6579baaa0","type":"tab","label":"Christmas Lights Simple","disabled":false,"info":"","env":[]},{"id":"cc28a93a30fc342a","type":"ui_colour_picker","z":"85fce9c6579baaa0","name":"Color Picker","label":"COLOR PICKER","group":"d2ace9cc.9f3998","format":"rgb","outformat":"string","showSwatch":true,"showPicker":true,"showValue":true,"showHue":false,"showAlpha":false,"showLightness":true,"square":"false","order":1,"width":0,"height":0,"passthru":true,"topic":"","x":370,"y":360,"wires":[["024561a721d6f79c"]]},{"id":"024561a721d6f79c","type":"function","z":"85fce9c6579baaa0","name":"Set Color","func":"var count = global.get('count')||0;\nmsg.payload = msg.payload.replace(/[rgb()\\s]/g,\"\");\nif(count===0){\n    msg.payload = msg.payload;\n}\nelse{\n    msg.payload = (count-1) + \",\" + msg.payload;\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":540,"y":360,"wires":[["c0297b03d780b3ae"]]},{"id":"693df877b38a2cf1","type":"ui_button","z":"85fce9c6579baaa0","name":"Clear","group":"d2ace9cc.9f3998","order":6,"width":0,"height":0,"passthru":false,"label":"CLEAR","tooltip":"","color":"","bgcolor":"","icon":"","payload":"0,0,0","payloadType":"str","topic":"","x":190,"y":460,"wires":[["a96f4433de81777e","663a12cf6cede0ef"]]},{"id":"206d8115b7db9943","type":"ui_dropdown","z":"85fce9c6579baaa0","name":"Select Strip Color","label":"SELECT STRIP COLOR","tooltip":"","place":"SELECT STRIP COLOR","group":"d2ace9cc.9f3998","order":4,"width":0,"height":0,"passthru":true,"multiple":false,"options":[{"label":"RED","value":"255,0,0","type":"str"},{"label":"GREEN","value":"0,255,0","type":"str"},{"label":"BLUE","value":"0,0,255","type":"str"},{"label":"WHITE","value":"255,255,255","type":"str"},{"label":"PURPLE","value":"255,0,255","type":"str"},{"label":"CYAN","value":"0,255,255","type":"str"},{"label":"YELLOW","value":"255,255,0","type":"str"}],"payload":"","topic":"","topicType":"str","className":"","x":370,"y":420,"wires":[["c0297b03d780b3ae"]]},{"id":"9d8f5d23eeba3096","type":"delay","z":"85fce9c6579baaa0","name":"","pauseType":"rate","timeout":"1","timeoutUnits":"seconds","rate":"4","nbRateUnits":"0.0101","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"outputs":1,"x":710,"y":560,"wires":[["c0297b03d780b3ae"]]},{"id":"c0297b03d780b3ae","type":"rpi-neopixels","z":"85fce9c6579baaa0","name":"WS2812B LED STRIP","pixels":"250","bgnd":"","fgnd":"","wipe":"0","mode":"pixels","rgb":"grb","brightness":"40","gamma":true,"x":960,"y":400,"wires":[]},{"id":"40080ab07f9975a1","type":"ui_button","z":"85fce9c6579baaa0","name":"Christmas","group":"d2ace9cc.9f3998","order":5,"width":0,"height":0,"passthru":true,"label":"Christmas","tooltip":"","color":"","bgcolor":"","icon":"","payload":"true","payloadType":"bool","topic":"","x":200,"y":620,"wires":[["5db1f6bc1f363b40"]]},{"id":"34273e36c70ad99f","type":"debug","z":"85fce9c6579baaa0","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"reset","targetType":"msg","x":750,"y":700,"wires":[]},{"id":"5db1f6bc1f363b40","type":"function","z":"85fce9c6579baaa0","name":"Christmas","func":"var numberOfLEDs = 250;\n\nvar j = 0\n\nwhile (j<numberOfLEDs+1){\n        var setColor = j+','+ 255 +','+ 0 +','+ 0;\n        node.send({payload:setColor});\n        j++;\n        var setColor = j+','+ 0 +','+ 255 +','+ 0;\n        node.send({payload:setColor});\n        j++;\n        var setColor = j+','+ 0 +','+ 0 +','+ 255;\n        node.send({payload:setColor});\n        j++;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":460,"y":620,"wires":[["c0297b03d780b3ae"]]},{"id":"a96f4433de81777e","type":"change","z":"85fce9c6579baaa0","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"payload","tot":"msg"},{"t":"delete","p":"payload","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":520,"wires":[["9d8f5d23eeba3096","34273e36c70ad99f"]]},{"id":"663a12cf6cede0ef","type":"delay","z":"85fce9c6579baaa0","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"outputs":1,"x":530,"y":480,"wires":[["c0297b03d780b3ae"]]},{"id":"d2ace9cc.9f3998","type":"ui_group","name":"Christmas tree","tab":"14b7bf29.77ead1","order":1,"disp":true,"width":"6","collapse":false},{"id":"14b7bf29.77ead1","type":"ui_tab","name":"Lights","icon":"dashboard","order":1,"disabled":false,"hidden":false}]
    • pick "Import"
    • You should now be able to observe the flow depicted in the diagram.
    • In the upper right corner, click "Deploy."
    • Open a new browser and go to "http://hostname>:1880/ui" (change "hostname>" with the IP address of your Pi). You should now be able to see and interact with the picture of the user interface.
    Note: The light intensity in this code is set to 40%, which limits power consumption for the PSU I'm using and is a good level for the LEDs I'm using. If you wish to change this, double-click the rpi-neopixels node at the end of the flow, and you'll get a box where you may do so.

    Step 3: Connection

    Wiring Raspberry pi

    Before connecting any cables, make sure your Pi is turned off! Wiring the LEDs to the Pi is simple; all you have to do is connect the ground and signal cables from the LEDs. However, make sure you connect the right connections; mine were coloured:

    • Vinegar - Red
    • Pin 6 on the Raspberry Pi - Ground - White
    • Pin 12 (GPIO 18) on the Pi - Signal - Green (this is why your audio needs to be HDMI only on the Pi as audio via GPIO uses the same pin)
    You may now connect your PSU to the LED strip once you've linked the Pi. Depending on the length of your LED strip, you may wish to connect the power supply at several points along the strip (hide it at the back of the tree).

    Please ensure that any exposed wires are insulated with electrical tape and that everything is contained to prevent children from getting into it.

    After you've finished wiring everything up, you can power up the Pi and the lights. Navigate to "http://hostname>:1880/ui" (change hostname> with your Pi's IP address) from your device of choice once the Pi has booted up. Simply press anywhere on the colour wheel or the Christmas button once you've arrived, and your lights should spring to life!

    Credit: Ekul92

    Posts You May like


    Most Viewed Posts

    Write For Us


    Email *

    Message *

    All Blogs