Introduction: Ambilight System for Every Input Connected to Your TV. WS2812B Arduino UNO Raspberry Pi HDMI (Updated 12.2019)

I have always wanted to add ambilight to my TV. It looks so cool! I finally did and I was not disappointed!

I have seen many videos and many tutorials on creating an Ambilight system for your TV but I have never found a full tutorial for my exact needs.

It is whether the system is only made for 1 single source (PS4 or Xbox or TV etc..) or it is not using the same LED's as I wanted to use, so I decided to create an instructable and put together all the information and experience I gathered in one spot while making this project.

The system I have made can be connected to up to 5 different sources. I have it setup here to run with my PS4 system or my home theater/blu-ray player or my Foxtel (Australian cable tv box) or my computer and have a spare input left for something else. All of these simply with the press of a button.

I have added a LCD screen to display the current source being connected to the ambilight and an ON/OFF button for the system.

If you are looking to have ambilight available for every different inputs connected to your TV, want to use the WS2812 type led strips, then look no further, this tutorial is for you.

I have entered this instructable into the Raspberry PI 2016 contest so if you like it please drop me a quick vote! Much appreciated in advance.

Step 1: Material Needed to Build This System

Not all of the sources have an HDMI output, like my computer is still connected through the old VGA connector and my Foxtel unit is still connected via AV cables. I had to purchase quite a few different adapters to get it all working, but in the end the result is awesome and well worth it!!

Not everything here will be needed depending on your own system and if you would like a LCD or not. I will separate the optional items.

  1. 1x 4meter strip of WS2812B 30leds/m. (this was enough for my 55inch tv) I have bought mine from Aliexpress. LED strip
  2. 1xArduino UNO board.
  3. 1x Raspberry Pi model 2 or 3.
  4. 1x SD card. (8Gb is good)
  5. 1x Video grabber type STK1160. (be carefull when chosing the grabber, some models will not work!!) This is the one I got and it works correctly. Video grabber
  6. 1x 5V 10amps power supply. I got mine from Aliexpress again and it works fine. Power supply
  7. 1x HDMI splitter 1 x 2. splitter
  8. 1x HDMI switcher 5 in 1. switcher
  9. 1x HDMI to AV converter. converter
  10. 1x 10uF electrolytic capacitor

cables and hardware:

  1. 4x 25cm HDMI cable. cable
  2. 2x HDMI female to female enclosure connectors. connector
  3. 1x 220V input connector (fused).
  4. 1x project enclosure (can be different, it is up to you, mine is 424mm x 203mm x 86mm) box
  5. Single core wire to connect the 5V to the different converters etc.
  6. Ribbon cablesor extensions to wire inputs to the Arduino exemple

optional extras:

  1. 1x AV to HDMI converter. converter
  2. 1x VGA to HDMI converter. converter
  3. 2x 25cm HDMI cable. cable
  4. 1x LCD display 16characters x 2lines. LCD
  5. 1x I2C interface for the LCD. interface
  6. 1x cooling fan for the case.

Step 2: What Computer Programs Will Be Required

There will be a few different programs required for this project.

You need to download and install them (if you don't already have it)

  • WinSCP can be downloaded here
  • Putty can be downloaded here (click on the putty.exe link in the list)
  • SDFormatter can be downloaded here
  • Win32DiskImager can be downloaded here
  • Arduino IDE can be downloaded here (I used version 1.8.10 at the time)
  • HyperCon can be downloaded here
  • Notepad++ (optional) can be downloaded here

You will need to download the Raspberry Pi disk image too. Chose the file named "OpenELEC 8.0.3 for RPI2 / RPI3"that you can download from the bottom of the page here

Step 3: Getting the Raspberry Pi Up and Running

We are going to start by getting the Raspberry Pi up and running.

1) We are going to write openELEC to the SD card.

  1. Unzip the Raspberry Pi disk image.
  2. Plug the SD card into your computer.
  3. Run the SDFormatter program.
  4. Select the SD card drive letter.
  5. Click on option and select "size adjustment" to ON.
  6. Click OK.
  7. Click Format.
  8. Run the Win32DiskImager program.
  9. Select the Raspberry Pi image and the drive letter of your SD card.
  10. Select Write.

