Gesture controlled IoT switch (with IFTTT)

 

We LOOOVE the internet-of-things. But always using a phone to turn a light on-and-off again is kind of a pain ain't it? We're going to fix that by building a gesture controlled light switch in this example! Don't have your phone in your pocket when you walk into your room? Just wave on your light switch and bam - light turns on. 

We're going to use the following parts:

Hover + Particle Photon + LIFX + IFTTT = Gesture controlled light switch

The same combination can be used to control any IoT device that's supported on IFTTT -- use gestures to control your Nest Thermostat, August Lock and more. More ideas can be found here

 

 

Connect Hover to Particle Photon

Follow the hookup guide here

Setup the IFTTT Recipe

Sign in to IFTTT and click on Create. Then click the 'this' link. 

 

Type in Particle in the search box and select it. 

 

 

 

Next, select the 'New event published' button. 

 

 

 

 

In the next step, type in the text as shown. You can select a different Event Name and Event Contents but keep note of it because the event names used here must match our particle code later. 

 

 

 

Now click on the 'that' link. 

 

 

In the search box, type lifx and select it. Note that if this is your first time setting up the LIFX channel on IFTTT, you may be redirected to a popup to log in with your LIFX credentials. Once you've done that, it should redirect to the page shown below.

 

 

Now select the actions that should happen when this event is triggered. We select 'Turn lights on' in this example to match our 'lifxup' event. 

 

 

 

 

Finally, select your preferences when this action is triggered and hit 'Create'. You just finished setting up one recipe! Now every time an event named 'lifxup' is published by Particle, this recipe will trigger and cause your LIFX bulb to turn on. 

 

 

 

You'll need to repeat the steps above to setup other recipes corresponding to different gestures like swiping down (to turn lights off) or swiping left and right (to change light colors). 

 

Download Code from Github and Flash!

Download the library and navigate to the /examples/Hover_IFTTT_LIFX_Demo folder.  Copy the library over as well to the Particle IDE and flash!

A few notes on the code: 

To publish an event for each gesture, we use the Particle.publish() method shown below. Each gesture corresponds to a different call to Particle.publish() using the same event names we used to setup IFTTT above. The publish method enables us to generate different events based on different conditions - specific gestures in our case.  

if (g.gestureID == 1){
    switch (g.gestureValue){
        case 0x01:
          Particle.publish("lifxleft", "swipeleft");
          waveLeft();
          break;
        case 0x02:
          Particle.publish("lifxright", "swiperight");
          waveRight();
          break;
        case 0x03:
          Particle.publish("lifxup","swipeup");            
          waveDown();
          break;
        case 0x04:
          Particle.publish("lifxdown","swipedown");            
          waveUp();
          break;
        default:
          break;
    }
}

Going further

We've taken this basic setup further by 3D printing a case to house Hover and the Particle Photon as shown below. Hover can be covered up by any insulating material (like plastic, acrylic, etc) and gestures and taps will still be recognized! We left a small circular opening in the middle for design purposes but you can cover it up completely if you like. 

To take it even further, you could fit a NeoPixel ring on top of Hover as shown below to get instant feedback when swiping. The code you grabbed from the github link above already incorporates NeoPixels.

If you don't have a set of Neopixels lying around, feel free to comment it out or ignore it to test your code. In this example, we used the 24 count ring NeoPixel available from Adafruit.