Component guide · Intermediate · 3 min read
MPU6050 Accelerometer and Gyroscope
Guide, Wiring and Code
By Geekobot Learning Team · Updated 24 Oct 2026
On this page
The MPU6050 is a 6-axis motion sensor that combines a 3-axis accelerometer and a 3-axis gyroscope on one chip and talks over I2C at address 0x68. On the popular GY-521 module it runs from 3.3 to 5 V. It is used for self-balancing robots, tilt sensing, gesture control and drone stabilisation.
Key specs at a glance
- Sensors
- 3-axis accelerometer + 3-axis gyroscope + temperature
- Accelerometer range
- ±2, ±4, ±8 or ±16 g
- Gyroscope range
- ±250, ±500, ±1000 or ±2000 °/s
- Resolution
- 16-bit for each axis
- Interface
- I2C up to 400 kHz, address 0x68 (0x69 with AD0 high)
- Supply
- GY-521 module: 3.3 to 5 V (onboard 3.3 V regulator)
- Extras
- INT pin, Digital Motion Processor (DMP), auxiliary I2C
What the accelerometer and gyroscope measure
The accelerometer measures acceleration, including gravity. Held still, it tells you which way is down, so you can calculate tilt (pitch and roll). It is noisy when the sensor vibrates or moves.
The gyroscope measures rotation speed in degrees per second. Integrating it over time gives an angle that is smooth over short periods but slowly drifts.
Combining both with a complementary filter or the chip's DMP gives a stable angle. The MPU6050 has no magnetometer, so heading (yaw) always drifts; use an MPU9250-class or BNO055 sensor if you need a compass.
GY-521 pinout
| Pin | Connect to | Purpose |
|---|---|---|
| VCC | 3.3 V or 5 V | Power (module regulates to 3.3 V) |
| GND | GND | |
| SCL | Uno A5, ESP32 GPIO 22, Pico GP5 | I2C clock |
| SDA | Uno A4, ESP32 GPIO 21, Pico GP4 | I2C data |
| XDA, XCL | Optional | Auxiliary bus for an external magnetometer |
| AD0 | GND or leave open (0x68), 3.3 V (0x69) | Address select |
| INT | Optional interrupt pin | Data-ready or motion interrupt |
- VCC
- Connect to:
- 3.3 V or 5 V
- Purpose:
- Power (module regulates to 3.3 V)
- GND
- Connect to:
- GND
- SCL
- Connect to:
- Uno A5, ESP32 GPIO 22, Pico GP5
- Purpose:
- I2C clock
- SDA
- Connect to:
- Uno A4, ESP32 GPIO 21, Pico GP4
- Purpose:
- I2C data
- XDA, XCL
- Connect to:
- Optional
- Purpose:
- Auxiliary bus for an external magnetometer
- AD0
- Connect to:
- GND or leave open (0x68), 3.3 V (0x69)
- Purpose:
- Address select
- INT
- Connect to:
- Optional interrupt pin
- Purpose:
- Data-ready or motion interrupt
Read the MPU6050 with Arduino or ESP32
Install Adafruit MPU6050 from the Library Manager. Accelerations come out in m/s² and rotation in rad/s.
#include <Adafruit_MPU6050.h>
#include <Wire.h>
Adafruit_MPU6050 mpu;
void setup() {
Serial.begin(115200);
if (!mpu.begin()) { // default address 0x68
Serial.println("MPU6050 not found");
while (1) delay(10);
}
mpu.setAccelerometerRange(MPU6050_RANGE_4_G);
mpu.setGyroRange(MPU6050_RANGE_500_DEG);
mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);
}
void loop() {
sensors_event_t a, g, t;
mpu.getEvent(&a, &g, &t);
float pitch = atan2(a.acceleration.x,
sqrt(a.acceleration.y * a.acceleration.y +
a.acceleration.z * a.acceleration.z)) * 180 / PI;
Serial.print("Pitch: "); Serial.print(pitch);
Serial.print(" Gyro Z: "); Serial.println(g.gyro.z);
delay(100);
}Calibration and drift
Every MPU6050 has small offsets. Lay the module flat and still, average a few hundred gyro readings, and subtract that average from later readings. For the accelerometer, average readings in each orientation. Many libraries, including Electronic Cats' MPU6050 (based on i2cdevlib), include an auto-calibration routine that writes offsets into the chip.
MPU6050 alternatives
TDK InvenSense has listed the MPU6050 as end-of-life, so many modules now carry compatible clones. For new designs consider:
| Sensor | Axes | Why choose it |
|---|---|---|
| MPU6500 / ICM-20600 series | 6 | Drop-in successors, SPI and I2C |
| ICM-42688-P | 6 | Low noise, used in modern flight controllers |
| BMI160 / BMI270 | 6 | Very low power, wearables |
| BNO055 / BNO085 | 9 with fusion | Outputs ready-made orientation; no filter code needed |
- MPU6500 / ICM-20600 series
- Axes:
- 6
- Why choose it:
- Drop-in successors, SPI and I2C
- ICM-42688-P
- Axes:
- 6
- Why choose it:
- Low noise, used in modern flight controllers
- BMI160 / BMI270
- Axes:
- 6
- Why choose it:
- Very low power, wearables
- BNO055 / BNO085
- Axes:
- 9 with fusion
- Why choose it:
- Outputs ready-made orientation; no filter code needed
Common mistakes to avoid
- Expecting a stable yaw (compass heading); without a magnetometer it drifts.
- Sharing address 0x68 with a DS3231 RTC; pull AD0 high to move the MPU6050 to 0x69.
- Mounting it on a vibrating motor frame without soft mounting or filtering.
- Integrating the gyroscope alone for angles, which drifts within seconds.
- Ignoring the 'not found' message: usually SDA/SCL are swapped or the module is unpowered.
Frequently asked questions
What is the MPU6050 used for?
Tilt and orientation sensing in self-balancing robots, gimbals, gesture controllers, step counters, vehicle crash detection and drone flight controllers.
What is the I2C address of the MPU6050?
0x68 by default, or 0x69 when the AD0 pin is pulled high, so two can share one bus.
Can the MPU6050 run on 5 V?
The chip itself is a 3.3 V part, but GY-521 modules include a regulator and pull-ups, so they accept 3.3 to 5 V on VCC.
What is the difference between MPU6050 and MPU9250?
The MPU9250 adds a 3-axis magnetometer, giving 9 axes and a stable compass heading. The MPU6050 has 6 axes only.
Why are my MPU6050 angles drifting?
Gyroscope integration accumulates small errors. Calibrate offsets at start-up and fuse accelerometer and gyro data with a complementary or Kalman filter, or use the DMP.
Parts for this guide
- ₹562View
Terms in this guide
Projects that use it
Put this into practice: 39 step-by-step builds in our project library use parts from this guide.
Keep learning
Sources
- MPU-6000/MPU-6050 Product Specification and Register Map (TDK InvenSense)
- Adafruit MPU6050 library documentation
Written by the Geekobot team from manufacturer datasheets. Always check the datasheet for the exact part and variant you buy.