2) Eject the SD card from your computer and plug it in your Raspberry Pi.

Connections to be made on the Pi:

  • Connect an Ethernet cable to your Pi from your network.
  • Connect the HDMI port of your Pi to your TV or screen.
  • Plug in a keyboard and a mouse on the USB ports. (I use a wireless mouse and keyboard combo and I have left the dongle connected to the Pi, this way, now that the Pi is boxed up, I don't have to open it all up if I want to access my Pi.)
  • Plug in the usb end of the video grabber to your Pi.

3) Connect a 5V power supply to your Pi and follow the onscreen information until it boots up. You should be presented with a screen as per my photo.

We now need to check your internet connection. Follow the path Settings (cog wheel) - system information - summary and write down your IP address, it will be needed in the future.

Make sure SSH is enabled, follow the path Settings (cog wheel) - openELEC - services and check that "enable SSH" is activated.

Now we are going to install HyperCon and check our video grabber connection to the Pi.

For this we are going to use Putty. Your Pi has to be powered ON and connected to your network for this to work.

  • Type in the IP address you wrote down just before for your Pi. as per picture attached and click Open.
  • You should then be prompted with a window asking you for a username as per picture attached. type in root and press enter.
  • you will then be asked for a password. (note that the characters wont appear while typing the password, this is normal). Type in openelec and press enter.
  • To check all the usb ports, type in lsusb and press enter. You should find your video grabber in the list as per the picture attached.
  • You can now close the connection.

This complete the Raspberry PI setup. We will get back to it later on to upload our LED's configuration file.

Step 4: Hyperion and the Configuration File

  • Start by opening the program HyperCon.jar.

Copy the Device lines in the Hardware tab exactly as per the attached photo except for the output line.

To check what output your arduino is connected to we ll need to use Putty and log in to the Pi.

Connect to your Pi as previously.

Now type the following command: dmesg | grep "tty" and press enter

Check the response received. (See attached photo)

Normally, on the right hand side you should see something like /dev/ttyUSB0 or /dev/ttyACM0. This is what you will need to use in the output type of HyperCon.

In the "Construction" part of the Hardware tab, you will need to input your LED data.

  • Set the direction is which direction the strip is running when you are looking at it from the screen side of your TV to clockwise.
  • Do not tick any boxes for top and bottom corners.
  • You can then fill up the next 4 rows according to your setup.
  • The bottom gap is simply the results of "horizontal number of LED" - how may LED's you have at the bottom of your TV. In my case 39 at the top, 23 each side at the bottom = 11 gap
  • Increase or decrease the offset number until the LED 0 is located on the bottom left of the gap on the TV. See photo above if needed.
  • Copy the values in "Image process". They work well for me. It is a good start point for you.
  • Enable the "Blackborder Detection" and set the value to 15. I have found this to work pretty good.

Now moving to the Processtab.

  • Copy the values for the "Smoothing" as per the photo above. It works well.
  • Copy as well the "Color Calibration" values I have on my picture, they are a good starting point and work quite well.
  • The Luminance gain will set how bright your lights are. Set to 1, I thought my LED were a bit dull so I increased it to 1.25.

Now move onto the Grabbertab.

  • Copy the values as per the photo attached. We will come back to this tab later and set the cropping values once we are set.

Now move onto the External tab.

  • Copy the values as per the attached photo.
  • You can choose a different startup effect if you wish to.

Now move onto the SSH tab.

  • Copy the values as per the photo attached. Use your Pi's own IP address and not the one from the photo.
  • Set the password to openelec.

We will come back to HyperCon once your setup is ready for calibration.

Step 5: Getting the LED's on the Back of the TV

This step speaks for itself, it is time to put the LED strip at the back of the TV.

I personally just used the double sided tape of the LED strip and glued the strip on the edge of my TV. Some people prefer and build a frame for the LED's. This is all up to you and your TV as they will most likely always be different.

My setup has 78 LED's at the top, 47 on either sides and 30 on either sides at the bottom of the TV for a total of 232 LED's.

When I face my TV, the LED strip is running clockwise, this is looking at where the signal is getting to the first LED and travelling through until it reaches the last one.

