Introduction: Use the "Force" to Drive a Remote Controlled Device With a DIY 3D Capacitor!

For our electronics class project, we made our own version of the 3D capacitive controller described here:

https://www.instructables.com/id/DIY-3D-Controller/?ALLSTEPS

and here:
http://blog.makezine.com/2012/08/10/build-a-touchless-3d-tracking-interface-with-everyday-materials/


The controller is made up of a cardboard support, 3 "plates" of aluminum foil, shielded wire, resistors, an arduino, and a computer with a charger and the proper software.

By putting your fist in the space between the plates, you are creating a capacitor between your fist and the plates, with the plates at some voltage and your body at ground (don't worry - this is safe!) 

By changing the distance between your fist and the plates, you are changing the capacitance.  The Arduino can measure this by grounding the plates, then letting them recharge from a constant 5V source, and measuring how long it takes to recharge to a certain threshold.  This time is determined by the RC constant (equivalent resistance of the circuit times the capacitance), and since the resistance is constant, it's a measure of the capacitance.

The Arduino can measure the changes in this recharging time relative to an initial calibration, and through the Processing code, it figures out the location of your hand.


A quick overview of the steps:

1. Build the cardboard support structure pictured with 3 (non-touching) pieces of aluminum foil

2. Construct the circuit that we will discuss later using shielded wire, alligator clip heads, and resistors.

3. Plug the circuit into the Arduino (download Processing 1.5 if you don't already have it) and run the code found here: https://github.com/Make-Magazine/3DInterface

4. Run the Processing sketch and make sure that the capacitor can sense the location of your hand as shown in the videos from the guides we linked above

5. Modify the code in the Processing sketch so that it sends information about the location of your hand to the Arduino through the serial port

6. Modify the Arduino code to use that information to drive a device of your choice!  You'll need to take apart the device and wire some inputs from the Arduino into its circuitry.  We chose to drive the throttle of a remote controlled helicopter, varying rotor speeds (and thus the height that the helicopter flies at) depending on the position of your hand.

This project could still use some improvements and fun add ons!  Because of this, we'll try to describe some of the major problems we encountered during the making of the project, how we debugged them, and managed to fix them (or not.)

Step 1: Things You Will Need

You will need:
Cardboard
Aluminum foil
Shielded wire (Your results could be much worse if you use non shielded wire for the alligator clip cables due to an antenna effect )
Three 10k resistors and Three 270k resistors
An Arduino Uno with a Serial cable
A computer with a charger
Arduino software
Processing 1.5
Wire cutters or a knife to strip shielded wire

Step 2: Make the 3D Capacitor

Cut out three pieces of cardboard to support the aluminum foil and connect them so that they can stand on their own as shown in the picture. For this job, we used every DIYer's best friend: duct tape.  

Originally, we used large aluminum plates, which is why (if you look carefully) we have these little cardboard ridges on the inside edges that will hold the plates in place and prevent them from touching.  There was originally one in the vertical edge too.  

We experimented with different sizes of aluminum foil and our results were best when we used 8" x 8"  pieces.

Cut out three pieces of 8" x 8" aluminum foil and tape them to the cardboard as shown in the picture.   If you want to organize your wires better, you can cut a hole in the back corner of the cardboard, and thread the 3 cables through there.  Just make sure not to allow electrical contact between the plates or cables.

Step 3: Make the Wires (capacitor End)

You'll need three pieces of shielded cable for best results. You can use non-shielded wire as a cheaper alternative but the electromagnetic fields from the current will mess with your data and make your position inside the capacitor less accurate. We used BNC cables to make everything look nice. (Pictured).

First, cut off about an inch of the outermost layer of the cable to reveal the shielding. (Pictured)

Cut off the shielding. We don't need to worry about what we do with it on this end of the wire because with shielded wire, you only set the voltage on ONE end. The BNC cables make this easy on the other end of the cable, which we will set at 5V. This means the shielding can just get cut off on this end.

Strip the wire coating to reveal about half an inch of the wire at the end.

Strip the wire connecting to the alligator clip to reveal about half an inch of wire. 

Solder the two together. (Pictured)

Step 4: Make the Wires (arduino End)

Solder a 10k resistor and a 270k resistor to the yellow part of the BNC connector that juts out.  This part connects to the shielded wire that goes to the alligator clips. (Pictured).

Connect the three ends of the 270k resistors. We will call this "Connection A" for clarity. Solder wires from the tab that sticks out of the BNC connector (this connects to the shield and is labeled as "tab" on the second photo in this step) to Connection A.  The shielding acts as a Faraday Cage, blocking stray electric fields from outside and keeping the wire from becoming part of the capacitor and reducing the sensitivity of your circuit.

Finally, solder a wire to Connection A, leaving the other end available to be plugged into "5V" on the arduino. The 10k resistors will be plugged into digital pins 8, 9, and 10.

Note: It's very important to keep these wires and resistors from touching each other lest the signals from different plates interfere with each other.  You might want to look into separating them with electrical tape or shrink wrap tubing or something of the sort.

Step 5: Arduino Code and Processing Sketch

The code for the Arduino and the Processing sketch can be found here: https://github.com/Make-Magazine/3DInterface
It's best to download it as a zip file (click the arrow button) so that the directory structure is preserved.

If you haven't already, download Processing here: http://www.processing.org/download/

To be safe, make sure to download Processing 1.5.1, NOT 2.0!  We encountered some bugs running the code possibly due to incompatibilities with Processing 2.0.  

If you live in North America or Japan, change the line "#define mains 50"  to "#define mains 60" in the Arduino code
This reflects the 60Hz AC frequency coming out of your wall socket.

Here's a rough outline of how the Arduino code works to the best of our understanding:

Setup:

1. It sets up the Serial communication port to communicate at 115200 baud

(Serial communication works by sending one byte at a time between the computer and the Arduino at a certain number of symbols per second, or baud.  115200 baud is currently the fastest possible communication rate between the computer and the Arduino.)

2. The Arduino then sets every pin to ground (LOW).  This is to prevent fields from other pins from potentially affecting the wires going into the Arduino in some sort of an antenna effect.  It then initializes pins 8,9 and 10 to INPUT (remember pin 8 is connected to the left plate, pin 9 is connected to the bottom plate and pin 10 is connected to the right plate).  At this time, all of the plates will be charged to 5 volts through the 270 kOhm resistors.

Loop:
3.  The code calls the function "time" for pin 8 (left plate), which first sets pin 8 to OUTPUT and sets the voltage on the pin to a (digital) low (which is close but not necessarily equal to 0V).  This will very quickly discharge the plates through the 10k resistors.  

Sometime during or after this discharge process, the Arduino will set pin 8 to INPUT.  At this point, it will start counting upwards, once every clock cycle, until the plate has charged up enough through the 270 kOhm resistors that the Arduino sees the voltage at pin 8 has gone back to (digital) high (which is close but not necessarily equal to 5V).

Then the Arduino will stop counting, and report the number over the Serial cable to the computer.  Then the computer, using the Processing sketch, figures out based on this number where your fist is located relative to the left plate.

This same process now repeats for the bottom and right plates.  All of this happens in a fraction of a second, repeated over and over.

In this way, the Arduino constantly reads the position of your hand!













Step 6: Using the Controller and Hacking the Code

When running the Arduino code, make sure to have your computer plugged into the wall and the Serial cable attached to the Arduino.  This is to ensure that the Arduino's ground is the Earth's ground rather than a "floating" ground.

Open the Arduino code in its environment, and load it on to the Arduino.  Then open the Processing sketch in its environment and click the play button.  A screen that looks like the first image should pop up, with the ball moving to the top corner, closest to you.

Now place your fist in the top corner, with your arm pointing towards the far bottom corner (where the 3 pieces of cardboard intersect.)

Click the left mouse button, and hold it down.  Slowly move your fist towards the far bottom corner.  When you have reached there, let go of the button.

Now the Processing sketch knows what your range of motion is, and the range of charging times it can expect for each plate.  You can now play around and see the ball follow your hand!  

This tracking will not be perfect, especially towards the edges of the cube (probably due to fringe fields from the capacitor.)  However, by working with shielded wire, making sure that nothing is in electrical contact, and selecting a good value for the size of the plates and for the resistors, you should be able to improve the response of the sensor.  Experiment with this!  We tried a few plate sizes and settled on 8 inches square, but the way we did it was far from quantitative.  We also didn't have time to try other resistor values.  Remember, the higher the value of the resistor, the slower the charge or discharge time.  We are not sure how this will affect the accuracy of the readings, although my first guess would be that longer discharge times would lead to a more accurate but slower to respond measurement.

Hacking the code:

The real fun of having this 3D sensor is how you can adapt it to control all sorts of devices.  The most straightforward applications would be to control something that simply involved switching various circuits on when your hand is in a certain position, and off when your hand is in another.

In the Processing sketch, the variables that tell you the coordinates of your hand are called axyz[0].avg, axyz[1].avg and axyz[2].avg (sd is just a scaling factor.)

You can print out the values of these variables by adding print statements right after where the variables are first seen, such as:  print(axyz[0]);

By printing out the values of these variables, you can figure out which numbers correspond to which locations in the cube.  

Then you can use these coordinates to your advantage!  For example, you can write an if statement in the Processing Sketch that tells the Arduino where your fist is such as:

if (axyz[0] < 0.1 && axyz[1] > 0.9 && axyz[2] < 0.1) {
  serial.write(1)
// this code snippet should tell the Arduino over Serial that your fist is in the back corner
// note that the code has already initialized the Serial port to be called "serial" on line 4
}

Then in the Arduino code, you can write an if statement that says "if my fist is in this location, set digital pin 5 to HIGH"
Above
void setup()  
write the statement:  
int incomingByte = 0;   // declares a variable to store the incoming Serial byte

Then in the loop, write

// send data only when you receive data:
        if (Serial.available() > 0) {
                // read the incoming byte:
                incomingByte = Serial.read();
        if (incomingByte == 1){
        digitalWrite(5, HIGH);
        }

Now play around with the device you want to control!  Take it apart and see what you need to do, circuit wise, to drive it.  You now have the flexibility to use the location of your hand to tell your Arduino what to do with if statements.  Use it for good or for evil.

Step 7: Helicopter

We decided to try and hack a relatively cheap remote controlled helicopter.

The helicopter keeps in the air by spinning its rotors at a certain frequency, which you can adjust to make it go higher or lower by pushing on a joystick.  But who wants to push on a joystick when you can use the Force?

So we took apart the remote control (picture 3) and found that the joystick that controls the up - down motion is really just sliding a metal circuit connector over these pads.  The higher up the circuit you complete, the faster the rotors go.  

The long metal strip that looks like a backwards L is ground.  We covered it up with electrical tape in order to avoid spilling solder on it (probably not the best practice, but it worked in a pinch.)

We then saw that the default for the helicopter was to spin its rotors at a low frequency (not enough to keep it up in the air).  The part that the green wire is connected to is the pad that makes the rotors stop spinning completely.  

We experimented with grounding various pads until we could figure out which ones would make the helicopter behave in various ways.  We found that the pads on the right, going up seem to be the essential ones to ground to make the rotors spin faster and faster.  So we soldered some wires to those pads (not pictured - they were later unsoldered.)  

The black wire is connected to the ground of the batteries in the remote control.  We were going to connect this to the Arduino ground so that there was a common ground between the remote control and the Arduino.  This way, the Arduino would be able to write LOW to a digital pin, which would be connected to a pad through a soldered wire, and complete various circuits depending on the location of a fist in the sensor.  

Unfortunately, in the course of our experimentation, just as we figured out how to use Serial to send the location of a hand to the Arduino, we think that we short circuited something or burned something out in the circuitboard.  Since it's printed and not very accessible, we were not able to figure out what went wrong (first the board thought that the helicopter was charging when it was not, and then it refused to turn on.)  Even though we weren't ultimately successful in completing our project, we're pretty sure that if we had another remote controlled helicopter to play with, we would be able to make it work in this way (with a little more debugging and a little more careful soldering of course).  

In hindsight, a better first start would probably have been a remote controlled car.  The simplest ones just involve on - off switches to determine whether the car goes forward (yes or no - on or off), backward, left and right.  This seems easily programmable using a 3D capacitive controller, even with not the best spacial resolution!  

Have fun coming up with your own ideas about what to do with this controller, and happy hacking!