MPU6050: pinout and wiring of the accelerometer and gyroscope
The MPU6050 packs a 3-axis accelerometer and a 3-axis gyroscope into a cheap I2C chip. See the pinout, how to wire it to an Arduino and ESP32, and learn in the simulator how tilt becomes the values you read.
Specifications
- Axes
- 3 accelerometer + 3 gyroscope
- Supply
- 3.3 V to 5 V (regulator on the module)
- Interface
- I2C
- I2C address
- 0x68 (0x69 with AD0 at VCC)
- Accelerometer
- ±2, ±4, ±8 or ±16 g
- Gyroscope
- ±250 to ±2000 °/s
- Resolution
- 16 bits
- Temperature sensor
- built into the chip
Pinout
The GY-521 module has 8 pins; the first four are enough to read the data.
MPU6050 (GY-521)
| 1 | VCC | Power supply, 3.3 V to 5 V |
| 2 | GND | Ground |
| 3 | SCL | I2C clock |
| 4 | SDA | I2C data |
| 5 | XDA / XCL | Auxiliary bus (optional) |
| 6 | AD0 | Address: GND = 0x68, VCC = 0x69 |
| 7 | INT | Interrupt output (optional) |
MPU6050 simulator
Tilt the module and see how gravity is shared among the accelerometer axes.
Raw gyroscope (±250 °/s):
At a ±2 g range, 16,384 counts equal 1 g. Gravity always adds up to 1 g; what changes with tilt is how it is split among X, Y and Z. The gyroscope measures rotation rate: 131 counts equal 1 °/s.
How to wire it
Connect VCC to 5 V (or 3.3 V) and GND to ground. On the Arduino Uno connect SDA to A4 and SCL to A5; on the ESP32, SDA to GPIO 21 and SCL to GPIO 22.
The module already has pull-up resistors on the I2C bus, so you do not need extra ones for a single device.
The default address is 0x68. To use two MPU6050 on the same bus, connect AD0 of one of them to VCC so it answers at 0x69.
The library reads 14 bytes: acceleration (X, Y, Z), temperature and angular rate (X, Y, Z). At the ±2 g range, 16,384 counts equal 1 g; at ±250 °/s, 131 counts equal 1 °/s.
Resting on a table, the Z axis reads ≈ 1 g (gravity) and the others ≈ 0. Tilt is calculated from gravity.
Example code (Arduino)
Library-free sketch that wakes the chip, reads the registers and prints raw acceleration and rotation.
#include <Wire.h>
const int MPU = 0x68;
void setup() {
Serial.begin(9600);
Wire.begin();
Wire.beginTransmission(MPU);
Wire.write(0x6B); // PWR_MGMT_1
Wire.write(0); // wake the chip
Wire.endTransmission(true);
}
void loop() {
Wire.beginTransmission(MPU);
Wire.write(0x3B); // first acceleration register
Wire.endTransmission(false);
Wire.requestFrom(MPU, 14, true);
int16_t ax = Wire.read() << 8 | Wire.read();
int16_t ay = Wire.read() << 8 | Wire.read();
int16_t az = Wire.read() << 8 | Wire.read();
int16_t t = Wire.read() << 8 | Wire.read();
int16_t gx = Wire.read() << 8 | Wire.read();
int16_t gy = Wire.read() << 8 | Wire.read();
int16_t gz = Wire.read() << 8 | Wire.read();
Serial.print("A: "); Serial.print(ax / 16384.0); Serial.print(" ");
Serial.print(ay / 16384.0); Serial.print(" "); Serial.print(az / 16384.0);
Serial.print(" G: "); Serial.print(gx / 131.0); Serial.print(" ");
Serial.print(gy / 131.0); Serial.print(" "); Serial.print(gz / 131.0);
Serial.print(" T: "); Serial.println(t / 340.0 + 36.53);
delay(200);
}
Common mistakes
- Not waking the chip: it powers up in sleep mode and every reading is zero. Write 0 to register 0x6B.
- Swapping SDA and SCL or using the wrong board pins: Wire cannot find the device at address 0x68.
- Using the gyroscope reading directly as an angle: it is angular rate and must be integrated over time (and it drifts).
- Expecting rotation about the vertical axis (yaw) from the accelerometer alone: gravity does not change in that rotation.
- Connecting two modules without changing AD0 on one: both answer at the same address and the bus locks up.
Always check the manufacturer's datasheet for your exact model: pin order can vary between modules.
Frequently asked questions
What is the MPU6050 I2C address?
0x68 with the AD0 pin at GND (or floating) and 0x69 with AD0 at VCC.
How do I calculate tilt with the MPU6050?
With the module still, the tilt angle comes from the arctangent of the gravity components. For example pitch = atan2(−ax, √(ay² + az²)) and roll = atan2(ay, az).
Does the MPU6050 work with an ESP32?
Yes. Use SDA = GPIO 21 and SCL = GPIO 22 with the Wire library. The module accepts 3.3 V.
What is the difference between an accelerometer and a gyroscope?
The accelerometer measures acceleration, including gravity, and gives tilt. The gyroscope measures rotation rate and is good for fast movements.