Instructables
Picture of DIY 3D Controller
Make a 3D interface using an six resistors, aluminum foil, and an Arduino. Take that, Wii.

Update: a much more thorough explanation of this project is available from Make Magazine. It might be easier to follow their instructions, and I think their code is more up to date.

The basic goal here was to make a 3D hand-position sensing system that most people can build, while still preserving some semblance of functionality. To get an idea of possible applications, check out the demo video. If you think you can build one that is simpler and equally accurate, or slightly more complex and more accurate, share in the comments!


DIY 3D Interface: Tic Tac Toe from Kyle McDonald on Vimeo.
 
Remove these adsRemove these ads by Signing Up

Step 1: Materials

Picture of Materials
2690118127_ae3d9c2d2c.jpg

Tools

Materials

  • (3) 270k resistors
  • (3) 10k resistors
  • Solder
  • Wire
  • Aluminum foil
  • Cardboard

Optional:

  • Tape (e.g.: scotch)
  • Shielded wire (e.g.: coaxial cable, ~3')
  • (3) alligator clips
  • 3-pin header
  • Zip-tie
  • Shrink wrap tubing or hot glue

Step 2: Make the Plates

Picture of Make the Plates
2690119259_7d2b82e605.jpg
This sensor will work using simple RC circuits, with each circuit sensing distance in one dimension. I found that the easiest way to arrange three capacitive plates for this purpose is in the corner of a cube. I cut the corner of a cardboard box into an 8.5" cube, and then cut some aluminum foil to fit as slightly smaller squares. Tape on the corners keeps them in place.

Don't tape down the entire perimeter, we'll need it later for attaching the alligator clips.

Step 3: Make the Connectors

Picture of Make the Connectors
2690108359_a18669fff0.jpg
2690109213_1c4245c446.jpg
To connect the Arduino to the plates we need some shielded wire. If the wire isn't shielded, the wires themselves act more obviously as part of the capacitor. Also, I've found that alligator clips make it really easy to connect things to aluminum -- but there are probably plenty of other ways, too.

  • Cut three equal lengths of shielded cable. I chose about 12". The shorter the better. Coaxial cable works, but the lighter/more flexible the better.
  • Strip the last half inch or so to reveal the shielding, and the last quarter inch to reveal the wire.
  • Twist the alligator clips to the wires onto the wires and solder them together.
  • Add some heat shrink tubing or hot glue to keep things together.

Step 4: Make the Circuit

The "circuit" is just two resistors per piece of aluminum. To understand why they're there, it helps to know what we're doing with the Arduino. What we'll do with each pin, sequentially, is:

  • Set the pin to output mode.
  • Write a digital "low" to the pin. This means both sides of the capacitor are grounded and it will discharge.
  • Set the pin to input mode.
  • Count how much time it takes for the capacitor to charge by waiting for the pin to go "high". This depends on the values for the capacitor and the two resistors. Since the resistors are fixed, a change in capacitance will be measurable. The distance from ground (your hand) will be the primary variable contributing to the capacitance.

The 270k resistors provide the voltage to charge the capacitors. The smaller the value, the faster they'll charge. The 10k resistors affect the timing as well, but I don't completely understand their role.

We'll make this circuit at the base of each wire.

  • Solder the 10k resistor to the end of the wire opposite the alligator clip
  • Solder the 270k resistor between the shield and the wire (plate). We'll shield the wire with the same 5 V we use to charge the capacitors

Step 5: Finish and Attach the Connector

Once the 3 connectors are finished, you might want to add heat shrink tubing or hot glue to insulate them from each other, because you'll be soldering the shielding/5 V points together.

For me, it was easiest to solder the two outermost connectors together and then add the third.

Once you've soldered the three connectors, add a fourth wire for supplying the shield/5 V.

Step 6: Connect and Upload Code

Picture of Connect and Upload Code
2690122013_4c08dc04a3.jpg
  • Plug the connector into the Arduino (pins 8, 9 and 10)
  • Snap the alligator clips onto the plates (8:x:left, 9:y:bottom, 10:z:right)
  • Provide power by plugging the fourth wire (my red wire) into the Arduino's 5 V
  • Plug in the Arduino, start up the Arduino environment
  • Upload the code to the board (note: if you are outside North America, you will probably need to change #define mains to 50 instead of 60).
The Arduino code is attached as Interface3D.ino and the Processing code is attached as TicTacToe3D.zip

Step 7: Do Something Cool!

If you look at the serial window in the Arduino environment, you'll notice it's spitting out raw 3D coordinates at 115200 baud, at approximately 10 Hz = 60Hz / (2 full cycles * 3 sensors). The code takes measurements as many times as possible on each sensor over the period of two cycles of the mains power frequency (which is suprisingly stable) in order to cancel out any coupling.

The first thing I did with this was make a simple 3D Tic Tac Toe Interface. If you want to start with a working demo, the code is available here, just drop the folder "TicTacToe3D" in your Processing sketches folder.

Three helpful things that the Tic Tac Toe code demonstrates:

  • Linearizes the raw data. The charge time actually follows a power law relative to distance, so you have to take the square root of one over the time (i.e., distance ~= sqrt(1/time))
  • Normalizes the data. When you start up the sketch, hold the left mouse button down while moving your hand around to define the boundaries of the space you want to work with.
  • Adding "momentum" to the data to smooth out any jitters.

In practice, using this setup with aluminum foil I can get a range of the largest dimension of foil (the biggest piece I've tested is 1.5 square feet).

Step 8: Variations and Notes

Variations


  • Build massive sensors
  • Optimize the resistors and code for things that vibrate quickly, and use it as a pickup/microphone
  • There are probably other tricks for decoupling the system from AC hum (a huge capacitor beteween the plates and the ground?)
  • I've experimented with shielding the plates on the bottom, but it only seems to cause problems
  • Make an RGB or HSB color picker
  • Control video or music parameters; sequence a beat or melody
  • Large, slightly bent surface with multiple plates + a projector = "Minority Report" interface

Notes


The Arduino playground has two articles on capacitive touch sensing (CapSense and CapacitiveSensor). In the end, I went with an inversion of a design I stumbled across in a friend's copy of "Physical Computing" (Sullivan/Igoe) describing how to use RCtime (the circuit had the capacitor and one resistor fixed, and measured the valueof a potentiometer).

The microsecond timing was accomplished using some slightly optimized code from the Arduino forums.

Again: just from starting at tons of theremin schematics I don't completely understand, I'm well aware there are better ways to do capacitive distance sensing, but I wanted to make something as simple as possible that's still functional. If you have an equally simple and functional design, post it in the comments!

Thanks to Dane Kouttron for tolerating all my basic electronics questions and helping me understand how a simple heterodyne theremin circuit works (originally, I was going to use these -- and, if tuned correctly, it would probably be more accurate).
1-40 of 248Next »
JenniferG21 month ago

I followed the Make instructions that used 220K resistors and if I watch the Serial Monitor, all I get are 0 0 0. Is anyone else having this problem? I'm not sure if the resistors are the problem or something else.

i'm still unsure what this is, can some one explain please?

DangerousTim3 months ago

why don't you use the capsense library? It's quite good, and you'll need only one resistor per foil...

returner4 months ago

guys i m really new to this stuff and i want to learn on how to do this... i have no idea why i cant run this program??? my tic tac toe prog shows me that its not responding every time.. help please?!

thanks in advance.

returner returner4 months ago

i changed my serial port to 0, "int serialPort =0;" , and sensor to sen and i still cant get it to run. help anyone?

anandsd5 months ago

sir can u pls send me the tit tac toe code to this email: anandchidambaram2007@yahoo.co.in

i have made the senser cube and finished the connection but i dont have the program.

XYZAidan5 months ago

When I run the processing program, the window is brought up. It has the cubes and the sphere, but the sphere is in the upper back cube, and my hand doesn't affect it, even if I calibrate. Anyone have a solution?

rgreen10 XYZAidan5 months ago

Did you ever get it figured out? I am having the same problem.

Ramzeez1009 months ago

Hi, I realize this comment may be a bit late, but I'm a bit new to Arduino and I was trying to get this to work. I'm using an Arduino Uno, which Make Magazine used, and I fixed the processing code and got everything uploaded and running. When I run the TicTacToe3D program from processing I am able to see the grey cubes and the red ball, but when I place my hand in while left click holding the window, nothing happens except for the program saying "defining boundaries". Any help?

mwezel Ramzeez1007 months ago

look to the video

rgreen10 mwezel5 months ago

If their problem is the same as mine, the video's instructions do not work. The "defining boundaries" message shows up, yet the ball never moves.

slickman846 months ago

Then I open Processing program and then I open the TicTacToe3D its saying "cannot find anything named sensors.

Change "sensors" to "sen".

kovacp17 months ago

The 'code is available here' link above is broken,

Is the code available anywhere and tare there instructions for compiling it?

Thank you

kovacp17 months ago

What is the application code written in?

I use visual studio - has anyone made an app for that.

Thank you

akumama9 months ago

Hey Kyle, this is amazing, I first saw it on MAKE but have been meddling with it myself for some time now. I have got it working to an extent, but when I run it in processing, once I've clicked to get it to follow my hand, the ball just floats around one area. Do you know why this might be?

fanak1 year ago
An interesting application would be to make this as a controller for a mechanical arm
vvieira2 fanak9 months ago

In progress...
But the sensors still not working with me :/

arm.jpg
theamateur10 months ago

probably the coolest instructable i have seen to this day.

rami201311 months ago
Hi all,
I’m testing this with just one panel and using the test program (_3DInterface)
if I’m shorting pin 8+9+10 it’s working but reports three outputs,I would like just one output and that pins 9 and 10 (on the arduino) will be disconnected.
tried changing line for(inti=8;i<11;i++) pinmode(i,input), to for(inti=8;i<9;i++) pinmode(i,input)
but it didn't work, each time i remove the short line between pins 8+9+10 the output stops.

Please advise
rami
bugmeidareyou11 months ago
Hi all,
I’m testing this with just one panel and using the test program (_3DInterface)
if I’m shorting pin 8+9+10 it’s working but reports three outputs,I would like just one output and that pins 9 and 10 (on the arduino) will be disconnected.
tried changing line for(inti=8;i<11;i++) pinmode(i,input), to for(inti=8;i<9;i++) pinmode(i,input)
but it didn't work, each time i remove the short line between pins 8+9+10 the output stops.

Please advise
rami
AVNERD19911 months ago
Is there any way i could make a bunch of small ones and put them in a pattern to make a touchless keyboard?
fmmehr1 year ago
hey thanks for your great project the only thing is i can't make the tictactoe3d working on processing app it gives me errors and it can't export the application can you please help me or can u send me the ready made tt3d app to instal or right code thank you
my email is farbod_mjl@yahoo.com
mindlelle1 year ago
Hi, I have done everything and I see TicTacToe3D screen with boxes and orange ball. but the problem is that the ball doesn't move at all. It doesn't react. Any advice? What could be a problem? Help me~
allready tried to calibrate it? and did you use shielded wire, or else your body may act as a capacator.

Hope it helps!
how do you calibrate it? i have the same not-moving ball
MaC Malik1 year ago
Completed with :
--------------------------------------------------
Arduino : UNO [haven't tested this with Leonardo yet]

Processing version : 1.5.1 [as a must ,
because there is a part of the code is not compatible with the newer versions , maybe if you can replace it something is ok with for newers , then newers is ok ;) ]
________________________
I done it without shielded wires , but because the wires are not shielded , a capacitance between the wires and my body is created (same as between my hand and the plates) which is already mentioned earlier by Kyle, and that will disturb the readings and make controlling the ball a little harder ( I have to keep my body away from the wires) and from there the importance of shielding is shown up (beside stopping the antenna effect as well) ;).
MaC Malik1 year ago
UPDATE:::

I have some how solved the problem and I a sure with the solution with only 38% (since I don't really know what EXACTLY was wrong with it).

What I did is
[/\]Opening the serial port and check the values coming out of Arduino
[/\]and as mentioned in the previous comment, I had only one number coming out then stops sending numbers.

[/\]then I Removed all the connections from the Arduino pins while watching the serial monitor.

[/\]Nothing changed yet , but when I tried putting a wire (one of the wires that should be connect to the Arduino I/O pins in this instructable :8,9 and 10) on one of the three pins (8,9 and 10) and then take it off fast and doing the same with same wire with the other pins , in and out , in and out .

[/\]Then I FINALLY Saw the Numbers coming out of Arduino to the Serial (maaaan , how I was happy back then) after that,when I ran processing, the ball started responding and moving(finally).

I know it might seem as if I am telling a story , but here is what I did so you can get clue to fix your situation with (My opinion is that maybe the three pins were some sort of "stuck" at the beginning).

Best of Luck :) .
MaC Malik1 year ago
I did not solve the problem yet,However,

To all of you who has the "Not Moving Ball" problem , I know the starting point of the debugging :
I checked the Arduino's "Serial Monitor" and I found that Arduino does send NOTHING in the serial line ( except for a number that shows up one time at the beginning)

And thats WHY (I Assume with 99%) the ball in processing Does Not Move.

So all of you (including me =3 ) start debugging from there.
GoodLuck ;).
schmitta1 year ago
The shielded cable/ center conductor is the capacitor. The foil just takes away current from the shield capacitor. The hand forms a capacitor with the body being ground and current flows from the foil to the hand electrostatically robbing current from the shield capacitor's center conductor. The center conductor is first grounded through the 10k resistor when the logic zero is written to that port. Then when the port is made an input it is at a high impedance (cmos) and little current flows through the 10k to the port. The shield is at 5 volts. The center conductor of the shielded cable is at ground and charges through the 270k resistor until it reaches 2/3 of Vcc. Then a logic 1 is triggered. The foil is passing current to the hand and robbing current from the center conductor causing a longer time until the 2/3 Vcc is reached. The closer the hand is to the foil the higher the capacitance value of the hand/foil capacitor and the more current is robbed from the charging center conductor extending the charge time of the center conductor. Alvin....
NehadTabl1 year ago
Hi Kylem!!

I did everything, but the box is not moving. what’s the problem??
Can you help me please??
I made 220K ohm by two 100k series with two 10k ( behind each other) … do you think this is the problem?
Hi,
I'm trying to make this work, and it isn't working.
I loaded the code to arduino, and i load the processing code and run it, and all i get is a blank white screen. Please tell me what im doing wrong!
Newermore1 year ago
Hi kylemcdonald. Firstly I want to say how much this project interests me, so I want to make it by myself and use it as a school project to show possibilities of Arduino. But I'm not so good at programming and do not understand whole program, that you have made for the Arduino. Can you please e-mail me to kasanickyfilip@gmail.com what program does step by step? I will be very grateful.

#define resolution 8
#define mains 50 // 60: north america, japan; 50: most other places

#define refresh 2 * 1000000 / mains

void setup() {
Serial.begin(115200);

// unused pins are fairly insignificant,
// but pulled low to reduce unknown variables
for(int i = 2; i < 14; i++) {
pinMode(i, OUTPUT);
digitalWrite(i, LOW);
}

for(int i = 8; i < 11; i++)
pinMode(i, INPUT);

startTimer();
}

void loop() {
Serial.print(time(8, B00000001), DEC);
Serial.print(" ");
Serial.print(time(9, B00000010), DEC);
Serial.print(" ");
Serial.println(time(10, B00000100), DEC);

}

long time(int pin, byte mask) {
unsigned long count = 0, total = 0;
while(checkTimer() < refresh) {
// pinMode is about 6 times slower than assigning
// DDRB directly, but that pause is important
pinMode(pin, OUTPUT);
PORTB = 0;
pinMode(pin, INPUT);
while((PINB & mask) == 0)
count++;
total++;
}
startTimer();
return (count << resolution) / total;
}

extern volatile unsigned long timer0_overflow_count;

void startTimer() {
timer0_overflow_count = 0;
TCNT0 = 0;
}

unsigned long checkTimer() {
return ((timer0_overflow_count << 8) + TCNT0) << 2;
}

cantona1 year ago
Any ideas on how to make this emulate a mouse using the Arduino leonardo ?
Great
Hey I believe I've done everything in the instructions right. I built it all correct, there's no shorts. I've uploaded the _3DInterface into the Arduino. When i try to use the TicTacToe it only comes up with a whit screen and an error (ArrayIndexOutOfBoundsException: 1). It highlights a part of the script
serial = new Serial(this, Serial.list()[serialPort], 115200);
Please help =) thank you!!
Hahaha yes i got it to work, i had to change there serial number at the top to zero. since my arduino is in com 5
Exception in thread "Animation Thread" java.lang.ArrayIndexOutOfBoundsException: 1
at TicTacToe3D.setup(TicTacToe3D.java:57)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:662)
this is what it said at the bottom of the processing
TomB221 year ago
Hi
I installed processing and arduino software. I upload sketch to arduino and copied Tic Tac Toe 3D to sketch folder in processing. I'm running processing and I can see window with dimensions of 7x7cm, however I don't see any any points inside the square and I'm not sure how to initialize it. Could you pls help me out? Am I missing something? Thanks a lot for any help!
i only get a white screen nothing shows up, i get stuff through the serial port though
1-40 of 248Next »