Friday, March 1, 2019

DIY ambient light in the living room

It's been a while since our corridor project and we had plans for some changes to the living room since quite some time ... so it was time to make another one reality.

What is this project about?

The main purpose of this project has been to get a bit more ambient light into our living room. As this room only has one window, which is often also darkened by a shutter as the sun in the evening hours tends to become dazzling in this room, so it's often a bit dark.
The idea was to get a shelf behind the couch with an LED strip in the middle of it. Of course, we didn't want just the simple LED solution with remote control. The plan was to include some buttons to control the light inside the board directly. Later on, the LED should also not only light in a specific color at a time but display some animations and effects.
Further on, a charging station for smartphones should be built in as well.

The hardware

We went for some WS2812b RGB strips, two pushbuttons with LED (white for power on/off and orange for changing the color/animation of the LED strip), pots (to control the brightness) and a three-port USB power connector. When thinking about how to control it, we decided for a Raspberry Py Zero W, as it's easier to connect with other DIY solutions we are about to build, because of the build in wifi and Bluetooth.

Test setup at a breadboard
The first step was to set up all the electronic components at a test environment and get the base programming done in Python (more on that later in this article).

For the base construction, we got two boards of wood. One of them got cut in two smaller pieces to make room for the aluminum LED ledge. The two smaller pieces then got glued on top the carrier board and secured with a few screws.

The base construction

Next, we had to provide the holes for the buttons, the pots and the USB power connector for smartphones. 

The holes for the accessories
For the Raspberry Pi Zero W and the LED power connector, we 3D printed some cases. The one for the Pi we just downloaded at Thingiverse, created by endif, the one for the power connector we designed our self.

3D printed press-fitting case for the power plug

After that, all the electronics had to be transferred from the breadboard to the shelf, which was quite some soldering and a bit tricky at some parts.

Position layout before soldering

Everything soldered and put in place

Time to test if everything is still running :)

The buttons lit up and were working, same for the LED strip

Time to get everything mounted at the wall with some angles, screws, and dowels. We positioned the shelf behind the couch, just at the height of the couch rest.

Shelf mounted to the wall

Buttons and charger behind the couch

Ambient light behind the couch

For now, the brightness is set to a fixed (relatively low) value. Later on, the pots will allow to adjust the brightness.

The software

As mentioned above, the used board was a Raspberry Pi Zero W, therefore I could use Python for programming language :) . 

As I was recently setting up a different workstation for me at home, a PC with Ubuntu Linux and PyCharm as IDE, I wanted to try a different approach this time.
Usually, I directly connect to the Pi by ssh or vnc and develop directly on the device. Most of the time I by using VIM directly at a console for that. This time I wanted to try to remote connect to the Pi by PyCharm. 

PyCharm IDE with ssh connection and remote interpreter

At first I had some struggles to figure out how this setup would work and where I should manage the Git repository, but in the end, I got it to work.

This way I had a very strong IDE available with all its features, including debugging code remotely at the Pi itself, using a remote Python interpreter directly at the Pi. At first, a problem occurred here was that I had to run the code with sudo permissions but remotely I could only run it normally. I managed to solve this by a script created at the Pi that I called remotely to run this instead of the interpreter directly and set the interpreter call within the script with sudo rights.

That means I was able to run the code within PyCharm while accessing all the GPIO-pins of the Pi and use the IDEs debugging capabilities as well. Also, the management of the Git repository could be handled within PyCharm.

This was a really great experience and success to me.


The project had some challenges to get over but the result is great. In the first version we deployed now, the aim was to get it up at a wall and running. Later improvements will be done to the code mainly as well as the inclusion of the pots, which is not connected at the moment (it will control the brightness of the LEDs once it has been set up).
Also, different color animations will be implemented in the near future.

All in all the hardware for this project did sum up at about 80 €.