Warning: Illegal string offset 'hide_thumbnail_on_single' in /home1/husstec1/public_html/wp-content/themes/cudaziluxury/header.php on line 6

Warning: Illegal string offset 'columns' in /home1/husstec1/public_html/wp-content/themes/cudaziluxury/header.php on line 8
Using the Accelerometer – HUSSTECH

Using the Accelerometer

So we can connect the test vehicle and its accelerometer to the PC, now to do something with the data. Accelerometers are devices for measuring the strength of the Earth’s gravitational field in different axes, which means that with some arithmetic you can extract the orientation on the accelerometer and whatever it is attached to. Ever wondered how an iPhone knows when it is turned on its side, well it uses an accelerometer to sense its orientation. I am using the LIS302DL triple-axis accelerometer; there is a tutorial on how to use it here.

Measuring tilt angle

Taken from: Tilt Sensing Using Linear Accelerometers by: Kimberly Tuck

“Measuring Tilt using a Three Axis Solution
In order to define the angles of the accelerometer in three dimensions the pitch, roll and theta are sensed using all three outputs of the accelerometer. Pitch (rho) is defined as the angle of the X-axis relative to ground. Roll (phi) is defined as the angle of the Y-axis relative to the ground. Theta is the angle of the Z axis relative to gravity.”

Calculating the angles

Once the equations were established for calculating the orientation I could extract the angles and display the result. I wanted to show the orientation being tracked in real time with a simple intuitive animation. I chose a basic artificial horizon type animated display; it’s simple and clear to understand.

The raw measurements from the accelerometer were already being inputted into MATLAB; all that was needed was some more code to initialise the figure and to update the figure each time new data was received. I took the roll angle value and used that to alter the “angle of bank” on the figure. The pitch angle is also available but that data is not used in this demo.


All the movements I am making need to be reasonably slow, this is because an accelerometer can also sense dynamic acceleration. Image that an accelerometer is held perfectly flat, but it is accelerating in a straight line, the accelerometer will detect the dynamic acceleration and will give a false reading of its orientation. At this point you need to bring in other sensors taking other measurements and fuse the data together to get a more accurate picture.

Usually gyros are used with accelerometers; gyros are devices which measure the angular velocity about an axis. The gyro will read non zero during a rotation and will be zero once it stops rotating, you can then obtain a value for the angle by integrating the angular velocity over time. However gyros have “drift” which is that they are constantly accumulating errors, so eventually you have no idea which way you are pointing. This is where you use the accelerometer to correct the gyro drift, but we know that the accelerometer can be corrupted by sensing dynamic acceleration too…. So for that reason the average value from the accelerometer over a period of time is used to correct the gyros.

  • Why we need accelerometers and gyros.