Reference
MPU6050 Accelerometer + Gyroscope Complete Guide
The MPU6050 packs a 3-axis accelerometer and 3-axis gyroscope on one die with an onboard motion-fusion processor, for around the price of a single sensor. This guide covers its real I2C addressing, pinout, and wiring one to an ESP32.
The MPU6050 (usually sold on a small “GY-521” breakout) is a 6-axis motion-tracking IC from InvenSense: a 3-axis accelerometer and 3-axis gyroscope combined on one chip, with an onboard Digital Motion Processor (DMP) that can fuse both into a stable orientation estimate in hardware, offloading that math from your microcontroller.
Pinout and I2C Address
| Pin | Function |
|---|---|
| VCC | Power, typically 3.3V–5V (breakout-regulated) |
| GND | Ground |
| SCL | I2C clock |
| SDA | I2C data |
| XDA | Auxiliary I2C data, for chaining a magnetometer directly to the MPU6050 |
| XCL | Auxiliary I2C clock |
| AD0 | I2C address select |
| INT | Interrupt output (e.g. new-data-ready, or DMP events) |
Default I2C address is 0x68 with AD0 left floating or tied to GND. Pull AD0 HIGH (3.3V) for address 0x69, useful when running two MPU6050s on the same bus.
Wiring to an ESP32
| MPU6050 Pin | ESP32 Pin |
|---|---|
| VCC | 3.3V |
| GND | GND |
| SCL | GPIO22 |
| SDA | GPIO21 |
Arduino code (Adafruit MPU6050 library)
#include <Wire.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
Adafruit_MPU6050 mpu;
void setup() {
Serial.begin(115200);
Wire.begin(21, 22);
if (!mpu.begin()) {
Serial.println("Failed to find MPU6050");
while (1) delay(10);
}
mpu.setAccelerometerRange(MPU6050_RANGE_8_G);
mpu.setGyroRange(MPU6050_RANGE_500_DEG);
}
void loop() {
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
Serial.print("Accel (m/s^2): ");
Serial.print(a.acceleration.x); Serial.print(", ");
Serial.print(a.acceleration.y); Serial.print(", ");
Serial.println(a.acceleration.z);
Serial.print("Gyro (rad/s): ");
Serial.print(g.gyro.x); Serial.print(", ");
Serial.print(g.gyro.y); Serial.print(", ");
Serial.println(g.gyro.z);
delay(200);
}Install “Adafruit MPU6050” via the Arduino Library Manager (it uses Adafruit’s shared sensor-abstraction library, giving values in standard m/s² and rad/s units). For onboard DMP-based orientation fusion instead of raw values, the older i2cdevlib MPU6050 library exposes it directly, at the cost of a less beginner-friendly API.
Practical Tips
- Calibrate at rest: the gyroscope has a real zero-rate offset that drifts between units, read and subtract a baseline while the sensor sits still before using its output.
- Gyro drifts over time: pure gyro integration for orientation drifts, this is exactly what the onboard DMP’s sensor fusion (or a software complementary/Kalman filter combining accel + gyro) is for.
- Mount rigidly: any flex or vibration in the mount reads as false acceleration/rotation.
- XDA/XCL are optional: leave them unconnected unless you’re chaining an external magnetometer (e.g. an HMC5883L) directly to the MPU6050’s auxiliary bus.
Practical Applications
- Tilt/orientation sensing: self-balancing robots, gimbals.
- Step counting / activity detection: wearable projects.
- Vibration/impact detection: accelerometer-only use cases.
- Drone/RC flight controllers: a common low-cost IMU choice for hobby builds.
Conclusion
The MPU6050 is a well-documented, inexpensive way to add 6-axis motion sensing to a project, over the same I2C bus an ESP32 already uses for other sensors on this site.
Related
Reference
The Complete Guide to the RC522 RFID Module
A low-cost 13.56 MHz RFID reader/writer that talks SPI and reads MIFARE cards and key fobs out of the box. This guide covers the pinout, ESP32 wiring, the MFRC522 Arduino library, and where its short read range and UID-cloning risk matter.
Read more
Reference
PN532 NFC Module Complete Guide
The PN532 reads and writes NFC tags, including the kind your phone already uses for tap-to-pay and tap-to-share, not just the 13.56MHz RFID cards the already-published RC522 handles. This guide covers its three interfaces, wiring it to an ESP32 over I2C, and when you actually need NFC over plain RFID.
Read more
Guide
ESP8266-01 Pinout
The complete pin reference for the ESP8266-01 breakout: just 8 pins, only 2 usable GPIOs, and no onboard USB, so wiring it up needs a bit more care than a dev board.
Read more
More guides
Keep building.
From ESP32 HomeKit accessories to Arduino and ATtiny reference guides, there’s more where this came from.
All guides