Remember that there will potentially be a fair bit of current running through the strip, depending on its size, this is why I ran the power on both ends of the strip. The connecting wires on the edges of the TV will have to be big enough as well to pass this current through.

I used the connectors supplied with the LED strip. One connector (where the strip begins) has 3 wires, +5V and GND and as well the Data IN. The other side of the strip only has 2 wires. +5V and GND.

Step 6: Uploading the Hyperion Config to the Raspberry Pi and Setting the Grabber

For this step, your Raspberry Pi needs to be powered ON and connected to your network. We will use WinSCP to load up the file into the Pi.

Open up HyperCon and connect to your Pi.

  • You know your are connected once the SSH fields are not greyed out anymore.
  • Go to the Grabber tab.
  • As per the attached photo, right click on your TV image and select take grabber screenshot.
  • You can now adjust each Crop values until you have small to no black borders on each side of the screenshot. Every time you adjust a value, take another screenshot to see the difference it made.
  • Once your are happy with all your values, we are done.
  • You can go back to the SSH tab and disconnect.
  • Now press the "Create hyperion configuartion" button and save it somewhere handy on your computer.

Next you can start WinSCP.

  • Start by opening the program and entering the IP address under Host name, user name root and password openelec into the field as per the picture attached. Click login.
  • You should then see a window with a few lines as per the second picture while it is logging in.
  • You will then be presented with a window as per the picture above. The left side is your personal computer and the right side is the Raspberry Pi.
  • On the left side, navigate through until you have the configuration file located.
  • On the right side, double click on the return arrow couple of time until you are in the root menu ( only a / in the address bar above) the double click onto storage to get into this menu.
  • Select the config file on the left and click F5 or click onto the Upload button above it.
  • You will then have an upload window as per the picture. You need to copy the path storage/.config/ and the press ok.

Your hyperion config file is now loaded into your Pi. You can reboot it and it will now use this new config file when it restarts.

Step 7: How It All Works

You can refer to the organization chart I have drawn, a picture is worth a thousand words.

Brief explanation:

The HDMI switcher will pass through to its output 1 out of the 5 input signal it receives, as selected by you. (Playstation, Xbox, tv, etc...)

This signal is then fed into the splitter, which will duplicate the signal.

The first output of the splitter is going straight to your TV, to display the image as per usual.

The second output of the splitter is fed into the HDMI to AV converter.

The signal is converted and passed through to the video grabber. (via the yellow connector. Red and white are not needed, they carry the sound).

The raspberry Pi will in turn take the data from the video grabber, process it and send through to the Arduino the color that each LED will have to take.

The Arduino will then output the data to the LED's.

The Arduino is as well monitoring the HDMI switcher and according to the channel selected on the switcher, it will update the LCD screen to display the correct source. It monitors the ON/OFF button too which allows the led strip to be turned OFF if not needed.

Step 8: Boxing Up the Project and Connecting the Different Parts.

The boxing up of your project will be up to you. I have tried to put as many comments as possible on the pictures to give you and idea of how my setup is put together.

One very important thing is to make sure the video grabber input to the Pi is not connected with anything else, I had frame size errors and a lot of other weird things happening when I had anything else connected to the other USB port. It must reach a bandwidth limit or something but it would not work when I tried plugging in a WiFi dongle in this USB or even the output cable going to the Arduino.

I recommend placing all the converters etc and starting by bringing power to all of them first. Most of these converters came with a wall plug power pack. I cut off the cable and only used the connector on the converter's side and decided to build a little board with a lot of +5V and GND connections to power them all from. It saved a lot of room.

I stuck the different converters down with 2 component glue and used plastic stand offs to bolt the Arduino down. I added some glue to the back of the IEC connector as well for a bit of added rigidity. My IEC connector has an inbuilt ON/OFF switch that I can use to power off the whole unit. It has as well a fuse draw where I have put a 1.6A /250V fuse for protection if anything had to go bad with my cheap power supply.

I used my dremel tool and some files to make the openings into the enclosure and make it look nice. I have as well carved an opening for the IR sensor at the front of the enclosure above the LCD.

I have not drawn a proper schematic drawing for the wiring to the Arduino, let me know if someone would prefer to have one instead of using the picture one I have made up.

Don't hesitate to comment if needed and I will happily answer questions and update this instructable to make it more complete or easy to understand.

