A brain for the light!

werner
10 min readJul 3, 2018

A brain for the Philips LivingColors Micro Lamp (7001830PH)

How to make an RGB LED light display the colour you want with your voice.

Some time ago I got a Philips LivingColors desk lamp to be used as a night light for my daughter. By running your finger over the control strip, you can make it emit pretty much any colour in the RGB spectrum. Pretty cool, except you have to actually touch it… : }

So time goes by and my daughter starts reading books, so this cool light got replaced with a normal bedside lamp, and because it’s cool, it deserves a new life... a better life… a smarter life.

ESP All the things!

As an amateur, budding Electronics Engineer, I have attempted adding the popular, awesome, cheap ESP8266 Wifi Enabled MCU to just about anything I can (in the name of learning of course) and this lamp is no different.

Step 1: Open it up

The thing that strikes me about modern tech products, is they seem to snap together permanently with neigh a screw in sight. So a bit of googling revealed a single image of how to attempt to open this thing up without breaking it.

Laura and Maaike over at instructables.com (see link at end) provided an answer, albeit a bit basic —

And this is what I tried... to no avail, but as fate would have it, I had to get back to some real food paying work which lasted numerous hours. Eventually it was late afternoon and my daughter came running into my office, grabbed the stubborn egg shaped device off my desk, and shouted “My old light!” whilst accidentally dropping it quite hard. And pop, it opened. Her face was one of “oh no I broke one of Daddy’s things again”, and mine, without trying to teach her it’s ok to break things, was of pure joy.

So to summarise — in order to open one of these, poke around a few times with a screw driver at the spot indicated in the photo, then leave it for a while, then throw it on the floor… It should pop open.

Step 2: The inside

Cracked open like an egg — you notice the massive heatsink.

I always love seeing how large companies (Philips in this case) design and assemble products. In this instance (omitting the missing power supply cover screw for now — must be cost savings in action), they have a fancy static finger strip thingy, with 16 sections each feeding into a micro-controller pin — the first thing I wondered was: how sensitive could this be? Definitely not at a resolution where the LED could display every colour possible… But hey, that’s for another day. What matters to me is the fact that there is plenty of space in this egg for a brain.

The LED is found under the rather large heatsink:

Notice the controller circuit with 16 segments from the touch strip connecting to the microcontroller.

In this picture you can see the contacts for R,G,B,Vcc and Ground. What’s important here is that this is actually 2 LED’s. One RGB (which is technically 3 LEDs in itself), and one pure white high luminance one (hence the extra ground connection).

Since RGB LEDs have 4 poles, 1 for Vcc (Or Ground), and the others for R,G and B respectively, the first thing to check is the polarity of the LED with a multimeter.

https://randomnerdtutorials.com/electronics-basics-how-do-rgb-leds-work/

In this case, it is indeed, a Common Anode (+)... Great.

Step 3: The plan

My philosophy with these things is that I always try to retain the original functionality of the hardware I am hacking (if possible). In this case, I would still like to control the light with the built-in touch strip in addition to the ESP8266 brain I want to add.

This complicates things somewhat as there will be two controllers vying for the same LED. Various solutions exist for this :

  • Add a physical switch to switch modes (not preferable)
  • Use an open collector configuration (complicated)
  • See if the ESP8266 can sink enough current on each pin to drive each LED, in which case we can simply use diodes to prevent the 2 controllers feeding each other (maybe)
  • Use a transistor to cut off the ESP when the strip is activated (definitely)

In choosing the last option, I expect the lamp to be controllable via the strip as normal until I “power it off”, at which time the ESP will boot up and await instructions. If someone touches the strip again, the ESP powers down again.

Step 4: The hacking

So here’s the bill of materials :

Hardware

  • Soldering kit
  • Wemo D1 Mini (ESP8266)
  • Some leads
  • A PNP transistor
  • USBa to USBm cable (You should have at least half a dozen after a decade of mobile phones)

Software

  • Visual Studio Code (VSCode)
  • platform.io plugin for VSCode

I like the Wemo D1 mini as it has all the ESP8266 pins easily available with on-board serial UART (and a USB port). Much easy! (And only a few beans more)

So first I remove the LED driver from the lamp, hook it up to the D1 Mini, and see if I can talk sense to it.

I’m not going to bother with a diagram, since the strip already has resistors included in it. All that you have to do is basically solder some leads onto the LED driver, connect Vcc and Ground, and then the R, G and B leads each to a GPIO pin (I chose D1, D2 and D3) — I also used a red lead for R, blue for B, and green for G. Thus, departing from convention, my Vcc lead is white and sticking with convention, my Ground lead is black. :}

Being a software developer by day helps, and I threw together a small piece of code from various sources to connect the D1 mini to my test WiFi router and run a web server that accepts RGB values and relays it to the pins. Like so:

Nifty…

With prototype working, I move on to get my power source and code in better shape. I would like to have a few things :

  • Powering the NodeMCU board from the lamp adapter
  • WiFi auto connect
  • Web server accepting RGB values
  • MQTT client auto connect and subscribe
  • MQTT client accepting RGB values on a topic

