Filter results by

Make Any Device Gesture-Controlled

In this tutorial, we will integrate a few IoT technologies to create a new gesture-controlled device. It will require only some basic development skills and about an hour or two of time to complete.

Hardware Required

You'll need these resources to do the tutorial.

Set Up Equipment

We need to set up the equipment.

  1. Follow the instructions outside this tutorial for connecting the Wemo Insight Switch and the ARTIK board to your Wi-Fi access point.

  2. Plug in the device you wish to control such as a fan or lamp.

  3. Wire the IR sensor to the ARTIK board to analog pin 0 (shown on an ARTIK 710 kit).

  4. Log in to your ARTIK board via serial terminal or ssh and set up Node-RED with three add-on nodes:

    dnf install npm
    npm install -g node-red
    npm install -g node-red-contrib-artik
    npm install -g node-red-contrib-artik-cloud
    npm install -g node-red-node-wemo
    node-red &

Programming the Flow

Great, now all the equipment is set up. On to the programming and configuration portion of the tutorial:

  1. Connect to the running Node-RED instance on your ARTIK board by pointing your browser to http://x.x.x.x:1880
  2. Build a simple flow on the canvas that connects 4 nodes available from the palette in this order (or download all flows for this entire tutorial here):

    • Inject input node
    • ARTIK ADC node – configured as pin 0 with the proper board selected from the drop-down menu
    • Function node – configured as an interval, repeating every 1 second
    • Wemo output node – configured to select the Wemo Insight that is available on the network.

  3. For the function node (shown as "Logic" in the screenshot), the JavaScript code should be as follows:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
var old_proximity = global.get("proximity") || 0;
var new_proximity = msg.payload;
if (old_proximity <= 3000 && new_proximity > 3000) {
    if (global.get("wemo_state") === "on") {
        msg.payload = "off";
        global.set("wemo_state", "off");
    } else {
        msg.payload = "on";
        global.set("wemo_state", "on");
    }
} else {
    msg.payload =  global.get("wemo_state");
}
global.set("proximity", new_proximity);
return msg;

Deploy the flow and place your hand near IR sensor for a second or two. Notice the device turn on. Then take your hand away, put it back for a couple seconds and notice the device turn off. Congratulations, your device is now smarter than it was before! Isn't that fun?

Visualizing in ARTIK Cloud

But wait, that's not all – you can add your device to ARTIK Cloud for visualization and even integration with the rules engine.

  1. Open a new tab or window in your browser and sign in to https://my.artik.cloud/devices (sign up if you need to).
  2. Click "Add another device…" and start typing to find the Belkin WeMo Insight Switch Proxy device type, then click "Connect device…" .
  3. Select your newly created device and then click "Generate device token…" within the popup.
  4. Leave the ARTIK Cloud browser tab or window open and switch back to your Node-Red canvas.
  5. Drag 2 nodes to the canvas and connect them, a Wemo input node and an ARTIK Cloud output node.
  6. Select the Wemo connected to the network from the pulldown in the configuration of the Wemo node.
  7. Copy and paste the Device ID and Device Token from the other ARTIK Cloud browser tab or window into the ARTIK Cloud node configuration.
  8. Deploy the flow and go to https://my.artik.cloud/data in another tab or window.
  9. Click "+/- Charts", select the "State" field from your new device, and close the popup.
  10. Wave your hand over the sensor again and notice the chart is populated with data like the screenshot below.

Awesome work, now you are collecting data to track state changes.

Controlling from ARTIK Cloud

Finally, you may want your new device to also be controllable in ARTIK Cloud from the rules engine based on the conditions of other devices. We can set that up as well.

  1. Drag three more nodes to the canvas from the palette and connect them.

    • ARTIK Cloud input node
    • Function node
    • Wemo output node – configured with the proper Wemo selected

  2. Copy and paste the Device ID and Device Token from the other ARTIK Cloud browser tab or window into the ARTIK Cloud node configuration.
  3. The JavaScript code for the function node should be:
1
2
3
4
5
6
7
8
9
10
11
12
var value = msg.actions[0].name;
if (value === "toggle") {
   if (global.get("wemo_state") === "on") {
        msg.payload = "off";
    } else {
        msg.payload = "on";
    }
} else {
    msg.payload = value.substring(3).toLowerCase();
}
global.set("wemo_state", msg.payload);
return msg;

Deploy the flow and now you can use the rules engine in ARTIK Cloud to control your device as well. Go to https://my.artik.cloud/rules to see or edit your current rules and to set up new ones.

Hope you found this tutorial useful, you can modify the code or steps to suit your specific needs. Best of luck!

Last updated on: