When to use accelerometer or gyroscope on Android

user2892857 picture user2892857 · Dec 20, 2013 · Viewed 33.3k times · Source

Is it ok to assume most of the user devices will have a gyroscope? In other words will I be excluding a significant number of people by using a gyroscope in my app?

I'm making a children's storybook app and I'm wanting the user to be able to tilt their device around the yaw axis to move a rocking chair back and forth. It's a small part of the app and it doesn't have to be very precise. Is there one sensor I should use over the other?

Answer

foibs picture foibs · Dec 20, 2013

User coverage:

Most devices have both gyroscope and accelerometer, but almost every device has an accelerometer. Especially the older devices and the cheaper ones do not have a gyroscope. Don't forget that since it is a kids app, maybe the parents don't want the little ones to use their superb 700$ tablet, and will probably use cheaper ones. Cheaper devices tend to not have gyroscopes. So +1 for the accelerometer.

User experience

The accelerometer measures acceleration in the 3-dimensional coordinate system. In most cases (when the user actually does not jump around or throw the device) the biggest part of acceleration is gravity. With gravity alone it is very easy to determine tilt and slight movements. Plus you have the Gravity software sensor to eliminate strange movements, and Linear Acceleration to eliminate Gravity. The Gyroscope detects rotation. It is more sensitive, more precise and produces events faster than the accelerometer, but it seems to be an overkill for this usecase. If you wanted to make a 3D racing game or a flight simulator It'd be a win for the gyroscope, but for a kids app it's just too much.

Battery Usage

No contest here. The gyroscope uses 3-30 times more battery (maybe more, depending on device), while the accelerometer is very gentle on the battery. Plus, for most users the accelerometer is already active (to rotate the screen automatically) so there is no sensor battery usage here. +1 for the accelerometer

Programming

Sensors are pretty easy and straightforward to implement in Android apps. Since the gyroscope detects rotation speed, it gives all 0 values if the device is left still (and maybe a little noise in the range of +-0.01rad/s), so you only need a small if block to dismiss very slight movements (e.g. when gyroscope values are less than 0.2 rad/s). With the accelerometer, you need some extra calculations to determine the orientation of the device and which axis is actually the one that needs more attention to determine the direction of movement. It's not hard to do, but it does add a few extra lines of code and some extra debugging to your line of work. +1 for the gyroscope.

Conclusion

For a simple kids app, accelerometer is the way to go. I wouldn't think about it any more. Since you don't care much about precision, you actually eliminate the points gained by the gyroscope.