Source: https://mokxi.com/libraries/adafruit-mpu6050
Updated: 2026-11-02

Libraries / Sensors
Arduino library · Sensors

# Adafruit MPU6050: motion in real units

Adafruit MPU6050 is the friendly route to the GY-521 module. Instead of raw counts it gives you physical units through Adafruit’s Unified Sensor events: acceleration in meters per second squared, rotation in radians per second and the die temperature in degrees Celsius, filled into three sensors_event_t structures by one getEvent() call.

Open the example in the editor See the calls

Built in on Mokxi: #include <Adafruit_MPU6050.h> and it builds, with nothing to install. Free, and no account needed.

## What Adafruit MPU6050 does

Before reading, you set the ranges and the digital low-pass filter with names rather than register values: MPU6050_RANGE_8_G, MPU6050_RANGE_500_DEG, MPU6050_BAND_21_HZ. A narrower filter smooths vibration out of the readings at the cost of response time, which suits a tilt sensor more than a drum pad.

Remember the units when you compare with other tutorials. One g is about 9.81 m/s², so a board lying flat reads close to 9.8 on Z, and a rotation of 1 rad/s is about 57 degrees per second. The chip’s motion-detection interrupt can be configured, but in Mokxi it is never raised.

Library Manager name | Adafruit MPU6050

Author | Adafruit

Include | #include <Adafruit_MPU6050.h>

Boards | every board Mokxi compiles for but ATtiny85

In the simulator | Simulated: it runs against the part the way it does on the bench.

Parts it drives | Accelerometer and gyroscope, MPU6050

## Install it

It builds on every board Mokxi compiles for but ATtiny85.

In Mokxi it is built in: #include <Adafruit_MPU6050.h> and the sketch compiles, with no download, no zip and no Library Manager.

On a real board, install "Adafruit MPU6050" by Adafruit from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add Adafruit MPU6050 to lib_deps in PlatformIO. Mokxi follows the calls of release 2.2.6, so a sketch written here builds there too.

What to know in the simulator: The motion-detection interrupt is written to the chip but never raised.

ESP32-C3 · Arduino Uno · Arduino Nano · Arduino Mega 2560 · Arduino Leonardo · SparkFun Pro Micro · Arduino Micro · ESP32-C6 · Raspberry Pi Pico · Raspberry Pi Pico W · Seeed XIAO SAMD21 · STM32 · STM32 Nucleo-F411RE · STM32 Blue Pill · micro:bit V2 · Arduino Uno R4 · ESP32 DevKit · ESP32-S3-DevKitC-1 · ESP8266 NodeMCU · Arduino Pro Mini 3.3 V · Seeed XIAO ESP32-C3 · ESP32-C3 SuperMini · Seeed XIAO ESP32-C6 · ESP32-DevKitC V4 · LOLIN32 Lite · Wemos D1 R32 · Cheap Yellow Display · TTGO T-Display · Seeed XIAO ESP32-S3 · Arduino Nano ESP32 · Arduino Nano RP2040 Connect · Seeed XIAO RP2040 · Waveshare RP2040-Zero · Arduino Uno R4 WiFi

## The calls you will use

In the order a sketch meets them.

### Adafruit_MPU6050 mpu

Creates the sensor object.

### mpu.begin()

Starts I2C and checks the chip at 0x68. Returns false when it is not found; begin(0x69) for a board with AD0 high.

### mpu.setAccelerometerRange(MPU6050_RANGE_8_G)

Plus or minus 2, 4, 8 or 16 g. A wider range reads harder knocks with less resolution.

### mpu.setGyroRange(MPU6050_RANGE_500_DEG)

Plus or minus 250, 500, 1000 or 2000 degrees per second.

### mpu.setFilterBandwidth(MPU6050_BAND_21_HZ)

The low-pass filter, from 260 Hz down to 5 Hz.

### mpu.getEvent(&a, &g, &temp)

Reads the chip once and fills three events.

### temp.temperature

The chip’s own temperature in degrees Celsius. It runs a few degrees above the room, so it is not a room thermometer.

## Example: Tilt an MPU6050

On the Arduino Uno R3. It runs in the browser exactly as printed.

sketch.ino · Arduino Uno R3

### Wiring

- Arduino Uno R3 A4 to Accelerometer and gyroscope, MPU6050 SDA
- Arduino Uno R3 A5 to Accelerometer and gyroscope, MPU6050 SCL
- Arduino Uno R3 5V to Accelerometer and gyroscope, MPU6050 VCC
- Arduino Uno R3 GND to Accelerometer and gyroscope, MPU6050 GND

Open it in the editor, wired and ready to run

## Common errors and how to fix them

### Failed to find MPU6050 chip

begin() returned false. Check the I2C wires and the address (0x68, or 0x69 with AD0 high). Some modules sold as MPU6050 carry an MPU6500 or a clone with another ID, which the Adafruit library rejects on a real board.

### Acceleration on Z reads about 9.8 and you expected 1

The library reports meters per second squared, not g. Divide by 9.81 (SENSORS_GRAVITY_STANDARD) if your code or a tutorial expects g.

### fatal error: Adafruit_Sensor.h: No such file or directory

The library depends on Adafruit Unified Sensor and Adafruit BusIO. On a real board install both from the Library Manager, then include Adafruit_Sensor.h as the examples do.

## Projects that use Adafruit MPU6050

Built-in projects that include it. Each page has the full sketch and opens in the editor, already wired.

MPU6050 servo stabilizer A self-leveling gimbal on an Uno: tilt the MPU6050 and two servos turn the other way to hold a platform level, through a complementary filter. Hand gesture controlled car Tilt an MPU6050 on your hand and a 2WD car follows over nRF24L01 radios: forward, reverse, left, right, and it stops when the signal is lost.

## Keep going

### Learn

- Arduino MPU6050: Accelerometer and Tilt

### Parts

- Accelerometer and gyroscope, MPU6050

### More sensors libraries

- DHT sensor library
- DHT20
- VL53L0X
- Adafruit_VL53L0X
- HX711 Arduino Library
- MPU6050
- BME280
- Adafruit BMP280 Library

Every built-in library · Open the editor

## Try Adafruit MPU6050 without installing anything

Open the example, change the sketch, and keep your version in a free account.

Start building free

Open the editor
