Introduction: TV AmbiLight With USB Camera, Raspberry Pi and Arduino
In this Instructable, I will be showing you how you can make Ambient Lighting for a TV. Making my own ambilight has been kind of my dream project since a long time, only thing stopping me was the usage of a HDMI splitter or a HDMI grabber for the project. I consume a lot of content from the inbuilt TV apps, and I didn’t want to limit the ambilight just for the content I watch over HDMI. When I saw a solution that makes the use of a camera to capture color information for ambilight, I decided to make it. This way, no matter what I watch on the TV, the ambilight reacts to it flawlessly.
Supplies
Let’s start with the components required for this project. Firstly, you will need a Raspberry Pi of any kind. To drive the LEDs, we will use our favorite Arduino, as it is not very easy to control the individually addressable LEDs with Raspberry Pi. Then you will need a USB camera that will capture the content playing on TV screen and send it to Raspberry Pi. I am using WS2812B LEDs, you can choose other individually addressable LEDs as well. I have found that the 60 LEDs/m is the best balance between brightness and power, but of course your mileage may vary, and you can choose whatever version you want with some modifications. We will need a beefy 5V power supply, assume 60mA per LED and calculate what wattage power supply you need. I am using a 5V 20Amp one. Since I am using a RPi Zero, I will also need a USB hub. Some headers, screw terminals and a perf board are also required for making permanent connections. For prototyping, I will be using a WS2812B LED matrix and a small breadboard. Finally, we need some cables, adapters, memory card and a memory card reader for flashing the OS for Raspberry Pi.
Step 1: Watch the Video
You can watch the video if you want or read along.
Step 2: Prepare the Pi and Arduino
Let’s start with installing the OS on to a memory card. We will be using Hyperion as the software to extract the color details from TV screen using USB camera. To install Hyperion, you can either flash the Raspbian OS to your memory card and then use a few commands to install Hyperion on it, or you can directly install Hyperbian, which basically is Raspbian with Hyperion pre-installed. All the steps for installation are there in Hyperion documentation page. In the first boot of the OS, connect to a WiFi, enable SSH and enable auto-login through raspi-config as we might need to use the Raspberry Pi headless for initial stages. After Hyperion is installed, go to the website "http://<ip_of_your_pi>:8090" through any device connected to the same WiFi and see if Hyperion config page opens up. It if doesn’t then something has gone wrong, and you might need to reinstall Hyperion. You can turn the Raspberry Pi off for now.
For the Arduino, download the sketch from Github, edit the number of LEDs to be 4 and baud rate to be 112500 and upload it. I am using 4 LEDs for prototyping as it can be easily powered using USB. Your Arduino is ready.
Links:
Download Raspbian - https://www.raspberrypi.com/software/operating-systems/
Install Hyperion - https://raspberrytips.com/install-hyperion-on-raspberry-pi/
Install Hyperbian - https://docs.hyperion-project.org/user/HyperBian.html
Attachments
Step 3: Do the Config
Now connect both the USB webcam and Arduino to the Raspberry Pi. Turn it on and go to the Hyperion configuration page. In the capturing hardware page, enable USB capture and you should be able to see your webcam in the devices list. Select it, set the resolution to 320x240 and FPS to 30 and save the settings. Now, go to LED output in LED instances page, select controller type to be Adalight, in output path you should see a device code, it will be different for different kind of Arduino, but it should not be empty. Set streaming protocol to "Adalight - Standard", set the Hardware LED count to 4 as we are prototyping with 4 LEDs, and save it. Now set the settings level to be advanced and select the correct baud rate which you set in Arduino sketch. The configuration is complete now and you should see the LEDs light up according to what your camera is seeing. Turn everything off and turn it on once again to check if your setup is working as it should or not. With this, we are done with the easy part.
Step 4: Prepare Your TV
Now comes the hard part. Lay your TV flat on a soft surface to access the back of the TV. Measure the LED strip length for each side of your TV and cut it. I will be using the connectors that come with WS2812B roll to connect all the 4 strips together. Try to do as much soldering as possible before sticking the LED strip to the TV. Also, I will be feeding 5V to both the ends of the strip to account for the voltage drop after traveling such long distance. Don’t forget to solder one more wire to Din of the first LED along with power. After connecting the strips, it is a good idea to check for continuity between the start and end of the connected strips. Use the FirstLight sketch in FastLED library to do a final test of all the LEDs just to make sure we do not have a faulty one in between. Now you can stick the LED strip to the back of the TV and if you want you can do the same test again. It is good to be extra paranoid of this step as removing and hanging the TV back is a risky task, and we should aim to do it only once. I used a bit of hot glue to secure the protruding connectors. You may or may not do the same, it’s completely up to you. You can put your TV back at its place now.
Step 5: Soldering
Let’s do some soldering now. Please note that this step is optional. I am only doing this to reduce the number of wires in my setup. You can skip it if you want. Take the Raspberry Pi and Arduino and settle on a space for it in your perf board. Start soldering headers for both the Pi and Arduino and also solder the screw terminals. We will use the screw terminals to power both the Pi and Arduino and connect the data pin of Arduino to the LED. Make sure to double check the GPIO pin map of RPi and solder the power to correct GPIO pin. You can cook your RPi if you are not careful. I am using some leftover leads from LEDs, capacitors etc. from my previous projects to connect the header to screw terminals. Now prepare the SMPS by setting its output to 5.1V if it is not set at that voltage already. Connect everything together and do a final test.
Step 6: Connect It All!
All that’s left to do now is use some kind of connectors and a 3-core cable to extend the wire length and connect it to PCB we built, and we are ready to roll. Edit the Arduino sketch to set the correct number of LEDs in your setup and upload the sketch to your Arduino. Also, do the same in the Hyperion config and turn your setup on. It should be working as expected now. If you are not powering the Raspberry Pi using your SMPS and are using a separate power adapter for it, don’t forget to short the ground of SMPS and the Raspberry Pi so that we have a common ground reference, otherwise your LEDs will not light up correctly.
Step 7: Issues
One issue I faced with is the positioning of the camera. The LEDs color will completely depend on what your camera is seeing, and it is a bit hard to capture the TV screen from corner to corner in a typical living room. You will need to mount your camera very far away from the TV if you want to capture it completely. As a result, the camera only sees center of the TV in my setup, but don’t get me wrong, it is no way looking bad. In fact, I think it looks even better. We might be able to use a fisheye lens camera or using two cameras to capture the full TV screen. I don’t think Hyperion supports the two camera solution yet. Anyway, I have been enjoying the current setup for more than 1 year and I am very happy with it, and I don’t plan to change it.
Step 8: Done!
I hope you enjoyed this project. Let me know what you think and how you would enhance it. I will see you in the next one!