Electronics Design AU
SensorsEmbedded Systems

What Is an Accelerometer and IMU?

Last updated 27 June 2026 · 8 min read

Direct Answer

An inertial measurement unit (IMU) combines an accelerometer (measures linear acceleration and gravity vector direction) and a gyroscope (measures angular rotation rate) in one package. An accelerometer uses MEMS technology — a microscopic proof mass suspended by springs inside the IC — where deflection under acceleration shifts a differential capacitance that is read by onboard electronics. A gyroscope measures rotation via the Coriolis effect on vibrating MEMS structures. Common embedded IMUs include the MPU-6050 (I2C, 6-axis, low cost) and LSM6DSO (SPI or I2C, 6-axis, lower power, better performance). The primary challenge is gyroscope drift: small integration errors accumulate over time, causing orientation estimates to slowly diverge from reality. Sensor fusion (complementary filter or Kalman filter) corrects gyroscope drift using the accelerometer's long-term reference to gravity.

Detailed Explanation

IMUs (inertial measurement units) are among the most information-rich sensors in embedded design. A 6-axis MEMS IMU in a 3 mm × 3 mm package can provide real-time acceleration, rotation rate, step counting, tap detection, free-fall detection, and attitude estimation — capabilities that would have required large, expensive mechanical gyroscopes a generation ago. Understanding how to get useful data from them requires understanding their physical principles, their digital interface, and the firmware math needed to turn raw sensor data into meaningful orientation information.

MEMS Accelerometer Operating Principle