Step 9: Hacking Into the HDMI Switcher (optional)

For our Arduino to tell which source the HDMI switcher is actually displaying, we need a way to send this information from the switcher to the Arduino. Luckily, the switcher the switcher has 5 LED's to display source 1 through to 5 when selected and we are going to use these signals for the Arduino.

I have taken a signal from the 5 LED's but later when I wrote the Arduino code, I realized that I did not need a signal from the LED number 1, if you look closely at the ribbon cable connection to the Arduino, you can see that the brown wire on the right hand side is actually not connected. We only have LED2 connected to A0, LED3 to A1, LED4 to A2 and LED5 to A3.

I connected them to the Analog inputs for no other reasons that convenience of the wiring into my project box.

If you decide to build this project and do not want to have an LCD display on the front panel, this step is not needed and can be skipped. It will be hard to know which source is selected on the HDMI switcher if the LED's on it are out of view like in my project design where the switcher is housed inside the enclosure.

Step 10: The Arduino and Arduino Code

Download the sketch from the following link. here

For the Arduino sketch to compile properly you will need 2 libraries:

Adafruit_NeoPixel.h that you can download here

LiquidCrystal_I2C.h that you can download here (version 2.0)

I have tried to add as many comments as possible through the code. If anything is unclear, don't hesitate to post a comment and ask questions. They can help a lot of people.

Having a look through the code that I have attached to this step.

Datapin is the pin selected where the Din of our LED strip will be connected

#define DATAPIN 5

Led count is the actual number of LED's in your system

#define LEDCOUNT 113

The baudrate must not be changed, or it will need to be changed in the Hyperion config file too

#define BAUDRATE 500000

This is the brightness level you want your LED strip to operate at. Testing required in your environment. 0 to 100 selection

#define BRIGHTNESS 100

You will need to modify the line 24 with your own prefix.

Using the attached prefix file, find your number of LED and copy the values from the file into your prefix line. You need to open the file with something like Notepad++ to have it displayed correctly.

Exple for 113 LEDS: const char prefix[] = {0x41, 0x64, 0x61, 0x00, 0x70, 0x25};

Exple for 278 LEDS: const char prefix[] = {0x41, 0x64, 0x61, 0x01, 0x15, 0x41};

At the end of the code, in the check_source() routine, this is where you can change for each source the information that is going to be displayed on the LCD when the source is selected like TV or PS4 or computer etc etc...

You can set the LCD cursor as well to have the printed name printed in the center of the LCD.

Once you are happy with your code you can upload it to your Arduino and check that it works correctly with at least the LCD for now.

Once your Arduino is programmed, please add a 10uF capacitor between the pins GND and RESET. (Pin reset being the + of the capacitor).

This will prevent the Arduino from rebooting when the serial data coming from the Pi when the system starts up.

If you need to reprogram the Arduino, remove the capacitor before hand and replace it once it is done.

Step 11: Bringing It All Together and Testing

Raspberry Pi and Arduino can now be linked with the USB cable.

LED strip has been connected to the enclosure and to the Arduino.

Arduino and Raspberry are programmed.

5V supply from the power supply is going to all the different converters Arduino and Raspberry.

When power is applied to the project box, the HDMI switcher LED source is light up, Source channel can be change by the mean of the remote control or button on the switcher.

Select the source on your TV where you connected the main cable from the project box output and see if you are getting an image on the screen from whatever source you have selected on your switcher.

After a few seconds, the LED strip should progressively light up and the switch off. This mean the Arduino has started and the connection with the LED strip is good.

Soon after, the LED strip should start displaying colors as per the information passed on by the Raspberry.

Succes!! You have now finished your project and can start enjoying some entertaining TV light show!

Step 12: Control Your LED Strip From Your Phone

To add a bit of fun to this, you can download an App on Iphone, I am sure it must be available for other devices as well.

Very easy to use, just make sure your Pi and LED strip are ON and press the Detect button on the top left. It should detect the Server, that you can name as you wish to.

Select it and you are all set, you can pick colors from the color wheel and your strip will light up accordingly or chose from different effects to be displayed.

Raspberry Pi Contest 2016

Second Prize in the
Raspberry Pi Contest 2016