The MPU-9250 is a 9-axis inertial measurement unit (IMU) that combines a 3-axis accelerometer, 3-axis gyroscope and 3-axis AK8963 magnetometer. It measures linear acceleration, angular velocity and magnetic field, making it useful for motion tracking, orientation experiments and electronic compass projects. The sensor does not directly output a reliable heading or fused orientation; those require calibration and software processing.
How the MPU-9250 works
The accelerometer measures acceleration including gravity, so a stationary sensor can estimate tilt from the gravity vector. The gyroscope measures rotation rate and is useful for responsive motion tracking, but integrating its output causes drift. The AK8963 magnetometer measures the local magnetic field and can help estimate heading after calibration. Motors, speakers, steel, magnets and current-carrying wires can distort magnetic readings.
The MPU-9250 contains several sensor subsystems. Reading acceleration and gyro data does not automatically produce a stable compass heading or full orientation. For those results, choose an appropriate sensor-fusion algorithm and calibrate the device in its installed environment.
I²C wiring and address
Use the board-specific wiring below and keep SDA/SCL wiring short. The examples connect AD0 to GND for address 0x68 and NCS to 3.3 V to select I²C mode. If AD0 is tied HIGH, change the address in the sketch to 0x69. Avoid 5 V pull-ups on the I²C bus when the breakout is not level-shifted.
What you can build
- Digital compass: use calibrated magnetometer readings and tilt compensation when the board is not level.
- Motion logger: record acceleration and angular velocity for experiments or gesture recognition.
- Orientation interface: combine the sensor data with a suitable fusion filter for a more stable attitude estimate.
- Robot or drone prototype: use the IMU as one input to a larger control system; validate sampling, vibration isolation and calibration before relying on it.
- Wearable and handheld projects: detect movement patterns while accounting for drift and magnetic interference.
Frequently asked questions
Is MPU-9250 the same as MPU-6050? No. The MPU-6050 has an accelerometer and gyroscope; the MPU-9250 adds a 3-axis AK8963 magnetometer.
Can I power it from 5 V? Only if the exact breakout board explicitly supports a 5 V input. The bare IC requires 2.4–3.6 V. The examples here use 3.3 V.
Does it provide yaw, pitch and roll directly? No. It provides raw sensor measurements. Orientation angles require processing; heading also needs magnetometer calibration and tilt compensation.
Why do some cheap modules fail the MPU-9250 check? Some visually similar boards contain MPU-6500 or other compatible-looking chips. Check the chip marking and library detection rather than assuming every clone is genuine.
Can the embedded simulator reproduce real sensor data? No. It demonstrates the circuit layout and interactive tilt visualization; it does not emulate the MPU-9250 register protocol, live AK8963 field measurements, noise, drift or sensor fusion.
Run the MPU9250 in your browser
Ready-wired circuit with code. No hardware, no install.
Wiring & code
Board integration
Library
MPU9250_WE by Wolfgang Ewald
Arduino IDE → Library Manager → search "MPU9250_WE"
Wiring
| Component pin | Arduino Uno pin | Note |
|---|---|---|
| VCC | 3.3V | Use 3.3 V unless the exact breakout explicitly supports 5 V. |
| GND | GND | Common ground. |
| SCL | A5 / SCL | Uno I2C clock. |
| SDA | A4 / SDA | Uno I2C data. |
| AD0 | GND | Select I2C address 0x68. |
| NCS | 3.3V | Keep HIGH for I2C mode. |
| XDA / XCL / INT | Not connected | Optional for this example. |
Warning
The MPU-9250 IC is a 3.3 V device. Confirm your breakout's regulator and I2C pull-up circuitry; do not put 5 V on the sensor or ESP32 GPIO.
#include <Wire.h>
#include <MPU9250_WE.h>
#define MPU9250_ADDR 0x68
MPU9250_WE imu = MPU9250_WE(MPU9250_ADDR);
void setup() {
Serial.begin(9600);
Wire.begin(); // Uno SDA=A4, SCL=A5
delay(100);
if (!imu.init()) {
Serial.println("MPU-9250 not detected. Check wiring and AD0.");
while (true) delay(10);
}
Serial.println("Keep the sensor still for calibration...");
imu.autoOffsets(); // Not a substitute for magnetometer calibration
imu.setAccRange(MPU9250_ACC_RANGE_2G);
imu.setGyrRange(MPU9250_GYRO_RANGE_250);
imu.setSampleRateDivider(4);
Serial.println("MPU-9250 ready");
}
void loop() {
xyzFloat accel = imu.getGValues();
xyzFloat gyro = imu.getGyrValues();
xyzFloat mag = imu.getMagValues();
Serial.print("Accel (g): ");
Serial.print(accel.x, 2); Serial.print(", ");
Serial.print(accel.y, 2); Serial.print(", "); Serial.println(accel.z, 2);
Serial.print("Gyro (deg/s): ");
Serial.print(gyro.x, 1); Serial.print(", ");
Serial.print(gyro.y, 1); Serial.print(", "); Serial.println(gyro.z, 1);
Serial.print("Mag (uT): ");
Serial.print(mag.x, 1); Serial.print(", ");
Serial.print(mag.y, 1); Serial.print(", "); Serial.println(mag.z, 1);
Serial.println();
delay(250);
}Setup and calibration
- Install MPU9250_WE by Wolfgang Ewald from Arduino IDE Library Manager.
- Wire the module exactly as shown and connect AD0 to GND for address 0x68.
- Upload the sketch and keep the sensor motionless during startup offset calibration.
- Open Serial Monitor at 9600 baud and move/rotate the module to observe changes.
- Compass heading requires separate magnetometer calibration and compensation for nearby magnetic interference.
Library reference and source: https://github.com/wollewald/MPU9250_WE (MIT-licensed MPU9250_WE library).
Expected output
Serial Monitor prints acceleration in g, angular velocity in degrees per second, and magnetic-field readings in microtesla. Raw values are not fused pitch, roll or yaw angles.
Troubleshooting
- No device found: check 3.3 V, GND, SDA/SCL, NCS HIGH and AD0; run an I2C scanner.
- If AD0 is HIGH, use address 0x69.
- Missing or implausible magnetometer values: verify the chip/module and use a compatible library; some clones contain a different IC.
- Heading changes near motors or steel: move the sensor away from magnetic interference and calibrate in the final installation.
- Jumpy values: secure the module, shorten I2C wires and verify the supply.
Try it in the simulator
The circuit below runs a no-library sketch that wakes the MPU-9250, prints its WHO_AM_I register and then pitch and roll from the accelerometer. Press Run, open the Serial Monitor and tilt the module from its Settings. The same register reads work on real hardware, so it is a quick way to confirm wiring and identify the chip before adding a library. A genuine MPU-9250 answers 0x71; many boards sold as MPU-9250 carry an MPU-6500 and answer 0x70, which has no magnetometer.
Try this circuit in the SolderHub Simulator
Run this exact circuit in your browserReady-wired, code loadedConfirm simulator behavior against the real wiring and the sensor datasheet before connecting hardware.
/*
MPU-9250: read the accelerometer directly over I2C and print pitch and roll
VCC -> 3.3V, GND -> GND, NCS -> 3.3V (selects I2C)
SDA -> A4, SCL -> A5, AD0 -> GND (address 0x68)
No library needed.
*/
#include <Wire.h>
const uint8_t MPU_ADDR = 0x68; // 0x69 if AD0 is tied HIGH
void writeReg(uint8_t reg, uint8_t value) {
Wire.beginTransmission(MPU_ADDR);
Wire.write(reg);
Wire.write(value);
Wire.endTransmission();
}
void setup() {
Serial.begin(115200);
Wire.begin();
writeReg(0x6B, 0x00); // PWR_MGMT_1: wake up (it starts asleep)
Wire.beginTransmission(MPU_ADDR);
Wire.write(0x75); // WHO_AM_I
Wire.endTransmission(false);
Wire.requestFrom(MPU_ADDR, (uint8_t)1);
Serial.print("WHO_AM_I = 0x");
Serial.println(Wire.read(), HEX); // 0x71 = MPU-9250, 0x73 = MPU-9255, 0x70 = MPU-6500 (no magnetometer)
}
void loop() {
Wire.beginTransmission(MPU_ADDR);
Wire.write(0x3B); // ACCEL_XOUT_H: 6 bytes of X, Y, Z
Wire.endTransmission(false);
Wire.requestFrom(MPU_ADDR, (uint8_t)6);
int16_t ax = (Wire.read() << 8) | Wire.read();
int16_t ay = (Wire.read() << 8) | Wire.read();
int16_t az = (Wire.read() << 8) | Wire.read();
// At the default ±2 g range, 16384 counts = 1 g
float pitch = atan2(-ax, sqrt((float)ay * ay + (float)az * az)) * 180.0 / PI;
float roll = atan2(ay, az) * 180.0 / PI;
Serial.print("pitch ");
Serial.print(pitch, 1);
Serial.print(" roll ");
Serial.println(roll, 1);
delay(200);
}
