DIY Arduino Christmas tree lights


Last year I built a very simple light switch with and Arduino board and a relay shield, I put a video on Youtube buy here is the detailed explanation of the code and the parts used.

The only drawback is that the Relays have mechanical switching parts and are a bit noisy, specially in the silence of the night.

I bought the board and the shield on BricoGeek, which is a fine shop from Spain but they can be found anywhere. The other smaller parts were bought at my local electronics shop.

So, these are the required parts:

  • Arduino Uno board
  • Relay shield - I’ve got v1.3 but for this particular project it’s irrelevant.
  • Non blinking Christmas tree lights. Mine are LED and connected directly to the mains power.
  • Universal power supply. USB 5V supply is not enough to power the Relays, so you need an external supply of 9V for them to work properly.
  • Electrical tape (to cover the USB port of the Arduino and avoid accidental contact with the AC power damaging the board)
  • Two wire electrical cable
  • Male and female AC plugs
  • Small regular screwdrivers for the relays and maybe other types to mount the plugs

The job is easy, just be careful because mains current levels are dangerous and some parts of the board leave it exposed.

The electrical cable has two wires, just cut one of them and connect one lead to the COM1 and the other to the NO1. If you have more lights just connect them to COM2, COM3, COM4 and NO2, NO3 and NO4 respectively.

You can also use NCn instead of NOn: NC stands for Normally Closed which means it’s connected -closed- when pin is low (0) and disconnected -open- when pin is high. NCn works the opposite.

A detailed explanation of the relay can be found on Seeedstudio wiki page

Then, mount the plugs on both sides of the cable, male on one side an female on the other.

Finally put some electrical tape over the Arduino USB connector and mount the Relay Shield on top of the Arduino board.

Finally it’s time to program the board. On my Github arduino-christmas-lights project you can find the example code.

Basically on the code you can see two state arrays states1[] and states2[], one for each connected light. They should be the same size to maintain synchronization between both light strips. On each state array you can define the HIGH/LOW sequences, as long as you want.

Finally there’s a loop that turns the relay on and off with a 500ms delay between changes. If you put two equal consecutive states, the relay will maintain it’s state.

As you can see it’s very simple, but works and opens a world of possibilities. For example syncing the lights with a song adjusting the patterns and the delay to the rhythm.

If you have any doubt just add a comment, drop me a line or add an issue on the Github project.

Merry Christmas and have fun!

Related Posts

Bye bye Kurobox

A deserved farewell to a device that has worked flawlessly for so many years

Back to blogging

My statement on getting back to blogging. Will this go anywhere?

Lessons learned optimizing MySQL

A summary of some things I discovered while trying to optimize the performance of a production MySQL server.

Simple Mini Profiler Glimpse plugin

I just created my first Glimpse plugin, integration between Mininprofiler and Glimpse.

Carbon Copy Cloner saved my day

Just a gratitude post because this piece of software was extremely useful when others don't. And it was my birthday.

Troubleshooting MSDTC, RPC and NServiceBus issues

MSDTC is rare and can cause many headaches. This is the process I followed to track down the problems I was having

Using fail2ban with nginx in Debian

fail2ban helps you fight spam and bots but comes with an Apache sample. I converted it to handle Nginx information.

How msiinv saved my day

mssinv is a tool to manage MSI installed packages and I used it to track a problem with a package partially installed, that had to be removed with this tool

Install ASP.NET MVC 3 Manually

Due to some strange problems in my PC, I had to install this package manually and this is applicable to many other installers

Deployment web site Zip with MsBuild and TeamCity

I needed to make a Zip file of a web site and automate it with TeamCity. I used MsBuild and some obscure tricks