A few hours later, and the software is ready. I use the LED to indicate the progression of the above stages for me.

  • Red blinking — Wifi connecting
  • Yellow — Wifi connected, MQTT connecting
  • Green — Wifi and MQTT connected and ready
  • Off — Ready to accept RGB values

A full explanation of the code is in the git link at the end of this article — I have commented it profusely)

You will notice a capacitor connecting the LED strip to ground. This is to give the NodeMCU time (and enough amps) to boot up before the load of the bright white LED takes over.

At this stage, if you couldn’t care about using the original control strip controls on the lamp anymore, you can simply jam all this back into the light, wire up the D1 Mini to the power leads, and call it a day.

The next step was to wire up the control strip from the Philips lamp back into my prototype, and make them work together…

Step 5: The conjoined twins

As described earlier, I have various options to do this….

First I remove the flexible control board from the lamp and solder on some leads.

Then I breadboard some solutions.

Madness

So I got it working, tried out the touch strip (which was crap), blew a transistor in the process, looked at my spaghetti, and decided it would be much more elegant to just remove the touch strip completely, and stick with the NodeMCU ESP8266 board.

Step 6: The software

So as I mentioned, I would like to control the lamp via HTTP and MQTT.

If you look at the main.cpp file in the repo linked at the end of this article, you can see that the webServer is listening for a GET request in the form of

http://x.x.x.x/?r=255&g=255&b=255

Included in the repo is a directory called web you can cd into and run something like python -m SimpleHTTPServer to serve it from your shell / terminal. This will serve a basic colour picker that will connect to your MQTT broker, and send colour codes as you pick them — changing the colour of the light.

I can trivially include the web directory in the device SPIFF (IDE dependent — you will see my code where I open the filesystem) — but decided against it for now.

The rest of code is commented, so feel free to have a look around.

Step 7: Putting it all together

So with everything working, I properly wire my circuit into the egg, make a hole for the USB port to be accessed in case I want to re-flash the board, and pop it back together…

Tip: If you don’t have a suitable drill, or the casing in which you are trying to make a hole is oddly shaped — load an old soldering bolt head on your soldering iron and melt a hole the shape you need.

So there you have it, a $24.00 lamp turned into a $64.00 one with a $5.00 development board, a few bits and bobs, and time…

But wait, this is 2018...

So let’s hook this up to, say, Google Home.

Step 8: Adding to your smart home

Being a professional Full Stack Developer (whatever that means :} ), I was never keen on using projects like OpenHab or Home Assistant to be the gateway to my smart home.

Not only am I a bit paranoid about the security of my home network, but also always keen to see if I can do it myself. To give you an idea, here’s a picture of where the Internet enters my home in a walk in storage cupboard.

Part-Time cable management.

Besides the Router, Fibre CPE and ONT modem, you can see a Raspberry Pi with it’s red edged case doing something.

The Raspberry Pi is basically my home automation gateway, and all home automation related traffic is routed to it. It also hosts an MQTT broker to which my lights, switches and garage doors subscribe to for instructions (messages).

An Ethernet cable is seen disappearing into a wall — the other end of which connects to the rest of my home network through a dedicated firewall machine. I say this as I deliberately split Home Automation traffic from the rest. If a smart device goes rogue, the worst a hacker can do is turn my lights on and off — and with a little more effort, probably open my garage door.

I always first use an IFTTT applet to test a new device with Google Home — and live with it for a while. It’s easy to setup and requires very little additional code — Here’s a sample tutorial:

https://www.androidcentral.com/google-home-setting-ifttt-assistant

Once I have figured out how want the device to function on a permanent basis, I switch over to using the actual Google Assistant API and SDK (which is more powerful) to bring it into the fold, add it to rooms and groups, and so on.

The test applet I setup for this project

The process is basically:

  • Get a static IP from your ISP, or use a dynamic DNS service like noip.com to map traffic from the Internet to your home network.
  • Setup your router with a DMZ or Static route pointing to a webserver that accepts posts.
  • Setup your IFTTT applet and trigger a webhook when activated.
  • Your web server will get the POST when you give the configured command to your Google Home (or Assistant)
  • From there you can publish to the topic your device is listening on. In this case I used the topic brainLamp and in the command passed either a colour name, or the word random.
  • For interest sake, I developed my own HTTP/S to MQTT bridge in NodeJS for the Raspberry Pi — in addition to using Let’s Encrypt for TLS and a custom data model for flexible messaging. (I will do a writeup on this in the future)
  • If you are not akin to developing your own gateway, I suggest using OpenHab or Home Assistant open source projects instead.

And now.. drumroll…

Step 8: The final result!

So here it is. A voice controlled lamp…

Thanks for reading! Feel free to comment if you can see a mistake somewhere in the process. Until next time — may the soldering fumes be with you.

The code for this project is up @ https://gitlab.com/k1dbl4ck/brain-lamp

Thanks to http://www.instructables.com/id/Mood-Projector-Hacked-Philips-Hue-Light-With-GSR-T for indicating how I should open the light up. : }

--

--