Introduction: Gesture-Capture Remote-Control Console

Project Summary

This project provides an alternative to the standard TV remote: a more interesting (and much cooler) way to control IR-enabled equipment. (To be clear: this is faux gesture-capture - I'm just using a set of cheap motion-detecting LEDs to record the end-points of simple gestures made immediately above, and in the plane of, the console box.) Using Arduino instead of buttons, I can "stack" commands, turning multiple devices on or off with a single gesture.


This Instructible focuses on the control unit, but there are additional sections that describe the IR-receiving hardware and code that I used to determine what "messages" the TV remote was sending. Generating the same codes in Arduino, the console makes it possible for you to use gestures to control both IR-enabled devices (TVs, DVD-players, etc.) [Addendum 1] and those that are not IR-capsble, like lamps, fans or heaters [Addendum 2].
(Addendum 3 contains a plea for help from readers with experience in working with IR in Arduino.)

So - if you've ever wanted to mute your TV by making a gesture at it, here's what you'll need to make that work:

Step 1: Required Materials (Gesture-Capture Console Only)

1 Box (I used an iPad Mini box, 9"x6"x2")
1 Arduino Uno: (Adeept atmega328p)...............................................$14.49
4 Proximity Sensors: (IR Obstacle Avoidance Sensor Module).............6.84
1 Mini Breadboard.................................................................................1.80
Assorted Breadboard Wires..................................................................20
1 IR-Transmitting LED: (5mm 940nm IR emitter LED)..............................20
1 On/Off Switch: (Rocker Switch - SPST [Sparkfun]):..............................95
1 9v Battery............................................................................................1.93
1 Battery-to-Arduino Connector................................................................36

For IR-Signal Amplification:
1 2N2222 Transistor...................................................................................14
1 470-ohm Resistor...........................................................................…….03

For LED Signaling Option:
4 LEDs…………………………………………………………………………..08
4 220-ohm Resistors…………………………………………………………..04
Another Mini Breadboard…………………………………………………1.80
More Breadboard Wires……………………………………………………..20

Total…………………………………………………………………….Under $30

Step 2: "Some Assembly Required": the Box

I used the box that my treasured iPad Mini came in, and it worked well. A viable alternative (one that occurred to me only after the project was complete) is for sale at hobby stores: small wooden boxes are available in a variety of useful sizes for under $5.
Turn the box over and drill 1/2" - 3/4" holes in all 4 corners (cover the exit areas with tape to minimize splintering, and use a sharp drill with minimal pressure); drill another (smaller) hole near where you decide to mount the display breadboard. (Mounting the unit in the middle of the box, as I did, interferes with one's gestures: putting it on the side facing the user would be better.)

Step 3: "Some Assembly Required": the Wiring (1)

There are 4 'circuits' in the Gesture-Capture Console (GCC): POWER, INPUT, OUTPUT and IR.

Let's wire up the POWER first:
(Please refer to the photo above for wiring details.)
Note that I soldered and heat-wrapped a switch into the Battery-to-Arduino Connector, so that the GCC can be switched on and off without opening the box. (In a future update, I plan to add a 'Sleep' function to the device, which should eliminate the need for a switch - and the soldering. )



Step 4: "Some Assembly Required": the Wiring (2)

Next, we'll add the INPUT wiring for the sensors that will be positioned at each corner of the box. (Again, refer to the photo above.)

The pins at the bottom of each of these sensors are labeled: the right pin (VCC) connects to the Arduino 5-volt pin (via the mini-breadboard); the center pin goes to the Uno GRD (again, through the breadboard); and the left pin (OUT) is connected to one of the digital input pins on the Arduino. In the interest of clarity, I've fully wired up only one sensor in the accompanying photo. You'll need to add wires from the 3 other sensor GRD pins to the left side of the mini-breadboard, and from the remaining sensor VCC pins to the right side of the breadboard.

(Note that the purple breadboard wire goes from the OUT pin on the sensor at the lower left corner of the box to Uno pin 2; the green wire goes from the sensor on the lower right to pin 4; the blue wire goes from the upper right to pin 5; and the grey wire leads from the upper left sensor to pin 6. The user can change this layout, but he'll need to change all the gesture descriptions, too.)

My experience with these sensors has been mixed: They're adjustable, which is not necessarily a good thing; they're a little quirky, going out of adjustment at inopportune times; and they're influenced by artificial light, which means you can't keep the box under a lamp. On the other hand:
they work, and they're cheap.

Step 5: "Some Assembly Required": the Wiring (3)

The OUTPUT function consists of LEDs that show the user what gesture the device has captured. Although the colors are arbitrary, the relative position of the LEDs is not: the red LED represents the lower left corner of the box, and is connected to Uno pin 7; the yellow LED corresponds to the lower right corner and is wired to pin 8; blue is upper right and pin 9; and green is upper left and pin 10. (The positive [longer] lead of each LED connects to the respective Uno pin 7-10; the negative lead goes to the Uno GRD through a 220-ohm resistor.)

(Note that the white mini-breadboard shown above is the same as the one shown in Step 3: this is the second "layer" of wiring to be applied to that board.)

Step 6: "Some Assembly Required": the Wiring (4)

And - finally - we'll apply a third layer of wiring to the white breadboard: the IR emitter that's the raison d'etre for this whole project.

The IR-emitting diode requires amplification, so I included a transistor and a resistor, per an AdaFruit tutorial. The positive (longer) lead from the diode is connected to Arduino pin 3; the negative lead goes to the right lead of the transistor (with the rounded side facing you.) The center lead of the transistor connects to Arduino pin 3 through a 470-ohm resistor, and the left lead is attached to an Arduino GRD.

This IR diode transmits the codes that activate IR-capable devices, just as a TV remote does.

Step 7: Accessing and Modifying the Sketch

When you're done building and wiring the Gesture-Capture Console, you're ready to install the program that makes it work.

To access the Gesture-Capture Sketch (GCS), click on this link:

https://docs.google.com/document/d/1s2qNIBgP0V5VEoi6c2O7Ip0jX-iu9-DoTvaG0_nMqpM/edit?usp=sharing

Copy the code, then open Arduino and paste the GCS into the code box that appears, overriding everything in the box (Select All>Paste). Rename the sketch (File>Save As) and test-compile the GCS.

(A note on the code: I've tried to make this information accessible to readers with any level of experience. I've included a lot of "// explanatory notes" in the sketch: a narrative describing the code and processing runs down the right side of the sketch. (You'll want to use a full-screen view). I've also retained display routines and some of the debugging code to make it easier to get the sketch running. (More experienced readers should feel free to contribute sophisticated code, and to ignore the narrative.)

Before uploading the GCS to your Arduino, you'll need to gain some basic familiarity with the code (because you're going to have to modify it, slightly.) The parts you'll be changing are the long strings of raw code in the initial section of the sketch (e.g.: unsigned int SamPWR[78] = xxx, xxx . . .). These are the "messages" that control my TV and satellite box: you'll have to change them to work with your own devices. To do that, you'll need the information contained in the YouTube tutorial "1302 Arduino Chapter 13 Capturing Raw IR Codes" by Jason Welsh: please refer to that excellent work for details.
To summarize Jason's project:
Hardware: You'll need an Arduino Uno and an IR-receiving diode. With the bubble on the face of the diode facing you, connect the left lead to Arduino pin 11, the center lead to one of the Arduino GRD pins, and the right lead to the Arduino 5v pin.
Software: Upload Jason's sketch (File>Examples>IRremote>Capturing Raw IR Codes). Activate the serial monitor (Tools>Serial Monitor).
Processing: Point your TV remote at the diode and press the ON button; several paragraphs of data will be displayed on the serial monitor. Copy and save the data from "unsigned int" through "irsendRaw(raw,xx,xx)" into a file or Notebook page set up to store this information.
(Note that the term "raw" in both expressions is the name of the data set: you'll want to replace it with a name of your own. (For the code generated by the ON button on my remote, I chose the name TVON; I identified that data set as "unsigned int TVON[78]= xxx, xxx. . ." and used the Arduino command "irsendRaw (TVON,78,38);" to send that code to my TV.))
Repeat this process for any other functions you may want to control by gesture.

Having captured, renamed and recorded your activation codes, you're ready to return to the Gesture Control Sketch: Copy and Paste your "unsigned int" codes at the top of the sketch (replacing mine); then locate the gestures you want to use in Section 3 of the processing portion of the sketch, and enter the appropriate "irsendRaw" command in the code block associated with that gesture. (To turn my TV on, I use a gesture like brushing dust off the right side of the control unit, so I placed the command "irsendRaw (TVON,78,38)" in the processing section immediately following the line "Serial.println ("Gesture is a right-side upwards swipe");".)

Compile your version of the sketch (correcting as necessary) and upload it to your Arduino. Turn on the control unit (the LEDs will cycle to show you it's ready to go), and try it out: passing your hand over one side of the box should light up the LEDs on that side and, immediately afterwards, the device you've associated with that gesture should come to life. (With a little practice, you can learn to disguise the simplicity of the control unit by making your gestures florid or elaborate, but still touching the same end-points.)
"…And now … Live from New York …!"

Step 8: Addendum 1: Controlling IR-Capable Devices

There's lot of information available online on this topic, but it took me a very long time to locate material that I could understand and that actually worked. Jason Welsh's four YouTube tutorials ("1301 Arduino Chapter 13: Introduction" through "1304 Arduino Chapter 13: Sending Raw IR Codes") are clear, detailed and functional: they provide all the information that you'll need to identify the codes that control your TV, DVD player, satellite box, etc., and to incorporate those codes into my gesture-capture sketch. Please refer to his tutorials for code, materials requirements and cost estimates. (I'd guess that all the pieces for this part of the project cost less than $3.00.)

I'll be happy to answer any questions and help with problems, but you'll probably get better information about the IR tutorials directly from Jason.

Step 9: Addendum 2: Controlling Non-IR Devices

In order to establish control over any device that isn't equipped with an IR receiver (a lamp, heater, coffee-maker, etc), you only need to splice an Arduino-controlled switch (relay) into an extension cord supplying current to the device. The Arduino sketch referenced below includes an IR receiver which allows the gesture-capture control-unit to turn the relay - and the device - on and off.

Naturally, there's an Instructible for that: I chose Osten Jos' "Controlling AC light using Arduino with relay module" for its simplicity, and because Osten doesn't go overboard in describing the dangers of working with 120-volt circuits. You can find his project on Instructibles.com, and you can buy the materials for it (an Uno and a relay) for about $15 (per slave device). I modified his circuit to include an IR receiver, and changed his code slightly; to access the revised sketch, click this link:

https://docs.google.com/document/d/1yRURSAd3HLL0OC7phS42dHUgmAvD4_q5PGxhzIuZ43I/edit?usp=sharing

Step 10: Addendum 3: Notes, Suggestions for Improvement, and a Plea for Help

Some semi-important details, in random order:

16-year-old FoamboardRC has posted an important caveat about a program you may need to remove from your Arduino library in his excellent
Instructible, "How to Use IR Remotes with Arduino".

Jason Welsh's tutorial doesn't call for it, but I needed to amplify the signal from the IR LED, and I used the wiring diagram at the AdaFruit tutorial
"Using an Infrared Library on Arduino: Sending IR Codes. "

In debugging the IRsend portion of the sketch, I found that my iPhone 6 camera wouldn't allow me to see an IR signal - I had to use a Samsung.

Someone may want to correct my math, but I think that the addition of a block of code to increase the number of motion end-points from 2 to 3
(a relatively simple change) would produce a total of 64 gesture-reading possibilities instead of 16.

Keeping the Arduino and the sensors powered seems to use a lot of power. This thing needs a 'Sleep' mode.

It also needs optimizing - it's way bigger than it ought to be. John Gialluca has a tutorial on code optimization, and I'll be updating this Instructible right after I view and absorb that information.

Finally, a plea for help: In trying to put together a stack of commands to activate my DVD, I've run into a problem. Using Jason's Capture Raw IR Codes, I've found that several buttons on my TV remote generate (slightly) different codes each time I press them, making it impossible to copy a working code for that function into IRsendDemo or any other sketch. And I NEED that function! Does anyone have experience with this sort of thing? Have you found a way around the problem? Will you please, PLEASE tell me? (I'll happily accept general referrals to sources that might contain useful information, or suggestions for a work-around.) Thanks, guys -
Neil