Home IoT – Voice Controlled Lab Lights with Amazon Alexa and ESP8266

I recently won an Amazon Echo in a BBQ cooking competition and I was eager to get it set up in my house. As you may know, the Echo allows you to use voice commands to do things like order from Amazon, play music, set timers, and get the weather forecast. By adding additional “skills”, it also allows you to integrate with smart home and Internet of Things (IoT) devices.

I integrated it with my Hue lights and my SmartThings hub by installing the relevant skills for those devices and was able to control everything with voice commands to Alexa. But being a maker, I wasn’t satisfied with just buying premade devices. I wanted to be able to create my own smart IoT gadgets that I could use with the Echo.

I had recently installed an Adafruit analog LED light strip for task lighting in my home lab but I needed a better way to control it. Adding voice control to it would be a great solution.

Around 8 feet long, the lighting strip contains 18 sets of 4 LEDs per foot, in red, green, blue, and white colors, and runs on 12 volt DC power. The LEDs are arranged in repeating sets of 3, each with current-limiting resistors. One segment looks like this:

A logical choice for controlling a DIY smart home device is the ESP8266. With an integrated microcontroller, 9 GPIO pins which can also be used for I2C or SPI, a serial UART, and built-in Wi-Fi, the ESP8266 has all of the elements required for a basic IoT device in an inexpensive package. I already had an Adafruit HUZZAH ESP-8266 in my parts bin, so that’s what I chose to start with.

The missing piece was the software to make this work. A brief search of the web led me to the fauxmoESP library. This is an Arduino IDE compatible software library that emulates a Belkin Wemo device and uses that protocol to communicate with the Echo.

Laying Out the Schematic

Armed with this information and the library code, all I needed to do was to put together a circuit and the code to control my LEDs. Each segment of 3 LEDs draws around 20 mA of power per color, so that’s a total power draw of 80 mA per segment. I have an 8 foot strip, with 6 segments per foot, for a total of 6*8*80 mA = ~3.8 amps @ 12 volts.

The ESP8266 runs at 3.3 volts and has GPIO pins with a maximum current capacity of only 12 mA. To drive the 12 volt, high-current LED strip, we are going to need some help, in the form of a beefy external power supply and a quartet of N-Channel MOSFETs. The MOSFETs allow us to switch the 12 volt circuits on and off using the 3.3 volt GPIO pins on the ESP8266. The basic circuit is shown below:

For testing, I assembled all of this on a breadboard and attached an 18 inch scrap piece of LED strip that I had left over from my project. 12 volt input power is supplied by my bench power supply and the 3.3 volt power for the ESP8266 is provided by an OKI regulator on the breadboard.

Setting Up the Code

With everything assembled, it was time to write the code. I started out by installing the fauxmoESP library by downloading the zip file and adding it to the Arduino IDE.

Next, I copied the example code from the fauxmoESP_Basic.cpp into a blank Arduino sketch and saved it as fauxmo.ino, modifying it to match my selected GPIO pins and hardware. I created five virtual devices to control my LED lights:

Programming the ESP8266 in the Arduino IDE

The Adafruit ESP8266 that I used comes with the LUA interpreter installed by default. To use the Arduino IDE, we are going to overwrite that by uploading our sketch to the device. To upload code, you need a USB to Serial TTL converter, for example an FTDI cable or similar. Mine is on port 13, so I selected that port in the IDE and connected the cable to the breadboard.

To upload the sketch, I put the ESP8266 into bootloader mode by doing the following:

Press and hold the GPIO0 button

Press and release the Reset button

Release the GPIO0 button

In the Arduino IDE, I set the board type to “Adafruit HUZZAH ESP8266” and the COM port to COM13, which is my USB to serial adapter board. Then, I uploaded the sketch, which also compiles the code.

Pairing with Alexa

Now that the code is uploaded to the ESP8266, we can check the Amazon Alexa apps for the new devices. First go to devices:

Then scroll to the bottom and select “discover”

We can now see our 5 devices: test green, test blue, test red, test white, and test lights. Test lights turns all 4 colors on or off at the same time.

This was a fun and relatively easy project. I used this same design to Alexa-enable my workbench lights and now I have full voice control of my LED lights. I’m sure I will find more uses for this project in the future. How would voice control work in your design projects? If you have used other voice control services, what did you think of them?

I could could see this being used in a home theater. Or even better, I could see this being used in a bath/shower setting to control water temperature. The ideas are coming, now I just need time to do them 😉