Home > Projects > Sensor – Transducer – Detector Projects > Sensing Orientation With The ADXL335 + Arduino

Sensing Orientation With The ADXL335 + Arduino

Summary of Sensing Orientation With The ADXL335 + Arduino


This article explains how to use the ADXL335 analog 3-axis accelerometer with an Arduino to sense simple orientation by measuring gravity's effect on internal springs. It clarifies that while a single axis detects only 180 degrees, combining axes using the Atan2 function allows for full rotation tracking in two dimensions. The text notes that accelerometers cannot measure yaw (rotation around the vertical axis) and suggests using a gyro or digital compass for that purpose.

Parts used in the ADXL335 + Arduino Orientation Project:

  • ADXL335 Accelerometer
  • Arduino Board
  • Analog 3-axis Accelerometer

I know, I know, this one has such a simple name. Where’s the pun? Honestly, the description was just to long to include one. Maybe it could have been “What’s Up? Sensing Orientation With The ADXL335 + Arduino” – Ehhh… Probably not.Sensing Orientation With The ADXL335 + Arduino

A few weeks ago we wrote a tutorial about using the ADXL345 to sense taps, and drops, but this week we are going to wind it back, go back to basics, and show you how to take an analog 3-axis accelerometer and use it to sense simple orientation with it, specifically the ADXL335, but this can be applied to any analog 3-axis accelerometer.

Before we really dive into it, we need a general understanding of how accelerometers work, so if you already know why each axis can only differentiate 180deg of movement, you can skip this. Wraning: Over-simplification ahead. In the last article I described an accelerometer as a device that sensed movement. Today, think of them as devices that sense gravity.

Basic Understanding Of Accelerometers

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).Schematic Sensing Orientation With The ADXL335 + Arduino

No Love For Yaw

Yaw is name for rotation around an axis that is similar to spinning a top, or shaking your head “no.” Accelerometers can’t measure this type of motion. Why? Well think about the box. If you turn the box in this manner, non of the sides change their orientation to the ground. If you need to measure yaw, you will need to incorporate a gyro or digital compass into your project, but it gets tricky, and is beyond the scope of this article.

For more detail: Sensing Orientation With The ADXL335 + Arduino

Quick Solutions to Questions related to ADXL335 + Arduino Orientation Project:

  • What is the primary function of an accelerometer when standing still?
    When standing still, the accelerometer senses acceleration caused by gravity.
  • How many degrees of movement can a single accelerometer axis differentiate?
    A single axis can only differentiate 180 degrees of movement.
  • How can you calculate rotation values between -180 and 180 degrees?
    You can combine Y and Z values using a trigonometry function called Atan2.
  • Can an accelerometer measure yaw motion?
    No, accelerometers cannot measure yaw because turning the box does not change side orientations relative to the ground.
  • What components are needed if you need to measure yaw?
    You will need to incorporate a gyro or digital compass into your project.
  • Does this tutorial apply only to the ADXL335 sensor?
    No, the method can be applied to any analog 3-axis accelerometer.
  • What happens to the sensor reading when rotated 90 degrees from the top position?
    The sensor sees it feels 0.5g when rotated 90 degrees from the top.

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter
Scroll to Top