DIY 3D Tilt Sensor

by tamberg in Circuits > Sensors

16743 Views, 160 Favorites, 0 Comments

DIY 3D Tilt Sensor

13962099175_47b443d332_z (2).jpg

How to build a DIY 3D tilt sensor Bluetooth HID controller

Fun, educational to build, and a bit like magic. Check this video of the DIY 3D tilt sensor hooked up to Philips Hue. The project is designed to be made in a FabLab (Zürich represent!) with a laser cutter, a 3D printer and a soldering iron. Because the project is based on Adafruit's Bluefruit EZ-Key, no programming is required.

Cheers, @tamberg

Video

https://www.flickr.com/photos/tamberg/13939001466/ (switching animated GIFs)

https://www.flickr.com/photos/tamberg/14034330334/ (controlling the Philips Hue connected light bulb)

Material

- PLA in 6 colours
- gray acrylic, 3mm
- 24 copper nails, 2.5 x 25 (e.g. on eBay)
- 1 aluminium ball, 20mm diameter (e.g. on eBay)
- 10 jumper wires, F-F (e.g. http://www.adafruit.com/products/266)
- some hookup wire (e.g. http://www.adafruit.com/products/290)
- 1 3.7 V LiPo battery (e.g. http://www.adafruit.com/products/1578)
- 1 LiPo charger (e.g. http://www.adafruit.com/products/1304)
- 1 Bluefruit EZ-Key module (http://www.adafruit.com/products/1535)
- a used 1" bike inner tube to make DIY rubber bands

Tools

- 3D printer
- Laser cutter
- Soldering iron
- Heat sink (e.g. a clamp)
- Pliers and a wire stripper

Idea, Prototyping and Iterations

13188585635_52de96b588_z.jpg
13386270185_caeaf625e1_z (1).jpg
13392732963_974a18619e_z.jpg
13892113925_2dd4fdbfc3_z.jpg
13949807655_aea89f250e_z.jpg

(This step documents the development process and can be skipped.)

Idea

The goal was to build a cube that is aware of its orientation in space (or at least which side points up), without using an accelerometer.

Standard 1D tilt sensors are not much more than a ball in a tube, so I thought this could be generalised to three dimensions. Note that using three 1D sensors would probably not work, as many orientations would leave some of the switches in an undefined floating state.

So the idea was to force a single ball to the side of the cube pointing down. As in the 1D case gravity is your friend here. All you need is an inner chamber holding the ball, with one vertex per side of the cube.

Prototyping

To test the idea a quick "cut-away" cardboard prototype was built. This seemed to work as intended, so I started designing the cube in Sketchup. Only then I realised that the inner chamber is not a cube, but an octahedron.

To test the switch (made from nails) an improvised aluminium ball was used with an LED and a battery.

Iterations

It's often hard to get everything right in the first try.

In this case it turned out that the size chosen for the cube and chamber did not allow enough space for the electronics. Also, the thick acrylic took too long to laser-cut. An additional iteration was needed to add small cuts for the rubber bands holding everything together. The solution is simple: iterate until it works.

Laser Cutting the Cube and the Octahedron

14530217271_f3502f4bc3_z.jpg

Download the design files from http://www.thingiverse.com/thing:306251 and cut the cube and octahedron from 3mm acrylic.

3DTiltSensorLaserPartsCube.pdf and 3DTiltSensorLaserPartsOctahedron.pdf should work fine on an Epilog laser cutter.

3D Printing the Adapter Plugs

14532133574_be1c472730_z.jpg

Use the files 3DTileSensorPlug.stl and 3DTileSensorPlugSmall.stl from the previous download.

Print two of the big plugs, and four of the small ones. Ideally, each plug should have a different color. As an alternative you could also use a single color and add "engraved" letters or symbols to the surface that will end up on the cube's face.

(The design of the adapter plugs might look a bit complicated. However, they've been quite easy to draw in Sketchup by intersecting a cylinder with the cube and octahedron, then selecting the part that makes up the plug.)

Assembling the Ball Chamber

13958928142_d36e3e2f0e_z.jpg
14532731601_ddaa97b5ae_z.jpg
13982093433_c0415de9d1_z.jpg

No glue needed

(The hot glue shown here is not needed, if wiring is done right later on. Also, just ignore the wires and solder in the second picture for now.)

Add the octahedron-triangles to the bigger adapter plug using nails. They should fit tight.

Recycled material

Then, cut some rubber rings (24 in total) off the used bike tube, 5mm wide each, and pierce them to fix additional nails in the remaining holes.

Repeat this with the second half of the chamber...

Soldering Wires to the Chamber

13962568144_33a724d025_z.jpg
14539924921_21747daf7d_z.jpg
13962119335_73f97e7894_z.jpg
13962561024_cf9ec1bff6_z.jpg
13939012766_919c78de1f_z.jpg

Nails and ball switch

For the nails to work as a switch (together with the ball) we have to connect two wires to each vertex. As there are four nails per vertex, additional wire is needed to connect the two adjacent nails together (to prevent bouncing). And because ground is the same for all vertices, we add further wire to connect multiple nails to a common ground.

Preparing wires

First, cut 12 short pieces (3 cm) and 4 longer ones (5 cm) off the hookup wire.

Then you'll need six coloured jumper wires (a - f) and two additional ground wires (GND). To enable soldering them to the nails, cut off the connector at one end.

Soldering with a heat sink

Get something you can use as a heat sink to protect the acrylic / PLA, e.g. an alligator clip. It should be placed between the tip of the soldering iron and the plastic.

The nail's tip absorbs a lot more energy than a thin wire, so make sure it's well heated, otherwise the solder will not stick. And remember not to touch a heated nail on either side, as the head gets very hot, too.

Solder the wires as shown in the diagram (other pictures might be slightly different). The perspective is a top view into the chamber halves.

Assembling the Cube

13962560334_17a1039264_z.jpg
13958927901_85959bdc9d_z.jpg
13962109355_d7e4e4a91d_z.jpg
13982083713_36bff315bc_z (3).jpg
13958925852_eef078f6b2_z (3).jpg

Snap-together assembly

Assemble the cube shell, without the top cover. Use rubber bands to hold everything together.

Now add the lower half of the ball chamber. The printed adapter plug should just fit into the acrylic. The vertices should point to the round holes.

Then snap in the small adapter plugs by gently bending the side panels and making sure the acrylic goes into one half of the little x-shaped printed hole.

Add the aluminium ball, and cover it with the upper half of the ball chamber. The chamber should fit into what's left of the x-shaped holes tight enough to enable a first test of the sensor.

Connecting and Powering the Module

13958924961_1d777450cf_z (1).jpg
13962553864_fc75d62929_z.jpg

Powering the Bluetooth module

To power the module, connect the LiPo battery to the Bluefruit EZ-Key module. Make sure to connect the black wire to GND, the red to VIN. An on / off switch would probably be nice (it could probably even be wired to one side of the cube), and maybe a charging circuit. But for now, let's keep it simple.

Connecting the module

Connect the wires to the Bluefruit EZ-Key. Make sure the black (GND) wires are connected to GND on the module. All other wires (a to f on the previous diagram) can be connected to one of the numbered data pins. Be aware that each data pin is hardcoded to send a key press (see next step).

Closing the cube

Finally, add the cover and attach it with additional rubber bands. This part might be done later on as well, to simplify testing in the next step.

Pairing and Testing the Module

13958933271_b6d63485d8_z.jpg
14541324682_e70476fa08_z.jpg

Pairing the module to your computer

The Bluefruit module acts as a simple Bluetooth HID Keyboard and can be connected to your desktop computer or mobile phone. Adafruit has instructions for Windows, Mac and Linux.

https://learn.adafruit.com/introducing-bluefruit-e... (Windows)

https://learn.adafruit.com/introducing-bluefruit-e... (Linux)

https://learn.adafruit.com/introducing-bluefruit-e... (Mac)

Be aware that once it's wired up to the DIY 3D tilt sensor, the module sends many key press events in rapid succession. It's safer to first focus your test Web page and then power the module. Therefore it might be easier to test a bare bones setup first (see picture), to figure out the basics of the module.

Testing the keys / 3D tilt switch

The cool thing about the Bluefruit EZ-Key is that it's really just a Bluetooth HID device, like a Bluetooth keyboard. By connecting any pin to ground you send a predefined key press.

A great Web page to test the module is http://dmauro.github.io/Keypress/ as it shows each key press event on a soft keyboard. Not the key pressed for each vertex and make sure the same key is pressed each time you turn the cube on the same side.

Mapping keys to cube faces

While the actuated switch is the one on the bottom side of the cube, you might well associate the pressed key with the top side. This helps if you want to match triggered actions to the color facing up.

Switching Animated GIFs

gifs.png
Screen Shot 2014-06-30 at 23.17.14.png
Screen Shot 2014-06-30 at 23.15.56.png

Controlling Javascript running in the browser

It's quite easy to write a program that takes the DIY 3D tilt sensor's input. This example uses Javascript to display a different animated GIF for every key: http://www.tamberg.org/wire/2014/gif/

Debugging with any keyboard

To try it without a cube, visit the link above and press w, a, s, d, 1 or 2 on your keyboard. Use view source in your Web browser to see how it works. Download the source and the GIFs to modify the code and just run it from your desktop. Note how the code debounces multiple key press events.

Going big

Chrome has a presentation mode (select View > Enter Presentation Mode), other browsers probably got one as well. This allows a setup with a beamer for a more immersive experience or to enable projection mapping.

Controlling the Philips Hue

hue.png
red.png
blue.png

A bit like magic

If you happen to have Philips Hue connected lights at your home, here's how to hook them up to the 3D DIY tilt sensor. Here's a video. The Javascript runs in a Web page and uses Web requests to control the light.

Download the source from http://www.tamberg.org/wire/2014/hue and set the HUE_BRIDGE_IP to match your Hue bridge's IP address (for details on the API, please see the official Hue docs at http://developers.meethue.com/ ).

Note that the example only works if you're in the same network. If that's a problem, you might check out this thread (disclosure: I'm a founder of the relay service mentioned there) or configure port forwarding.

Thanks

That's all for now. If you find another application or a clever tweak in the design, please let me know in the comments. Thanks for reading, @tamberg