Star Wars Inspired "Jedi Lights" - Pozetron Inc

Episode IV

Admit it, ever since you first saw Star Wars you’ve wanted to control the world around you by waving your hands. Grab that blaster, lift that enemy, forget those droids. While gesture control has certainly come a long way we’ll start off with a project that is slightly less ambitious than mind control.

We’re of course talking about Star Wars inspired “Jedi Lights” or as they are more properly named, gesture controlled light switches. These gesture controlled light switches allow you to turn on, off or dim your connected lights with just a swipe of your hand. This could be really useful because you are carrying something, say a rambunctious toddler, or simply because light switches are so last century. Because the modules we are using are able to detect gestures other than just simple swipes we will even program them to change the color of the lights in the room with another simple gesture.

A New Project

The gesture controller that we’ll be using for this project is the ZX Distance and Gesture Sensor from sparkfun. This sensor uses two IR (infrared) LEDs to illuminate an object and a sensor and a microcontroller to interpret the reflected light and recognize the gesture performed. We’ll be using the I2C protocol to communicate with the module from our main microcontroller. For this project we have selected the Adafruit Feather HUZZAH which is based on the versatile ESP8266 module. This provides us with a MicroPython compatible microcontroller with integrated WiFi that we will use to communicate with the lights.

That’s it, these two small PCBs and some wire are all that are needed for this project! Oh, and a power supply like the Travel USB Wall Charger plus a Micro USB cable if you don’t have any spare.

The light… it’s always been there.

The power of connected devices comes from, you guessed it, their connectivity. We’re going to take advantage of this by making simple network calls to control the lights which frees us from worrying about concepts such as PWM or PID. We tell our hub what colour or brightness we want the lights to be and the light bulb manufacturer takes care of the rest.

As an additional benefit of utilizing an off the shelf solution for our lights we can let our light switches become just another part of the whole system. Want to speak to your lights to turn them off? Sure. Want to use a smart phone app as well? Of course! In our example code we will be using the Phillips Hue Lights but another type such as Insteon would work equally well.

A few good wires

The wiring for our project is actually quite trivial, the gesture module will need only four wires for the communication over I2C. Power (VCC) and Ground (GND) as well as Data (DA) and Clock (CL).

Power (VCC) on the ZX Distance and Gesture Module will be connected to the pin marked 3V on the Feather. We will connect GND on the gesture module to GND on the Feather. The DA pin on the red gesture module will connect to the SDA pin on the Feather and finally the CL pin on the red PCB we will connect to the SCL pin on the Feather with the black PCB.


Now for the easy part. For our software we’re obviously going to take full advantage of the power of MicroPython and Pozetron to deploy to our Feather.

Let’s start by looking at the

You will need to update two values in the URL defined in HUE_HUB_URL. First, you will need to replace the <ip_address> with the IP address of your Hue Bridge from our Hue IP Tool.

Secondly, in order to communicate with the Hue lights we will need a token or in the Hue parlance a ‘username’ to authenticate to the Hue Bridge. This will form part of the URL when we make requests to the bridge to turn on or turn off the lights. In our example code you will see the placeholder <username> which you will replace with your value.

To make it easy for you to obtain a username we have set up a tool you can use: Hue Username Generator. Just load the page, press the button on your Hue Bridge and then press the reload button on the page. You should see a long string of characters above the button. Replace the <username> placeholder with these.

You will need two more files to go along with the main file. The module to read from the gesture sensor and a module to make the scrolling more intuitive

Laugh it up, Fuzz ball

Now that we’ve got our files, we’re going to upload them to the Pozetron cloud so we can deploy them to our Feather. Run the following commands from a terminal.

$ tag add $( script upload -f -m zx_gesture) zx_gesture:1.0
zx_gesture:1.0 -> 90b57e1ab6223731e64b154167a07d41c306e2b60512123ad0c88f693d9342fb
$ tag add $( script upload -f -m inertial_scrolling) inertial_scrolling:1.0
inertial_scrolling:1.0 -> 3afc1b7774a1130964d9408c4cec46125bddb474aec60256a3ea4ff7957e12ee
$ tag add $( script upload -f -m main) gesture_main:1.0
gesture_main:1.0 -> a9779f2fc22a7502111d20394299c0c84e78b8f1e76faed015974edcb150d77f

Next, we will assume that we have already followed the Getting started with Pozetron on the ESP8266 tutorial and have a DEVICE_ID for our Feather. In our example this was a77eed66d15a3b3cba76573376695729bf7bce33d8e0997bfd8399f993fca4f8.

$ tag add a77eed66d15a3b3cba76573376695729bf7bce33d8e0997bfd8399f993fca4f8 gesture

You can make sure that the module is connected to the cloud by checking the time that it last checked in to make sure it was within the past few minutes.

$ device last-seen -d gesture
2017-10-05 12:12:22

Now for the final steps.

$ script deploy -s zx_gesture:1.0 -d gesture
$ script deploy -s inertial_scrolling:1.0 -d gesture
$ script deploy -s gesture_main:1.0 -d gesture
$ device log-mode enable -d gesture

You can view the logs for this module to make sure the modules are loaded and ready.

$ device logs -d gesture
2017-10-06T05:04:04.099092 Rebooting
2017-10-06T05:04:25.289329 Log mode enabled
2017-10-06T05:04:25.290705 Added: 7feaa9aba7c9d5df460638629a23364a8142e7b765a81d8d88e93af652bdb050 zx_gesture
2017-10-06T05:04:25.291832 Added: bc9f2c0843541035c1583c62adf2b5caf05e1fd4498ac24b71dd426942ced08c inertial_scrolling
2017-10-06T05:04:30.727233 Added: ccda189868b95271aa3c9eb17ff316d3c6feb101e4675d8f90f15f8b340c6df6 main

Now we will reboot the Feather so that it picks up our new main module.

After this you will be able to swipe your hand in front of the gesture module and see your lights get brighter and dimmer. Neat!

$ device reboot -d gesture
$ device logs -d gesture
2017-10-06T05:08:25.539104 Rebooting
2017-10-06T05:08:34.037394 Log mode enabled
2017-10-06T05:08:34.038702 No changes to deployed scripts
2017-10-06T05:08:34.039692 Device rebooted
2017-10-06T05:08:34.041567 Ready to sense gestures!
2017-10-06T05:10:27.843236 Dectected: Swipe Right
2017-10-06T05:10:29.702070 Dectected: Swipe Left

For the best performance you should disable the log mode when you are done.

$ device log-mode disable -d gesture

Free Registration

No credit card required. Limited time only.

Register Free