Arduino WS2811 Pixel LED Christmas Tree Lights

I made some neat Christmas tree lights using an Arduino and WS2811 pixel LEDs

Random LEDs will twinkle white. After the LED flashes, it is set with either red, green, or blue until it is twinkled again.

This was done on an Arduino Uno with the data wire connected to pin 6. The LEDs used are the WS2811 RGB LEDs ordered from Amazon, but now there are ones with black wires which will look better on your tree. You can hook multiple strands together, just change the NUMPIXELS from 50 to the total number of LEDs on your strand and use an external power supply with enough amperage to drive them all.

Here’s the sketch to upload to the Arduino:

// Include NeoPixel library
 #include <Adafruit_NeoPixel.h>

// Data pin for the pixel string
 #define PIN 6

// Change this to the number of LEDs on your string
 #define NUMPIXELS 50

// Loads NeoPixel
 Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_RGB + NEO_KHZ800);

// Delay between twinkles
 int delayval = 100;

 // Initialize LED variable
 int led = 0;

 // Initialize RGB variable
 int rgb =0;

 // Define max LEDs
 int maxLED = NUMPIXELS;

// Starts the library
 void setup() {
 pixels.begin();
 }

// Show begins
 void loop() {

 // Picks a random LED
 led=random(0,maxLED);

 // Sets pixel to white
 pixels.setPixelColor(led,pixels.Color(255,255,125));
 pixels.show();

 // Waits per delayval
 delay(delayval);

 // Picks a random color
 rgb=random(1,6);

// Switches LED to random color
 switch (rgb) {
 case 1:
 pixels.setPixelColor(led,pixels.Color(100,0,0));
 pixels.show();
 break;
case 2:
 pixels.setPixelColor(led,pixels.Color(0,255,0));
 pixels.show();
 break;
case 3:
 pixels.setPixelColor(led,pixels.Color(0,0,255));
 pixels.show();
 break;
case 4:
 pixels.setPixelColor(led,pixels.Color(255,0,255));
 pixels.show();
 break;
case 5:
 pixels.setPixelColor(led,pixels.Color(0,255,255));
 pixels.show();
 break;
case 6:
 pixels.setPixelColor(led,pixels.Color(255,0,255));
 pixels.show();
 break;
 }
}

Leave a Reply

Your email address will not be published. Required fields are marked *