IMU Sensors: How They Work, Which Chips to Choose, and How to Use Them

An IMU (inertial measurement unit) measures motion and rotation. It is commonly used to estimate tilt, detect movement, stabilize a robot, or recognize gestures.

What does an IMU measure?

A typical 6-axis IMU combines:

  • 3-axis accelerometer: acceleration along X, Y, and Z, usually reported in m/s² or g. It also senses gravity: when stationary, the acceleration vector is about 9.81 m/s² in magnitude.
  • 3-axis gyroscope: angular velocity around X, Y, and Z, usually in rad/s or degrees per second (°/s). It measures how quickly the device rotates—not its absolute angle.

A 9-axis setup adds a 3-axis magnetometer, which measures the surrounding magnetic field. It can help estimate heading, but motors, steel, and magnets can distort it.

Sensors report measurements, not perfect position or orientation. Integrating gyroscope readings estimates rotation but drifts over time; double-integrating acceleration to get position drifts even faster. Sensor fusion combines measurements to reduce some errors.

ChipSensorsGood to know
Bosch BMI2706-axisLow-power motion sensing, with built-in activity and gesture features.
ST LSM6DSOX6-axisIncludes embedded motion-processing features and a machine-learning core.
TDK InvenSense ICM-42688-P6-axisA low-noise option with configurable measurement ranges and motion features.
InvenSense MPU-60506-axisCommon on learning and hobby boards, with many example libraries; check supply and lifecycle before choosing it for a new product.

These are not interchangeable drop-ins. Compare range, noise, power, data rate, interface, package, driver support, and long-term availability. Many boards connect over I²C; SPI is also common and can provide higher throughput. A breakout board’s voltage compatibility depends on that board, not just the sensor chip.

When and why use one?

IMUs are useful when a device needs to sense movement or orientation without relying on an external camera or fixed reference:

  • A robot estimates tilt or detects a fall.
  • A handheld device detects shake, rotation, or gestures.
  • A drone or gimbal estimates angular motion for stabilization.
  • A machine monitors vibration or counts movement cycles.
  • A wearable estimates steps or activity.

Use an IMU when motion data is relevant to the feature. Do not rely on an IMU alone for accurate long-term position or heading: use suitable additional references, such as wheel encoders, GNSS, vision, or a calibrated magnetometer, depending on the application.

A practical Arduino example

This example uses an MPU-6050 breakout and the Adafruit_MPU6050 library, available from Arduino Library Manager. It averages stationary gyroscope readings to estimate zero-rate bias, then combines accelerometer and gyro readings for a basic roll estimate.

#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <math.h>

Adafruit_MPU6050 imu;
float gyroBiasX = 0.0f; // rad/s
float roll = 0.0f;      // radians
uint32_t previousUs;

void calibrateGyro() {
  sensors_event_t accel, gyro, temp;
  constexpr int samples = 500;

  Serial.println("Keep the IMU still...");
  for (int i = 0; i < samples; ++i) {
    imu.getEvent(&accel, &gyro, &temp);
    gyroBiasX += gyro.gyro.x;
    delay(2);
  }
  gyroBiasX /= samples;
}

void setup() {
  Serial.begin(115200);
  if (!imu.begin()) {
    Serial.println("Could not find MPU-6050");
    while (true) delay(100);
  }

  imu.setAccelerometerRange(MPU6050_RANGE_4_G);
  imu.setGyroRange(MPU6050_RANGE_500_DEG);
  calibrateGyro();
  previousUs = micros();
}

void loop() {
  sensors_event_t accel, gyro, temp;
  imu.getEvent(&accel, &gyro, &temp);

  uint32_t now = micros();
  float dt = (now - previousUs) * 1e-6f;
  previousUs = now;

  float rollFromAccel = atan2f(accel.acceleration.y,
                               accel.acceleration.z);
  float gyroRateX = gyro.gyro.x - gyroBiasX;

  // Simple complementary filter; tune the weight for your sample rate.
  roll = 0.98f * (roll + gyroRateX * dt) +
         0.02f * rollFromAccel;

  Serial.print("Roll (deg): ");
  Serial.println(roll * 180.0f / PI);
  delay(10);
}

The Adafruit library reports acceleration in m/s² and angular velocity in rad/s. This filter is a teaching example, not a production attitude estimator: the accelerometer’s tilt estimate is disturbed by strong linear acceleration, and the filter constants need tuning. Axis signs also depend on how the sensor is mounted. Other IMUs need their own driver or library, but the basic steps are the same: configure, read, apply calibration, then interpret the values.

Calibration that makes a difference

Calibration reduces sensor errors; it does not remove every error or make a low-cost IMU survey-grade.

  1. Gyroscope bias: Keep the sensor completely still and average many samples. Subtract that average from future readings. Repeat after significant temperature changes if drift matters.

  2. Accelerometer offset and scale: Place the sensor successively with each axis facing up and down. For one axis, if the measured values are p and n in m/s², estimate:

    offset = (p + n) / 2
    scale  = 2 × 9.80665 / (p - n)
    corrected = (measured - offset) × scale
    

    This basic six-position method does not correct cross-axis misalignment. More demanding applications need a multi-position calibration.

  3. Magnetometer (if present): Rotate the device through many orientations, often in a figure-eight motion. Correct hard-iron offsets and soft-iron distortions, and calibrate away from magnetic interference.

  4. Mounting and axes: Document the sensor’s orientation relative to the product. Map sensor X/Y/Z to the product’s coordinate system before using the readings in control or navigation.

Some chips or libraries provide factory calibration or internal fusion. Check their calibration status and documentation rather than assuming the sensor is calibrated for your assembled product.

Practical design tips

  • Choose a measurement range large enough for expected motion but no larger than necessary; excessive range reduces sensitivity.
  • Set the output data rate to match the application. Higher rates can improve responsiveness but use more power and processing time.
  • Use the sensor’s data-ready interrupt or FIFO when timing and sample loss matter; timestamp samples for filtering.
  • Add filtering for noise, but do not filter so heavily that you hide impacts or delay control response.
  • Test in the real mounting location. Motor vibration, magnetic fields, temperature, and board flex can change readings.
  • Do not use a hobby-grade IMU as the only safety sensor in a safety-critical system.

In short

An IMU provides acceleration and angular velocity; a magnetometer can add a heading reference. It helps embedded systems detect motion and estimate orientation, but readings need correct units, calibration, timing, and often sensor fusion. Start with a supported breakout board, verify the axes and stationary readings, then test the complete device in its real environment.

References