Saturday, October 15, 2011

How to make a cheap two-axis tilt sensor

I am sure many of you will find this trivial, but since I couldn't see any reference to something similar, I thought I should document it.

This hack allows you to measure tilt with a 90 degrees "accuracy" in a vertical (or I should say "non-horizontal") plan, basically to determine the orientation "up", "down", "left" or "right".

You will need 2 simple tilt switches and 3 resistors, wired as in the schematic below and assembled on a piece of prototyping board as shown in the photo.



















It is important to place the 2 tilt switches as shown, 45 degrees on each side of the "vertical" axis. The little board now becomes the "2D tilt sensor". It is shown connected to the Arduino with 3 wires: Vcc (red), GND (black) and A1 (white-orange). I used axial tilt switches, but radial (as those sold by adafruit) work as well.















The voltage on analog input A1 of Arduino is dependent on the orientation of the 2D tilt sensor. I selected the value of the resistors so that the voltages are spread as much as possible over the 5V range.
Basically, by closing any or both of the switches, unique voltage dividers will be created. By reading the voltage on the analog pin we can easily figure out the orientation of the 2D tilt sensor.

Here are the 4 possible combinations:
  • S1 open, S2 open: A1 = 0V
  • S1 close, S2 open: A1 = 1.6V
  • S1 open, S2 close: A1 = 2.5V
  • S1 close, S2 close: A1 = 3V
As always, comments are appreciated.

No comments:

Post a Comment

Post a Comment