Blog
ESP32 MPU6050: Accelerometer, Gyro
Two I2C wires, one address, and a small mountain of drift math — the MPU6050 is the default 6-axis IMU for ESP32 projects. Here’s the wiring, the wake-up gotcha, and the calibration.
Does the ESP32 Have a Gyroscope?
No — and no accelerometer either, so orientation sensing always means an external IMU. The MPU6050 is the standard choice: one chip, accelerometer plus gyroscope, I2C, ~$2 on a breakout. Nothing on the ESP32 itself measures motion.
How to Connect MPU6050 to ESP32?
Four wires on I2C: VCC→3V3, GND→GND, SCL→GPIO22, SDA→GPIO21 — the default Wire pins on a classic ESP32 DevKit. AD0→GND keeps the address at 0x68. Skip the INT pin for a first build; power the module at 3V3 even when the board carries a 5V regulator.
How to Connect a MPU6050 to ESP32?
Identical to the above — VCC→3V3, GND→GND, SCL and SDA to your board’s I2C pins — just check what those pins are, since the default changes per board. On ESP32-S3 devkits the same sketch often needs Wire.begin(8, 9) instead of 21/22. The simulator shows the classic layout first.
How to Connect a MPU9250 to an ESP32 Arduino?
Same I2C hookup as the MPU6050 — VCC→3V3, GND, SCL, SDA — because the MPU9250 is an MPU6500 with a magnetometer bolted on. In Arduino, the magnetometer answers on its own internal address (0x0C) through the same two wires, so nothing extra to connect. Libraries handle the extra axis.
How to Connect ESP32 to Computer?
A data-capable USB cable, full stop: the board appears as a COM port (or /dev/ttyUSB0 on Linux) and the serial monitor at 115200 baud prints your IMU readings — this is how you watch accelerometer values while calibrating. The classic trap is a charge-only cable that powers the board but never connects.
Why does my MPU6050 return 0, 0, 0?
It’s asleep — the chip boots into sleep mode, and a basic library forgets to wake it, so every axis reads zero while the I2C handshake still succeeds. One register write fixes it: mpu.wakeUp() or clearing PWR_MGMT_1. If it’s not sleep, check the address (0x68 vs 0x69 when AD0 floats) or the SDA solder joint. The debugging FAQ covers the scanner.
Why do my angles drift even when the sensor is still?
Gyro integration accumulates error — a small offset becomes a big angle over a minute, which is physics, not a broken sensor. Fuse the accelerometer’s absolute tilt with the gyro’s fast response: a complementary filter (a few lines) or the MPU6050’s onboard DMP. Raw gyro integration alone always drifts.
How do I calibrate the MPU6050?
Set it flat and still, average a few hundred readings, store the offsets. On my DevKit V1 the gyro Z offset came out at +0.9°/s at rest — small, but that’s ~54°/min of drift if uncorrected. MPU6050_light auto-calibrates on boot; rolling your own means subtracting the averages. Recalibrate whenever the mounting changes.
Which library should I use for MPU6050?
Adafruit MPU6050 for raw accelerometer and gyro values with a clean API; MPU6050_light when you want DMP angles without writing the fusion yourself. Both handle the wake-up. The DMP route costs RAM but saves filter math; example sketches show both.
Can I share the I2C bus with other sensors?
Yes — the MPU6050 sits at 0x68 (0x69 with AD0 high), so a BME280 at 0x77 and an OLED at 0x3C coexist happily on the same SDA/SCL pair. Capacity is about the address space minus collisions.
Confirm the Bus Before Blaming the Driver
No MPU6050-specific example yet — but the first debugging step for any I2C IMU runs here: the I2C scanner tells you whether your 0x68/0x69 device answers at all (or 0x69↔0x68 after the AD0 pin discussion in this FAQ). No answer means wiring and power, before any register-map debugging starts.