This year we made our own Christmas tree lights. They’re really easy to build, and can be reprogrammed to be used all year round. Read on to find out how to make your own!
When finished, you should have your own programmable Christmas tree lights! Then you can take it further and make it your own! Our Christmas tree lights are different to the ones you get in the shop. Here’s a few things that make them stand out.
- You can reprogram the lights to do anything you want.
- You can add sensors to make them react to the world. Science lights!
- They’re great for general lighting or kids rooms after the holidays - just reprogram them for regular soft lighting!
- They last for ages, and don’t die when a single light goes out.
- Best of all, because you build them yourself, you know exactly how they work, and they work exactly how you want them to.
What You’ll Need
To build your own christmas tree lights, all you need are two things:
- A HIDIOT
- A pack of WS2811 RGB String Lights, like these.
If you want to order components for part 2 of this series, where we add sensors, you’ll need some form of i2c or ideally 1-wire sensor, such as a photocell and resistor pair or a TMP36 temperature sensor.
Normally you’d decorate your own tree before Christmas but this is great to do with kids around Christmas in the run up to New Year. You can pick up a gift pack from our store, and order all the parts. Even if you build the lights after Christmas, they can go up anywhere in the home, even after the rest of the decorations go down.
Wiring Up Your Lights
Firstly, build your HIDIOT as normal following our easy step-by-step instructions. When you’re ready to start with the lights, there are a few things about WS2811 RGB lights that you need to know.
The WS2811 is a digital RGB LED capable of displaying millions of different colours. The LED uses a positive and negative terminal, and a separate data line to receive commands to turn the LED on, change colour etc. The data line flows in one direction only. That means that you must connect your HIDIOT to the data in line, and not your data out.
Normally, there’s an arrow on the LEDs pointing down, this is the data out side. The wires connected on this side of the LED are heading out of one LED and into the next one. The wires connected on the other side are connecting to the in side. If your lights have separate power lines, this may also indicate which end is the data in side as power is normally (but not always!) connected to the data in side first. If in doubt, try testing your connection with jumper cables instead of soldering them in first.
Normally people put a large capacitor between the voltage and ground lines to protect against power spikes. WS2811 lights hate sudden power drops. In our experiments we’ve found the capacitor pair in the HIDIOT seems to be good enough for the lights we have, but if you’re not sure, you can always put a 1000uF capacitor across the positive and negative terminals that connect your HIDIOT to the lights.
The WS2811 also hates surges. If you have a sudden surge, this can cause the first LED to burn out. Our LED strings have 50 lights. For us, having 49 working lights isn’t the end of the world. Again, in our tests everything worked fine using PB1, which has a 330 ohm resistor. Just bear in mind that you can either use a small delay at startup or a 1000 ohm resistor between your data pin and the HIDIOT if you feel you might need it.
Finally, this is definitely an indoor project. Your lights might come with an outdoor rating, but your HIDIOT does not. It doesn’t like the cold or wet and could lead to magic smoke or worse if exposed to the elements. As cool as it sounds, magic smoke is not good. Keep it indoors.
With that out of the way, lets wire things up! We’re going to use PB1 for our data wire and the voltage rail for VCC and GND.
If you hold your HIDIOT the same way as in the picture above you should see how we can solder our 3-pin connector to the HIDIOT. At column H and row PB1 you’ll see a green circle. This is where we’ll solder the Data pin for the connector.
If your lights are like the ones we linked earlier, you should have two sets of 3 pin connectors. These are for connecting the lights in a daisy chain. Assuming you’re not chaining multiple lights together, you can snip one of the connectors off and solder it to the HIDIOT. Make sure it’s the connector on the data out side of the string!
If you are going to daisy chain lights, you can snip the connector off the data in side, and solder the data line directly to the HIDIOT. You’ll need to power the lights separately to the HIDIOT, and think carefully about your code’s RAM usage before you go ahead, but it should be possible.
At the top of Column M and row P3 there’s a brown circle. This is where we’ll solder the connector’s ground pin.
At the top of Column N and row P3 is a red circle. This is where we’ll solder the connector’s VCC, or positive pin.
WS2811 lights can be really, really, REALLY bright. If you want super-bright LEDs, we’d recommend using your own 5v power source for the LEDs instead of the HIDIOT. The HIDIOT just can’t provide the current for all the lights to come on at full power for a sustained period and you run the risk of damaging your lights or your HIDIOT if you try it. If you’re going to power your lights externally, we recommend using an appropriate power regulator and the capacitor and resistor discussed earlier.
Now you should have a connector soldered to your HIDIOT, and when you connect it to your LEDs, the VCC, Data and GND should be connected to VCC, PB1 and GND on your HIDIOT. Great, it’s time to start programming!
Programming Your Lights
There are two main libraries we can use, the AdaFruit Neopixel Library and FastLED. Both are great libraries and there are others too if you look online. Each have their pros and cons.
Some Digispark board definitions bundle the Adafruit_Neopixel library as part of the installation. This is a slightly optimized version of the library. On other versions of the Digispark board definitions you’ll need to add the Adafruit Neopixel Library through the Library Manager (Sketch -> Include Library -> Manage Libraries) in the Arduino IDE. The FastLED library will need to be installed via the Library Manager.
The Adafruit library is great, but it’s a little slow when you start using a lot of LEDs, and it uses a lot of RAM. The HIDIOT has 512 bytes of RAM, which is fine for basic lights, but a 3 bytes of RAM to store red green and blue values per LED, a 50 RGB LED means our code uses 150 bytes of RAM. Fine for now, but when we add sensors this could be a problem.
In contrast, the FastLED library has special optimizations to reduce memory footprint. It’s very powerful, but it’s a bit more complicated. Both are great libraries, but we’ll use FastLED for now.
The code we’ll run is shown below. Install the FastLED library, copy and paste this into the Arduino IDE and it should work first time. The code is based on one of the FastLED examples and we’ll use this as our base for adding other features later.
Connect your lights to the HIDIOT, hit the upload button in the Arduino IDE and plug your HIDIOT into a USB hub. If all goes well, you should see a nice soothing pattern in a few seconds. Put your lights up on the tree or around the home, and don’t forget to share some videos of your new creation with the #HIDIOT hashtag!
If things go wrong, try to work backwards from hardware problems before looking at software. Make sure your 3-pin connectors are correctly connected and that your data line is the line going in and not out. If you’re using PB1 you should see LED1 flicker as the signals are sent out onto the data line. If you get really stuck, post about your problem on the community reddit and we’ll do our best to help - just remember that we’re closed over christmas, but either Steve and/or Aidan will check in from time to time.
Decorating Your Tree
You’re all set to decorate your tree. It’s exactly the same as if you use normal lights, just a few points to bear in mind:
If you haven’t created a case for your HIDIOT, make sure it’s not touching anything conductive. It’s normally ok to hang your HIDIOT off the connector but check everything first and make sure it can’t be reached or tasted by inquisitive toddlers or pets.
You might find the lights don’t come on at first, or that the lights come on but don’t change colour. This is almost always due to USB power supplies not providing enough current. Try a different USB power connector or cable.
In our next post we’ll add Bluetooth support so you can control your lights from either a mobile phone or computer. But for now lets look at what else you can do.
The code you just used contains a function called ChangePalettePeriodically(). This function isn’t called but is left in to let you explore other built-in palettes so you can make the lights cycle through different effects. FastLED is amazing for this and you can create your own palettes too. You should be able to modify your loop() function to have it switch through palettes, or try different ones like OceanColors_p or PartyColors_p.
At the docs site we walk you through how to use the two tact switches on the HIDIOT. Can you change the code to make the lights cycle faster and slower depending on which button you hold? How about lighter and darker?
Have a look at the Adafruit neopixel demos. There’s some really beautiful effects in there. Have a play around with different effects and animations to see if there’s anything you like!
Never miss a post
Like what you see?.
Get our latest electronics and security content in your mailbox. We won't send you spam. Unsubscribe any time.