Lot many times, We talk of Gyroscope , Accelerometer and Magnetometer in Smartphones, but most of us may not be aware of the Basic Difference between the Three sensors. The reason being all the sensors are related to Position and Orientation of the Device. Though similar in purpose, they measure different things. But combined together in a single device, they can create a very powerful array of information.
Each of the common sensor types: accelerometer, gyro, magnetometer and GPS have some overlap, but different characteristics.
What is a Gyroscope ?
Gyroscopes in consumer electronics sense angular velocity (angular rate) along one rotational axis. These does not give you the absolute orientation as they are (they give you velocity, or rate, not the actual degree). In order to obtain the orientation from these sensors, you need to “integrate” the rate values from a known initial orientation. Gyroscopes are usually tri-axial as well, making 6-degrees-of-freedom “inertial measurement unit” with 3-axis accelerometers.
What is Accelerometer ?
Accelerometers measure physical acceleration relative to the free-fall along one dimension. An accelerometer equipped in mobile devices is usually a tri-axial accelerometer unit, in which three linear accelerometers are aligned in x,y,z axis respectively and each measures acceleration along its dimension. Because we know the vertical component of the acceleration value of a stationary object must be 1-g (9.8m/s^2), we can compute the tilt angle of the unit (hence the object to which the unit is attached) by simple trigonometry.
Detecting portrait/landscape mode in smartphones is done in this way. On the other hand, you cannot know lateral orientation (“yaw”) from accelerometers only because we only have the vertical reference (gravity direction) but not horizontal reference.
What is Magnetometer ?
Magnetometers are simply a compass. A linear magnetometer measures direction and strength of magnetic field along one dimension. In the absence of external disturbance, it can be used to detect earth magnetic field, which always points to (magnetic) north. For magnetometers, this “reference” also contains horizontal component (“north”), from which you can read off lateral orientation of the device, unlike accelerometers. However, the earth magnetic field is very weak compared to common disturbances around (steel furniture, car passing by, etc), so not quite an accurate source of yaw orientation.