I'm experimenting with a 3 accelerometer breakout board. The X and Y axis are very easy to control, but the Z axis is a bit of a mystery. I'm trying to find a way of interpreting the data in my code to increase output as the device is lifted up in the air, and reduce as it is lowered down. Is this possible? If so, how? Maybe if someone can point me towards a good reference source that would help.
Basic Understanding Of Accelerometers: (Only for some conceptual clarification)
Accelerometers measure acceleration, often caused by motion. But when they are standing still, the only acceleration the accelerometer senses is due to gravity pulling down on it.
Imagine a box that has little springs sticking straight out from the sides of the box, and that the accelerometer measures how hard gravity is stretching out those springs. The springs on the side are all bending the same amount, the spring on the bottom is all stretched out, and the one at the top is not stretched at all (because the spring is pull back into itself), so the accelerometer sees it as feeling no gravity, or 0g (gravity). If you rotate the box 90º and follow the spring on the top. It is now on the side and is hanging down some and the sensor sees it now feels .5g. Rotate 90º again, and it is at the bottom, stretched out, and it feels 1g. Rotate again 90º and we are at the side again, with it feeling .5g, and 90º rotation again, we are back at the top and it feels 0g. So we made a full rotation and the accelerometer saw this: 0g-> .5g -> 1g -> .5g -> 0g.
If you look at this, it means that the accelerometer can really only sense differences in 180º of movement as the other 180deg is just a mirror image. So how can we sense 360 deg of movement?
The trick to this is that while one axis can only sense a 180deg difference, so can the another axis, but they sense it differently. If you look at the chart to the right, you can see the sensed values while rotating round the X Axis. (The x never changes because it is always facing the same direction) – So we can combine the y, and z values to find x using a trigonometry function called Atan2 who then gives us values back as -180º to 180º (but in radians, so it is -π to π and well have to convent it).
If you are interested you should read the full article Sensing Orientation With The ADXL335 + Arduino. You might also get some useful information from the accepted answer of this question if you decide to use gyro along with the accelerometer which is likely what you might end up doing.