Device Motion Sensors

Using device sensors can be very useful, especially in game development. Most of us have played some kind of mobile game that makes use of the device sensors. For example, a very popular type of game is the racing game where you control your vehicle by tilting your device. The concept is very simple, in fact it is so simple, some games achieved planetary succes. The first game that comes to mind is Real Racing. You tilt the device and the vehicle turn right or left accordingly.

Every device is different. Not all devices are going to have sensors for detecting light strength or the gravity acceleration. Most of devices that run Android 2+ have an accelerometer.


An acceleration sensor measures the acceleration applied to the device, including the force of gravity. To make a reference to the device accelerometer you need to do this:

Accelerometer gives you the value of acceleration applied to the device measured in m/s2.



Almost all of these sensors provides you with three values, one of each of the device’s axes. Same is the case with the gyroscope. The gyroscope measures the ratio of rotation is rad/s around all three of the axes. Getting an instance of the gyroscope is very similar to getting an instance of the accelerometer, in fact that is the case with most of the sensors.

Rotation is positive in the counterclockwise direction.

There is also an uncalibrated gyroscope. The difference between the calibrated and the uncalibrated gyroscope is that with the uncalibrated gyroscope no gyro-drift compensation is applied to the rate of rotation.

In general, this function applies:calibrated_x ~= uncalibrated_x - bias_estimate_x.

Note: Uncalibrated sensors provide more raw results and may include some bias, but their measurements contain fewer jumps from corrections applied through calibration. Some applications may prefer these uncalibrated results as smoother and more reliable. For instance, if an application is attempting to conduct its own sensor fusion, introducing calibrations can actually distort results.

And the initialization calls passes Sensor.TYPE_GYROSCOPE_UNCALIBRATED as a parameter to the getDefaultSensor() method.

Linear accelerometer

The linear acceleration sensor provides you with a three-dimensional vector representing acceleration along each device axis, excluding gravity.

linear acceleration = acceleration - acceleration due to gravity

Creating an instance of this sensor is done the same as the other examples in this post, except you pass the Sensor.TYPE_LINEAR_ACCELERATION as the parameter to the getDefaultSensor() method.

Learn more

These are definitely not the only sensors that Android provides you with.