MPU6050 (GY-521) accelerometer + gyro with ESP32
Supply 3.3-5 V
Bus I2C
I2C address
0x68 / 0x69
Measures acceleration, rotation, temperature
Pins and ESP32 wiring
| Pin | Role | ESP32 pin | Notes |
|---|---|---|---|
| VCC | Power | 3V3 | |
| GND | Ground | GND | |
| SCL | I2C clock (SCL) | D22 | |
| SDA | I2C data (SDA) | D21 | |
| INT | Interrupt | D35 |
Suggested wiring for the 30-pin ESP32 DevKit, avoiding flash, input-only and strapping pins. BoardPilot checks it for you as you wire.
Good to know
- The address is 0x68, or 0x69 when AD0 is HIGH. (InvenSense MPU-6000/MPU-6050 Product Specification, I²C interface: slave address)
- It starts in sleep mode and reads zeros until PWR_MGMT_1 (0x6B) is cleared. Libraries do this in begin(); your own code must too. (InvenSense MPU-6000/MPU-6050 Register Map, Register 107, Power Management 1 (reset value 0x40, sleep))
Check it is the real chip
Read register 0x75: a genuine part answers 0x68. BoardPilot does this automatically in “Debug a problem”.
Starter code (Arduino)
#include <Wire.h>
void setup() {
Serial.begin(115200);
Wire.begin(21, 22); // SDA = GPIO 21, SCL = GPIO 22
Wire.beginTransmission(0x68);
bool found = Wire.endTransmission() == 0;
Serial.println(found ? "MPU6050 (GY-521) accelerometer + gyro found at 0x68" : "Not found: check power, GND and SDA/SCL");
}
void loop() {}
Sources
- InvenSense MPU-6000/6050 Register Map, 4.32 Register 117 WHO_AM_I (0x68)
Try it in 3D in BoardPilot
MPU6050 (GY-521) accelerometer + gyro on other boards: wiring and code
Arduino Mega 2560 R3 Arduino Nano Arduino Uno R3 WeAct Black Pill STM32F411CE ESP32-C3-DevKitM-1 ESP32-S3-DevKitC-1 Nordic nRF52840 DK NUCLEO-F401RE Raspberry Pi Pico 2 Raspberry Pi Pico W Raspberry Pi Pico Teensy 4.1
Learn the basics
Lesson: UART, I2C and SPI Lesson: Timers and interrupts I2C I2C address SDA and SCL Pull-up resistor Interrupt
Related parts
ADS1015 12-bit ADCADS1115 16-bit ADCADXL375 high-g accelerometer (±200 g)AHT10 temperature + humidityAHT20 + BMP280 combo moduleAHT20 temperature + humidity
Part data: CC BY 4.0, free to reuse with credit to BoardPilot.