What is the difference between Accelerometer, Gyro, and Magnetometer Sensor?

The Accelerometer measures total acceleration on the vehicle, including the static acceleration from gravity it would experience even when its not moving.

The magnetometer measures the magnetic field around the robot, including the static magnetic field pointing approximately north caused by the earth. Being placed in/around a metal frame or any large motors, diving over/around underground metal pipes or electrical equipment will all make large and noticeable effects on its measurements.

The Gyroscope measures your instantaneous angular momentum around each axis, basically how fast its rotating. Note that angular momentum is not directly compatible with euler angles, but works out similarly for small angles. Very high quality signal in the short term because there isn't much noise, but since your angular position has to be integrated off of the gyroscope, it will build up error.

Gravity is your best reference for angular position, because it doesn't drift like the gyroscope and since your robot is operating in (and causing) a sea of magnetic disturbances, using north is risky. It will not work if you are experiencing a significant acceleration though.

The simplest code would just use the accelerometer for rotations around x and y, the mag for z, and ignore disturbances. The basic idea is "I know gravity is actually down, but its being measured on the accel X axis, so I must be pitched by some amount". The Better sensor fusion algorithms will use the accelerometer/magnetometer to correct for drift in the gyro, but get most of its information about rotational position from the Gyroscope.

Tracking lateral position using a standard 9-dof IMU is not possible. Only the accelerometer measures lateral motion at all, and it needs to be integrated twice to get position. Error builds so fast your position estimate is complete garbage within seconds.

Tracking angular position is possible because all three sensors measure it in one way or another. Angles are tricky though because they are not commutative. If the gyro measures a 90 degree yaw then a 90 degree pitch from north, you are facing down; if it measures a 90 degree pitch and then a 90 degree yaw from north, your facing east turned on your side. Be careful with the math, or download an arduino IMU library that has it taken care of for you.


The main difference is the way they operate and what they sense. In other words, they are all very very different things. Yet they can all measure motion in some way.

  • An accelerometer senses both the gravitational pull of the earth and the inertia / momentum of the motion of the device
  • A magnetometer senses the earth's magnetic field to get a compass heading.
  • A gyroscope senses changes in twist and angle.

They can all give information about motion and attitude, but each has both benefits and drawbacks compared to the others. Some drift more than others, some are slower or lower resolution, etc.

So generally all three are used together to get the benefits of them all and, to some extent, negate the drawbacks of them.

For instance, a gyroscope isn't good at measuring inertia, but it is good at measuring changes in angles. But those changes in angles drift over time and you lose accuracy. A magnetometer is good at giving you an exact angle, but it takes longer to get an accurate result, and it's not good at fine changes in angle. So a magnetometer is used to correct the drift of the gyroscope, and an accelerometer is used to measure inertia.

So to sum up:

  • Accelerometer for changes in speed
  • Gyroscope for changes in angle
  • Magnetometer to correct the gyroscope