DIY 3D Controller
Intro: 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.
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.
STEP 1: Materials
Tools
- Arduino
- Processing
- Wire cutters
- Soldering iron
- Box cutter
- (3) 270k resistors
- (3) 10k resistors
- Solder
- Wire
- Aluminum foil
- Cardboard
- 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
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.
Don't tape down the entire perimeter, we'll need it later for attaching the alligator clips.
STEP 3: Make the Connectors
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:
We'll make this circuit at the base of each wire.
- 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.
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.
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
- 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).
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:
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.
STEP 8: Variations and Notes
Variations
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).
- 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
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).
276 Comments
fenixbinario 3 years ago
samblam 11 years ago
I just made the 3d controller and im now trying to make it work. Im new to processing so when I tried to 'just drop the folder TicTacToe3D' in the folder I found under sketch->show sketch folder it wasnt opening. so i just dragged the 3 .pde files on the screen and pressed Run.
This gave an error
in line 54: if(parts.length == sensors) {
'Cannot find anythin named "sensors"'
Does anyone know what is the problem and what is the solution?
Thanks,
kylemcdonald 11 years ago
change "sensors" to "sen" and it should run.
samblam 11 years ago
AjayV34 6 years ago
bro when i run the code , one window will open but dosent show anthing
mashcon5 11 years ago
kylemcdonald 11 years ago
AjayV34 6 years ago
bro when i run the code , one window will open but dosent show anthing
royshearer 11 years ago
I have
[0] "/dev/tty.usbmodemfa131"
[1] "/dev/cu.usbmodemfa131"
[2] "/dev/tty.Bluetooth-PDA-Sync"
[3] "/dev/cu.Bluetooth-PDA-Sync"
[4] "/dev/tty.Bluetooth-Modem"
[5] "/dev/cu.Bluetooth-Modem"
from Processing.
I upload to /dev/tty.usbmodemfa131 in Arduino successfully and get good numbers out of the serial monitor there.
When I use a [0] variable for the serial port in Processing however, I get a lot of interference on the serial monitor - not gobbledygook, just weird strings of numbers if varying lengths. I just see the grey cube and nothing else happens.
When I use a [1] variable i get the following error:
RXTX Warning: Removing stale lock file. /var/lock/LK.012.018.043
gnu.io.PortInUseException: Unknown Application
and lots more.
Am I doing anything wrong?
AjayV34 6 years ago
bro when i run the code , one window will open but dosent show anthing
royshearer 11 years ago
royshearer 11 years ago
slickman84 9 years ago
Then I open Processing program and then I open the TicTacToe3D its saying "cannot find anything named sensors.
XYZAidan 9 years ago
Change "sensors" to "sen".
AjayV34 6 years ago
thx bro but when i click to run output window is white did not show anthing
ultra2301 7 years ago
ВсеволодК 7 years ago
I used your code and little bit of schematics for my project of theremin on arduino
Hesgoy 7 years ago
Sir, I have an error " sensors cannot be resolved to a variable" wat to do to clear this error
venkatesh111 7 years ago
sir the link you have provided for the code is not opening. can you plz provide me the code to the mail anantapalivenkatesh01@gmail.com
MdZaheerHasan 7 years ago
The .ino file? If you're not opening with the arduino software have you tried opening with a text editor like Notepad or Wordpad? That should also show you the code.