DIY Ambilight
Introduction
I've been using two Lightpack v1 modules connected via USB to my mediacenter box for years, but after getting a new TV, the old Lightpack setup wasn't big enough anymore. Pretty much all products that can be bought ready-to-use cost way too much so i deciced to build my own Ambilight clone.
Most solutions seem to go the way of using a HDMI splitter and a HDMI capture card connected to a Raspberry Pi, which interprets the grabbed video frames and controls the LEDs connected to one of its GPIO pins. This is not the way i wanted to go, first because that would require running another Raspberry Pi, and second because that's where it gets expensive if you want something that captures at 4K@60Hz and does not mess up the HDMI connection.
As one of the requirements was being able to use it with Kodi (on a Vero 4K+), Enigma (on a VU+ Uno 4K SE) and Android TV (on a Nvidia Shield TV Pro), controlling it via USB like the Lightpack does was also not an option, unless i wanted to move the USB cable between each device whenever i switch to it, so it needed to be something that can be controlled via network.
The very first search result for "ws2812b wifi" is WLED, so i started reading up on what it does and how to use it. The short version: it's a firmware for the wifi-capable ESP8266 board which can control addressable RGB LEDs (commonly referred to as "ws2812b"). And it has support for Hyperion, which is a software that can grab the display output of a video device and convert it to instructions for LED controllers.
WLED
WLED seems to be around for less than two years (as of this writing) but it looks like it is very mature and has lots of features and supports many common protocols already. Using ESP8266 boards also makes it very easy to set up, as those boards cost <$5, can be bought pretty much anywhere and you only need a USB cable to upload new firmware (disclaimer: i've been using them for years, so i may be a bit biased regarding what would be considered "easy to use").
Hyperion
Hyperion was also the software i have been running on my Kodi boxes, as it provided a very reliable video grabber and made it reasonably easy to set up the LED layout, which is something you have to do so Hyperion can covert the rectangular image from the video grabber into a command for the LEDs at the respective positions. (It basically looks at the video image, sees that e.g. the top left corner is red, so it refers to the LED layout you configured because it needs to know which LEDs in the LED strip are mapped to the top left corner, so that it can send a command to turn those red, too.)
Hardware
For the first proof-of-concept build i just went with the setup shown in the WLED Wiki and the hardware i had laying around: an ESP8266 Board, a TXS0108E Level Shifter and a short WS2813 LED Strip. That got wired up on a breadboard and connected to a 5V power supply (although the USB connection for uploading the firmware would probably have been sufficient for those few LEDs - just don't go full brightness), et voilà, we have blinkenlights. I was able to control the LEDs via the web interface, and the included effects looked like everything was working a intended, so i moved on to full build stage.
Two things i'd like to point out right away, because i only noticed them after the first prototype was finished and i connected the full 5 meter LED strip to it and had to integrate these fixes when i thought i was already done:
- Yes, you should add the relay, because even when switched off, those 300 LEDs draw ~0.25 amps unless you completely cut the power by using a relay.
- Yes, you should inject power also from the other end of the LED strip, as there will be a very noticeable drop in brightness along the LED strip.
So here's the bill of materials for my DIY Ambilight:
- ESP8266 Board Amazon 3 for ~12€
- TXS0108E Level Shifter Amazon 6 for ~10€
- KY-019 Relay Amazon 3 for ~5€
- WS2813 LED Strip Amazon 5m for ~47€ (60LED/m, black, IP30)
- 5V 20A Power Supply Amazon ~16€
- 4 pin LED Strip Connectors Amazon ~5€
- 1000 uF Capacitor Amazon Set of 125 for ~9€
- 470 Ohm Resistor Amazon Set of 500 for ~7€
Breaking the cost down into what was actually used for my build, i ended up at ~75€. This does not cover the cost of the wires, connectors, soldering tin and tools i used, let alone the time, but it should give you a general idea. ProTip: buy electronics in bulk. It's cheaper, and it's always good to have some ESP8266, level shifters and relays at home. ;-)
Wiring
After wiring it up, i would have liked to see something like the image below, but real life is messy so i won't show any actual photos of the build:
Let's go over the connections so you'll understand what they do: the 5V and Ground from the power supply is split into two cables each, one for the electronics and one for the LED strip.
- Power to the LED strip goes to the 1000 uF capacitor and from there into the power injector cables of the LED strip, but the 5V line for this i also wired into the relay: from power supply into "common" or "middle", and to the LED strip from "NO" ("normally open", as we want the power to be cut when the relay is off).
- Power to the electronics first goes to the control pins of the relay (because they provide enough contact surface to solder multiple connections), and from there to the 5V and GND pins on the ESP8266 and the high-voltage (well, still 5V) reference input on the level shifter. The GND between the level shifter and the ESP8266 was still connected from my early testing, so i left that in place, but i could also have soldered a separate connection from the relay's GND to the level shifter's GND. In short: all the electronics are on the same 5V and GND.
- The level shifter gets an additional connection from the ESP8266's 3.3V pin to the low-voltage reference input.
- Pin D4 of the ESP8266 is the "data" pin for the LEDs, so that gets connected to any of the inputs on the level shifter (i used A4)
- Pin D6 of the ESP8266 is the "data" pin for the relay, and that also goes to any of the inputs on the level shifter (i used A6). Technically it's not really necessary to use the level shifter to control the relay, as it should also work with 3.3V, but as i have 8 channels on the level shifter, that additional connection is just added peace of mind.
- Pin B4 on the level shifter (the high-voltage output of input A4) goes to the 470 Ohms resistor.
- Pin B6 on the level shifter (the high-voltage output of input A6) gets connected to the signal pin on the relay.
- Pin OE (Output Enable) on the level shifter gets connected to the 3.3V input, too, otherwise the outputs won't output. Don't ask me how long it took me to figure that out.
- From the 470 Ohms resistor, split the cable into two connections: one for the main data pin of the LED strip connector, the other for the backup data pin (as the WS2813 has two data pins for redundancy).
- GND from the level shifter also goes to the GND pin of the LED strip connector.
- The 5V input of the LED strip connector is NOT connected, otherwise it would bypass the relay and still draw power when the relay is off.
- TODO: plugs on cables
- TODO: secondary power injection