Last Christmas (2016) I wanted to make custom lights for a Christmas Tree but ran out of time. This Christmas (2017) I succeeded.
The idea
The idea was to use an Arduino to power WS2812 LED strips. WS2812 are RGB LEDs with an included microprocessor, that allows you to control all of them with a single data pin. This greatly simplifies the wiring process. At the time I had four 1m strips with 30 LEDs each. They were bought at different shops (mostly on AliExpress). Sadly this was noticeable – the colors and brightnesses were slightly different. Also one led was broken, but luckily only the LED, not the microprocessor, so the successive LEDs worked correctly.
Each LED uses around 20mA of current per color when fully lit. That means 120*3*20mA = 7.2A for all of them on full brightness white. The best power source I had was 3A phone charger, which limited the max brightness. I could have full brightness on one color (red, green or blue), but not white. Luckily the full brightness was too bright for a Christmas tree in the dark, so that wasn’t a problem.
Software
At first, it was meant to be controlled by many buttons. Because I only had 4 correct resistors I only used 4 – one for mode, color, brightness, and speed. Each button press goes to the next setting until it loops back around. Later I also added serial control, for easier debugging and more accurate control. I don’t like interrupts, so I wrote it without them. There are still a few bugs (mostly with serial control), but I will fix them next year.
- There are 7 modes
- All On – All LEDs are statically turned on.
- Fill Up – The LEDs turn on one by one, and then turn off one by one along the strip.
- Fade Out/In – All the LEDs brightness dims out and back on up to the full brightness as set by brightness setting.
- Rainbow – The LEDs have different colors, like on a color wheel. The order and colors are not actually as on a rainbow. The colors move around the strips in a circle. The color setting obviously doesn’t do anything in this mode.
- Every Second – Every second LED is lit, and then it switches to the other every second lit.
- Every Fifth – Every fifth LED is lit, and the lit LED move by one.
- Every Tenth – The same, but every tenth LED is lit.
- 5 colors (red, green, blue, yellow, white)
- 25 brightness settings (in steps of 10 from 5 to 255)
- and 10 speed settings. The same speed setting has a different meaning in different modes. But the speed number always means that the delay is that multiple of some base delay.
Changing the color/brightness/speed preserves the state in the current mode (it doesn’t restart).
Code
I haven’t found a good way to embed GitHub code in this blogpost, so here it is. Warning: the code is not that pretty.
Future development
Next year, it will be controllable via Wi-Fi (using ESP8266 or something similar). And even more LEDs – just after Christmas I finally received another 2 meters that I ordered back in November. Now I also received some 60LED/m and 144LED/m strips. I just need to solve the power supply problem. I also have ideas for new modes, most importantly a mode similar to “Every Second”, but that the LEDs slowly fade out and at the same time the next LED fades in.
Recent Comments