My project is a small plastic Christmas tree that can sit on your desk to bring holiday cheer to your workspace. The lights have a "twinkle" effect to make your holidays even more magical.

Here's a quick overview of this device:

Powered by a 12v wall-wart

3D printed parts (had to use Shapeways for 3D printing since I don't have my own printer)

Custom made PCB

24 LEDs of different colors

Uses an ATTiny24 to create the lighting effects

About 13cm tall, 11cm wide (at widest part)

Scroll down to the very bottom to see the demo video. Keep reading if you are interested in how I made this.

The Enclosure

For this project, I used FreeCAD to design the enclosure. The tree is made of four plastic pieces. The top part (the main tree shape) was designed as two halves. You can see that there are slots and tabs; this was my method of attaching all the pieces together (with some glue as well).

The base of the enclosure is a simple box to house the PCB. It has four tabs which allow it to attach to the slots in the pieces shown above. The base also has a removable piece which makes it easier to assemble the wiring and troubleshoot the circuit if there are any problems. Here is what the base looks like:

I uploaded these designs to Shapeways to get them printed. I don't have much experience with 3D design so I was really hoping there would be no problems. Unfortunately, when I received the pieces, I noticed there were two problems. First, I made the tabs the same size as the slots - they wouldn't fit. The tabs should have been slightly smaller than the slots. I ended up filing the tabs down until they could fit inside the slots. Second, the square base should have lined up with the square opening in the main tree part. Unfortunately, the base was about 2mm larger than the opening, so it wouldn't fit. To fix this, I cut the tabs off the base and just used plastic welder (two-component adhesive) to attach the base to the main tree part.

Aside from these fixes, I had to make one more modification to the parts (this time it was intentional). I drilled some holes in the tree pieces to stick LEDs through. I decided this would be easier than trying to design the part with holes in it already. I also had to drill a small hole into the base to allow the power cord through. Below you can see the two halves of the tree, one with holes drilled and the other without.

The Electronics

I used KiCad to design the electronics. Overall, the circuit works like this: there are 4 LEDs in series (each a different color), this makes a "strand". There are 6 of these strands total, three of them are always on and the other three are controlled (via three transistors) by the ATTiny using PWM to create a twinkling effect. There is also a voltage regulator (LM317T) to step down the 12v input to 5v for the ATTiny. Here is the original schematic. You may need to click on the image to see the full-size version.

Once I was satisfied with the schematic, I designed the PCB. It is a two-sided PCB, but there are no components on the backside. The top is the ground plane, the bottom is the 12v plane. The image below shows the top copper on the left (red) and the bottom copper on the right (green).

I sent this design to OSH Park and received three boards a couple weeks later. Since this was my first PCB design, I was quite happy with the results. There were only two problems. First, the footprint of the barrel jack did not match the actual component I had. I ended up abandoning the barrel jack and just soldered the power wires directly to the board. This actually made the assembly process easier, so I wasn't upset about it. Secondly, some of the resistor values were wrong in the schematic (particularly the 51k transistor base resistors). I'm not sure why I used those values, my prototype breadboard circuit used 1k resistors. Fortunately, it is easy to just use different resistors. I should also note that you may notice other resistor values are different than the schematic. This is because I did not have that particular value available in SMD form, so I had to use a resistor that was close enough. You can see the front/back of the blank board below.

After soldering the components onto the board, here is the result.

The Code

Before soldering the ATTiny24 to the PCB, I programmed it to use PWM to change the brightness of the LEDs in a specific pattern. The three PWM strands each change brightness individually and at different times. I wrote the code in notepad++ and uploaded it with a programmer. This was the first time I have programmed an AVR without the Arduino IDE. This was a very frustrating experience, but I learned a lot and it was definitely worth the pain in the end. For some reason I am having trouble embedding the code into this post, but you can see it on pastebin here.

The Assembly

Now that the microcontroller was programmed, everything was soldered to the board, and all holes were drilled into the plastic pieces, I was ready to begin assembly. It was tedious, but I connected the LEDs with short wires and pushed them through the holes in the plastic. The drilled holes were small enough that the LEDs fit snug without needing any glue. Once I had the LEDs in place, I tested them before attaching the base of the tree. You can see the successful test below.

Lastly, I used plastic welder to attach the base. Here's what that looks like:

Conclusion

Here's a quick video showing the final product in action.

Overall, this was a great project for me. I learned a lot about PCB design, 3D design, and programming AVR microcontrollers. In the future, I think I will try to remake this again but use all RGB LEDs and add wifi control - I imagine controlling the colors of the LEDs with my phone over wifi.