A MEMS (microelectromechanical systems) accelerometer contains a microscopic proof mass — a small silicon plate — suspended by thin silicon springs etched from the chip substrate. When the device accelerates, the proof mass deflects relative to the chip body (Newton's second law: F = ma, so a = F/m). The deflection is measured as a change in differential capacitance between the proof mass and fixed electrodes built into the chip.

The accelerometer output is the total force per unit mass acting on the sensor: the combination of gravitational acceleration and any dynamic linear acceleration. When stationary, only gravity acts — the sensor reports approximately (0, 0, 1 g) when lying flat with Z axis pointing up, or some combination of X/Y/Z gravity components when tilted.

Scale factor: MEMS accelerometers are available with full-scale ranges of ±2g, ±4g, ±8g, ±16g. At ±2g with a 16-bit ADC, sensitivity is 32,768 / (2×2) = 8,192 LSB per g. At ±16g, sensitivity drops to 2,048 LSB per g. Choose the smallest range that covers your application's dynamics to maximise resolution. For a stationary or slow-moving device, ±2g or ±4g; for vibration or shock measurements, ±8g to ±16g.

MEMS Gyroscope Operating Principle

A MEMS gyroscope uses the Coriolis effect: a vibrating proof mass that is rotating will experience a force perpendicular to its vibration direction. By measuring this Coriolis force, the IC determines the rotation rate. The gyroscope outputs angular velocity in degrees per second (°/s) or radians per second.

Gyroscope drift: The Coriolis force measurement contains a small, slowly varying bias error (typically 0.01–0.1°/s). When this is integrated to produce rotation angle (θ += ω × dt), the error accumulates. A 0.01°/s bias error causes a 0.6°/minute drift in the estimated angle — tolerable for fast motion tracking, problematic for slow orientation estimation over minutes.

Common Embedded IMU ICs

MPU-6050 (TDK InvenSense)

The MPU-6050 is the most widely used 6-axis IMU in hobbyist and early-stage embedded designs. Available on breakout boards from many suppliers.

  • Interface: I2C (up to 400 kHz, Fast Mode)
  • Axes: 3-axis accelerometer + 3-axis gyroscope
  • ADC: 16-bit for each axis
  • I2C Address: 0x68 (AD0 pin low) or 0x69 (AD0 pin high) — two devices per I2C bus
  • Supply voltage: 2.375–3.46 V (not 5 V tolerant on VDD; use a level shifter or 3.3 V logic only)
  • Gyro full-scale: ±250, ±500, ±1000, ±2000 °/s
  • Accel full-scale: ±2g, ±4g, ±8g, ±16g
  • DLPF (digital low-pass filter): configurable from 5 Hz to 260 Hz bandwidth
  • FIFO buffer: 1,024 byte FIFO for burst reading, reducing I2C polling overhead
  • DMP: onboard Digital Motion Processor for quaternion output (see FAQ)
  • Temperature sensor: built-in, useful for gyroscope drift temperature compensation

Register interface (key registers):

RegisterAddressContents
PWR_MGMT_10x6BSleep mode control, clock source
SMPLRT_DIV0x19Sample rate divider
CONFIG0x1ADLPF bandwidth
GYRO_CONFIG0x1BGyroscope full-scale range
ACCEL_CONFIG0x1CAccelerometer full-scale range
ACCEL_XOUT_H0x3BStart of 14-byte accel + temp + gyro data block
INT_STATUS0x3AData ready interrupt flag

Typical initialisation sequence:

i2c_write_reg(0x68, 0x6B, 0x00);   // Wake from sleep, use internal 8 MHz osc
i2c_write_reg(0x68, 0x1C, 0x00);   // Accel: ±2g full scale
i2c_write_reg(0x68, 0x1B, 0x00);   // Gyro: ±250°/s full scale
i2c_write_reg(0x68, 0x1A, 0x03);   // DLPF: ~44 Hz bandwidth

Reading 14 consecutive bytes from register 0x3B returns all 6 axes in big-endian 16-bit format: ACCEL_X, ACCEL_Y, ACCEL_Z, TEMP, GYRO_X, GYRO_Y, GYRO_Z.

LSM6DSO (STMicroelectronics)

The LSM6DSO is ST's current mainstream 6-axis IMU, offering lower power consumption and better performance than the MPU-6050. Used in professional embedded designs and IoT products.

  • Interface: I2C (up to 400 kHz) or SPI (up to 10 MHz) — see what is SPI?
  • Supply voltage: 1.71–3.6 V
  • Gyro full-scale: ±125 to ±2000 °/s
  • Accel full-scale: ±2g to ±16g
  • Low-power mode: down to 25 µA (accel only, 12.5 Hz)
  • FIFO: 3 kB, timestamp included
  • Embedded functions: step counting, tilt detection, free-fall detection, tap detection — all performed in hardware without MCU waking up
  • Machine learning core: simple decision tree classifiers run on the LSM6DSO itself for activity recognition

For battery-powered IoT products, the LSM6DSO's hardware step counter and activity recognition allow the MCU to stay in deep sleep until a motion event occurs, dramatically extending battery life compared to polling an MPU-6050 at high rate.

Sensor Fusion: Complementary Filter

The complementary filter is the simplest practical sensor fusion approach. It combines:

  • Gyroscope for short-term accuracy (low noise, but drifts long-term)
  • Accelerometer for long-term accuracy (gravity reference, but noisy during motion)
// Complementary filter (roll axis, executed every dt seconds)
float alpha = 0.98f;  // Trust gyroscope 98%, accelerometer 2%

// Gyroscope angle (integrated rate)
float gyro_angle = prev_angle + gyro_x_rads_per_s * dt;

// Accelerometer angle (from gravity vector)
float accel_angle = atan2f(accel_y, accel_z) * (180.0f / M_PI);

// Fused estimate
float angle = alpha * gyro_angle + (1.0f - alpha) * accel_angle;

The alpha coefficient (typically 0.95–0.99) sets the time constant: with alpha = 0.98 at 100 Hz sample rate, the complementary filter time constant is 1/(100 × (1−0.98)) = 0.5 seconds. The accelerometer corrects 2% of the gyroscope drift at each sample.

Limitation: Only corrects roll and pitch (gravity vector is the reference). Yaw (rotation around the vertical axis) still drifts indefinitely with this approach — a magnetometer is needed for yaw correction.

Madgwick and Mahony Filters

For better accuracy than a simple complementary filter, particularly during dynamic motion, the Madgwick filter (open-source, widely used) uses a gradient-descent optimisation algorithm on a quaternion representation of orientation. It handles nonlinear kinematics better than a scalar complementary filter and handles 9-DOF input (with magnetometer) as naturally as 6-DOF.

The Mahony filter uses proportional-integral (PI) control to drive the estimated orientation toward the sensor measurements, providing good behaviour for high-rate applications (≥ 200 Hz) with low computational overhead.

Both algorithms are available as C reference implementations from x-io Technologies and run efficiently on STM32, ESP32, and nRF52 microcontrollers.

For IMU integration into a product including sensor calibration, FIFO management, and fusion algorithm selection, Zeus Design's engineering team provides full sensor firmware development support.

Design Considerations

  • Calibrate the accelerometer and gyroscope bias at startup: Both the MPU-6050 and LSM6DSO have factory calibration but manufacturing variation means each unit has a small bias offset. At startup (when the device is known to be stationary), collect 1,000 samples of each axis and compute the mean — this is the bias offset for that unit. Subtract it from every subsequent reading. For the gyroscope, this dramatically reduces initial drift. Store the calibration values in non-volatile flash if the device is not expected to be stationary on every boot.
  • Mount the IMU with its axis frame aligned to the product's physical axes: The LSM6DSO and MPU-6050 have a defined X-Y-Z axis frame printed on the chip or marked in the datasheet. If the sensor is rotated on the PCB relative to the product's natural "forward" direction, apply a coordinate transformation (rotation matrix) in firmware rather than re-orienting the sensor physically, which may not always be mechanically feasible.
  • DLPF bandwidth and sample rate: The digital low-pass filter inside the IMU smooths the raw MEMS data before it reaches the output register or FIFO. Setting the DLPF too narrow (low bandwidth) introduces phase delay — the measurement lags behind actual motion. Setting it too wide passes more noise through. For typical orientation tracking at 100 Hz, a DLPF of 42–44 Hz is a good starting point.

Common Mistakes

  • Forgetting to take the MPU-6050 out of sleep mode: The MPU-6050 powers up in sleep mode with the SLEEP bit set in PWR_MGMT_1. Every reading will return 0 until sleep is cleared. The first register write in any MPU-6050 initialisation sequence must write 0x00 to register 0x6B to wake the device.
  • Using integer arithmetic for angle integration: Gyroscope integration must accumulate small values (e.g. 0.015°/s × 0.01 s = 0.00015° per step). 16-bit integer arithmetic cannot represent values this small without truncating to zero — losing all the angular change below 1°. Always use 32-bit float for angle integration.
  • Not accounting for MCU loop timing variation: If the dt (time step) in the complementary filter is assumed to be constant but actually varies ±10% due to MCU task scheduling or interrupt jitter, the filter accumulates systematic error. Either use a hardware timer to measure the exact time between samples, or run the IMU read and fusion code in a timer interrupt at a fixed rate.

Frequently Asked Questions

What is the difference between an accelerometer and a gyroscope?
An accelerometer measures force (acceleration), reporting the sum of gravitational acceleration (always approximately 1 g downward) and any dynamic linear acceleration. When the device is stationary, the accelerometer reads the direction and magnitude of gravity — this allows calculating tilt (roll and pitch) from the static gravity vector. When the device moves, the dynamic acceleration component adds to the gravity reading and makes the accelerometer noisy for tilt estimation during motion. A gyroscope measures angular rotation rate (in degrees per second or radians per second). To get rotation angle, you integrate the rate over time: angle += gyro_rate × dt. The problem is that any small bias error in the gyroscope rate measurement accumulates into ever-growing drift in the integrated angle. Sensor fusion combines both: the gyroscope is accurate short-term (low noise, but drifts); the accelerometer provides a long-term gravity reference (accurate on average, but noisy during motion).
What does 6-DOF vs 9-DOF mean for an IMU?
DOF stands for degrees of freedom — the number of independent measurement axes. A 6-DOF IMU has: 3-axis accelerometer (X, Y, Z linear acceleration) + 3-axis gyroscope (roll rate, pitch rate, yaw rate). This provides roll and pitch orientation but not absolute heading (yaw), because there is no reference for yaw other than integrating gyroscope data, which drifts. A 9-DOF IMU adds a 3-axis magnetometer (electronic compass), which measures Earth's magnetic field direction and provides a long-term yaw reference, enabling full 3D attitude estimation with bounded drift. An AHRS (attitude and heading reference system) is a 9-DOF fusion algorithm. The trade-off is that the magnetometer is sensitive to nearby ferromagnetic materials and electromagnetic interference from motors, speakers, and power wiring — 9-DOF is harder to calibrate correctly than 6-DOF.
What is the MPU-6050 DMP and should I use it?
The MPU-6050 includes an onboard Digital Motion Processor (DMP) — a small processing core that runs TDK's proprietary sensor fusion algorithm internally, outputting orientation quaternions over I2C without requiring the host MCU to run fusion code. The DMP offloads computation from the MCU and provides lower-latency output. However, the DMP firmware is a closed-source binary blob loaded into the MPU-6050 RAM at startup, which makes debugging and customisation difficult. For most designs, running a complementary filter or Madgwick filter on the MCU gives equivalent or better results, and the code is fully visible and tunable. Unless you are targeting very constrained MCUs (8-bit, < 8 MHz) where running float-point fusion in real time is impractical, implement the filter on the MCU rather than relying on the DMP.

References

Related Questions

Related Forum Discussions