Introduction: DIY 3D Tilt Sensor

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

Step 1: Idea, Prototyping and Iterations

(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.

Step 2: Laser Cutting the Cube and the Octahedron

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.

Step 3: 3D Printing the Adapter Plugs

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.)

Step 4: Assembling the Ball Chamber

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...

Step 5: Soldering Wires to the Chamber

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.

Step 6: Assembling the Cube

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.

Step 7: Connecting and Powering the Module

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.

Step 8: Pairing and Testing the Module

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.

Step 9: Switching Animated GIFs

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.

Step 10: Controlling the Philips Hue

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

Comments

author
wilgubeast (author)2014-06-30

I love it when people share DIY sensors. I also have a soft spot for pennies. This is perfect.

You even cleaned it up with an enclosure and everything! 10 stars. Would read again. :D

author
tamberg (author)wilgubeast2014-06-30

Thanks! Glad you like it.

About This Instructable

14,162views

153favorites

License:

More by tamberg:Voodoo Sonic LoRaWAN-connected dollIoT Gauge with Arduino, Yaler & IFTTTLog Arduino output for days with a BeagleBone
Add instructable to: