# MPU6050 6-DoF Accelerometer and Gyro

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/083/746/medium800thumb/sensors_mpu6050_hirez.jpg?1573074249)

The MPU-6050 is a popular six DoF accelerometer and gyroscope (gyro) that has all the info you need on how things are shakin' and spinnin' . With six axes of sensing and 16-bit measurements, you'll have everything you need to give your robot friend a sense of balance, using the MPU-6050 as its inner ear.

This combination of gyroscopes and accelerometers is commonly referred to as an&nbsp; **I** nertial&nbsp; **M** easurement **U** nit or **IMU.** Not so long ago IMUs were the [size of a breadbox&nbsp;](http://mentalfloss.com/article/55835/how-big-breadbox)and cost upwards of **$50,000!** While you're not going to be using it to guide your mars rocket, the MPU-6050 is several orders of magnitude smaller and a bargain at a price three orders of magnitude less!&nbsp; Now you can add telemetry to your [water rocket](https://en.wikipedia.org/wiki/Water_rocket "water rocket")(with some waterproofing).

![](https://cdn-learn.adafruit.com/assets/assets/000/083/751/medium800/sensors_back_with_quarter.jpg?1573074401)

As with all Adafruit breakouts, we've done the work to make the MPU-6050 super easy to use. We've put it on a breakout board with the required support circuitry and connectors to make it easy to work with. And of course we've added [SparkFun Qwiic](https://www.sparkfun.com/qwiic) compatible [**STEMMA QT**](https://learn.adafruit.com/introducing-adafruit-stemma-qt)&nbsp;JST SH connectors that allow you to get going&nbsp; **without needing to solder.** &nbsp;Just use a [STEMMA QT adapter cable](https://www.adafruit.com/product/4209), plug it into your favorite micro or Blinka supported SBC and you're ready to rock!

![](https://cdn-learn.adafruit.com/assets/assets/000/083/747/medium800/sensors_stemma_and_bb.jpg?1573074313)

"What is a sensor without a driver?" you might say. To that I would reply "Who cares, we got some for you right here". Be it Arduino, CircuitPython or Python on a computer (single board or even [multi-board!](https://learn.adafruit.com/circuitpython-on-any-computer-with-ft232h)), we've got you covered.

# MPU6050 6-DoF Accelerometer and Gyro

## Pinouts

![](https://cdn-learn.adafruit.com/assets/assets/000/083/749/medium800/sensors_top_crop.jpg?1573074335)

## Power Pins

- **Vin** - this is the power pin. Since the sensor chip uses 3 VDC, we have included a voltage regulator on board that will take 3-5VDC and safely convert it down. To power the board, give it the same power as the logic level of your microcontroller - e.g. for a 5V microcontroller like Arduino, use 5V
- **3Vo** - this is the 3.3V output from the voltage regulator, you can grab up to 100mA from this if you like
- **GND** - common ground for power and logic

## I2C Logic Pins

- **SCL** - I2C clock pin, connect to your microcontroller's I2C clock line. This pin is level shifted so you can use 3-5V logic, and there's a **10K pullup** on this pin.
- **SDA** -I2C data pin, connect to your microcontroller's I2C data line. This pin is level shifted so you can use 3-5V logic, and there's a 1 **0K pullup** on this pin.
- **[STEMMA QT](https://learn.adafruit.com/introducing-adafruit-stemma-qt)&nbsp;-** These connectors allow you to connectors to dev boards with&nbsp; **STEMMA QT** connectors or to other things with&nbsp;[various associated accessories](https://www.adafruit.com/?q=JST%20SH%204)

&nbsp;

## Other Pins

- **INT&nbsp;** -This is the interrupt pin. You can setup the MPU-6050 to pull this low when certain conditions are met such as new measurement data being available. Consult the [datasheet and register map](https://learn.adafruit.com/mpu6050-6-axis-accelerometer-and-gyro/downloads) for usage
- **AD0** - I2C Address pin. Pulling this pin high or bridging the solder jumper on the back will change the I2C address from&nbsp; **0x68** to&nbsp; **0x69**
- **FS, SCE, SDE, CLKIN** - Pins for advanced users to connect the MPU-6050 to another sensor. Consult the [datasheet and register map](https://learn.adafruit.com/mpu6050-6-axis-accelerometer-and-gyro/downloads) for usage

# MPU6050 6-DoF Accelerometer and Gyro

## Arduino

## Wiring

Wiring the MPU-6050 to communicate with your microcontroller is straight forward thanks to the I2C interface. For these examples we can use the Metro or Arduino to take measurements. The instructions below show a [Metro](https://www.adafruit.com/product/2488), but the same applies to an Arduino

- &nbsp;Connect&nbsp;**board VCC (red wire)** to&nbsp; **Arduino**  **5V** &nbsp;if you are running a **5V** board Arduino (Uno, etc.).&nbsp;If your board is **3V,** connect to that instead.
- Connect **board** **GND (black wire)&nbsp;**to&nbsp; **Arduino**  **GND**
- Connect **board** **SCL (yellow wire)&nbsp;**to&nbsp; **Arduino**  **SCL**
- Connect **board** **SDA (blue wire)&nbsp;**to&nbsp; **Arduino**  **SDA**

![sensors_arduino_QT_wiring.png](https://cdn-learn.adafruit.com/assets/assets/000/083/285/medium640/sensors_arduino_QT_wiring.png?1572467808)

![sensors_arduino_BB_wiring.png](https://cdn-learn.adafruit.com/assets/assets/000/083/286/medium640/sensors_arduino_BB_wiring.png?1572467842)

## Library Installation

Once wired up, to start using the MPU-6050 you'll need to install the [Adafruit\_MPU6050 library](https://github.com/adafruit/Adafruit_MPU6050). The library is available through the Arduino library manager so we recommend taking that approach.

From the Arduino IDE, open up the Library Manager:

![](https://cdn-learn.adafruit.com/assets/assets/000/083/142/medium800/sensors_library_manager_menu.png?1572303185)

Click the&nbsp; **Manage Libraries ...** &nbsp;menu item, search for&nbsp; **Adafruit MPU6050** ,&nbsp;and select the&nbsp; **Adafruit MPU6050** &nbsp;library and click **Install** :

![](https://cdn-learn.adafruit.com/assets/assets/000/083/143/medium800/sensors_lib_manager.png?1572303701)

Then follow the same process for the **Adafruit BusIO** library.

![](https://cdn-learn.adafruit.com/assets/assets/000/083/305/medium800/sensors_BusIO_Lib_Manager.png?1572471026)

Lastly find and install the **Adafruit Unified Sensor** library

![](https://cdn-learn.adafruit.com/assets/assets/000/083/304/medium800/sensors_Unified_Sensor_LibMGR.png?1572470995)

## Basic Reading Example

Open up&nbsp; **File -\> Examples -\> Adafruit MPU6050**  **-\> basic\_readings&nbsp;** and upload to your Arduino wired up to the sensor.

One you've uploaded the sketch to your board open up the Serial Monitor ( **Tools-\>Serial Monitor** ) at **115200 baud**. You should see the acceleration, rotation measurements, and temperature being printed like so:

![](https://cdn-learn.adafruit.com/assets/assets/000/083/145/medium800/sensors_ard_basic_output.png?1572304871)

Give the sensor a wiggle or a spin and watch how the measurements change!

# Basic Readings Example Code
https://github.com/adafruit/Adafruit_MPU6050/blob/master/examples/basic_readings/basic_readings.ino

# MPU6050 6-DoF Accelerometer and Gyro

## Arduino Docs

# MPU6050 6-DoF Accelerometer and Gyro

## Python and CircuitPython

It's easy to use the MPU6050 sensor with CircuitPython and the [Adafruit CircuitPython MPU6050](https://github.com/adafruit/Adafruit_CircuitPython_MPU6050) library.&nbsp; This library allows you to easily write Python code that reads the acceleration and adjust the measurement settings.  
  
You can use this sensor with any CircuitPython microcontroller board or with a Linux single board computer that has GPIO and Python&nbsp;[thanks to Adafruit\_Blinka, our CircuitPython-for-Python compatibility library](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux).

## CircuitPython Microcontroller Wiring

First wire up a MPU6050 to your board exactly as follows. Here is an example of the MPU6050 wired to a [Feather](https://www.adafruit.com/product/3857) using I2C:

- **Board 3V** &nbsp;to&nbsp;**sensor VIN (red wire)**
- **Board GND** &nbsp;to&nbsp;**sensor GND (black wire)**
- **Board SCL** &nbsp;to&nbsp;**sensor SCL (yellow wire)**
- **Board SDA** &nbsp;to&nbsp;**sensor SDA (blue wire)**

![sensors_cpy_feather_QT_wiring.png](https://cdn-learn.adafruit.com/assets/assets/000/083/287/medium640/sensors_cpy_feather_QT_wiring.png?1572467891)

![sensors_cpy_feather_BB_wiring.png](https://cdn-learn.adafruit.com/assets/assets/000/083/288/medium640/sensors_cpy_feather_BB_wiring.png?1572467966)

## Python Computer Wiring

Since there's&nbsp;_dozens_&nbsp;of Linux computers/boards you can use we will show wiring for [Raspberry Pi](https://www.adafruit.com/product/3055). For other platforms,&nbsp;[please visit the guide for CircuitPython on Linux to see whether your platform is supported](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux).&nbsp;

Here's the Raspberry Pi wired with I2C:

- **Pi 3V** &nbsp;to&nbsp;**sensor VCC (red wire)**
- **Pi GND** &nbsp;to&nbsp;**sensor GND (black wire)**
- **Pi SCL** &nbsp;to&nbsp;**sensor SCL (yellow wire)**
- **Pi SDA** &nbsp;to&nbsp;**sensor SDA (blue wire)**

![sensors_cpy_rpi_QT_wiring.png](https://cdn-learn.adafruit.com/assets/assets/000/083/289/medium640/sensors_cpy_rpi_QT_wiring.png?1572468002)

![sensors_cpy_rpi_BB_wiring.png](https://cdn-learn.adafruit.com/assets/assets/000/083/290/medium640/sensors_cpy_rpi_BB_wiring.png?1572468047)

## CircuitPython Installation of MPU6050 Library

You'll need to install the&nbsp;[Adafruit CircuitPython MPU6050](https://github.com/adafruit/Adafruit_CircuitPython_MPU6050) library on your CircuitPython board.

First make sure you are running the&nbsp;[latest version of Adafruit CircuitPython](https://learn.adafruit.com/welcome-to-circuitpython/installing-circuitpython)&nbsp;for your board.

Next you'll need to install the necessary libraries&nbsp;to use the hardware--carefully follow the steps to find and install these libraries from&nbsp;[Adafruit's CircuitPython library bundle](https://circuitpython.org/libraries).&nbsp; Our CircuitPython starter guide has [a great page on how to install the library bundle](https://learn.adafruit.com/welcome-to-circuitpython/circuitpython-libraries).

For non-express boards like the Trinket M0 or Gemma M0, you'll need to manually install the necessary libraries from the bundle:

- **adafruit\_mpu6050.mpy**
- **adafruit\_bus\_device**
- **adafruit\_register**

Before continuing make sure your board's **lib** folder or root filesystem has the&nbsp; **adafruit\_mpu6050.mpy,**  **adafruit\_bus\_device** , and&nbsp; **adafruit\_register** files and folders **&nbsp;** copied over.

Next&nbsp;[connect to the board's serial REPL&nbsp;](https://learn.adafruit.com/welcome-to-circuitpython/the-repl)so you are at the CircuitPython&nbsp;`>>>`&nbsp;prompt.

## Python Installation of MPU6050 Library

You'll need to install the **Adafruit\_Blinka** library that provides the CircuitPython support in Python. This may also require enabling I2C on your platform and verifying you are running Python 3.&nbsp;[Since each platform is a little different, and Linux changes often, please visit the CircuitPython on Linux guide to get your computer ready](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux)!

Once that's done, from your command line run the following command:

- `sudo pip3 install adafruit-circuitpython-mpu6050`

If your default Python is version 3 you may need to run 'pip' instead. Just make sure you aren't trying to use CircuitPython on Python 2.x, it isn't supported!

## CircuitPython & Python Usage

To demonstrate the usage of the sensor we'll initialize it and read the acceleration, rotation, and temperature measurements from the board's Python REPL.

Run the following code to import the necessary modules and initialize the I2C connection with the sensor:

```python
import time
import board
import adafruit_mpu6050

i2c = board.I2C()
mpu = adafruit_mpu6050.MPU6050(i2c)
```

![](https://cdn-learn.adafruit.com/assets/assets/000/102/064/medium800/sensors_mpu6050.png?1620650479)

Now you're ready to read values from the sensor using these properties:

- **acceleration -** The acceleration forces in the X, Y, and Z axes in m/s <sup>2</sup>
- **gyro** - The rotation measurement on the X, Y, and Z axes in degrees/sec
- **temperature** - The temperature of the sensor in degrees C

For example, to print out the acceleration, gyro, and temperature values:

![](https://cdn-learn.adafruit.com/assets/assets/000/083/156/medium800/sensors_repl_properties.png?1572306401)

That's all there is to it! Go forth and imbue your robot friends with the gift of being able to maybe not fall down all the time. Maybe.

# **Example Code**
https://github.com/adafruit/Adafruit_CircuitPython_MPU6050/blob/main/examples/mpu6050_simpletest.py

# MPU6050 6-DoF Accelerometer and Gyro

## Python Docs

# MPU6050 6-DoF Accelerometer and Gyro

## Downloads

## Files

- [MPU6050 Datasheet](http://www.invensense.com/wp-content/uploads/2015/02/MPU-6000-Datasheet1.pdf)
- [MPU6050 Register Map](https://www.invensense.com/wp-content/uploads/2015/02/MPU-6000-Register-Map1.pdf)
- [EagleCAD files on GitHub](https://github.com/adafruit/Adafruit-MPU6050-PCB)
- [Fritzing object in Adafruit Fritzing Library](https://github.com/adafruit/Fritzing-Library/raw/master/parts/Adafruit%20MPU6050.fzpz)

## Schematic
![](https://cdn-learn.adafruit.com/assets/assets/000/083/292/medium800/sensors_schematic.png?1572469262)

## Fab Print
![](https://cdn-learn.adafruit.com/assets/assets/000/083/295/medium800/sensors_fab.png?1572469347)


## Primary Products

### Adafruit MPU-6050 6-DoF Accel and Gyro Sensor - STEMMA QT Qwiic

[Adafruit MPU-6050 6-DoF Accel and Gyro Sensor - STEMMA QT Qwiic](https://www.adafruit.com/product/3886)
I mew, you mew we&nbsp;_all_&nbsp;mew for IMU! The MPU-6050 is what we call "an oldie but goodie" - this popular triple-axis accelerometer plus gyro combo has been a staple of electronic projects for years, and we've finally gotten around to making a breakout for...

Out of Stock
[Buy Now](https://www.adafruit.com/product/3886)
[Related Guides to the Product](https://learn.adafruit.com/products/3886/guides)

## Featured Products

### STEMMA QT / Qwiic JST SH 4-pin to Premium Male Headers Cable

[STEMMA QT / Qwiic JST SH 4-pin to Premium Male Headers Cable](https://www.adafruit.com/product/4209)
This 4-wire cable is a little over 150mm / 6" long and fitted with JST-SH female 4-pin connectors on one end and premium Dupont male headers on the other. Compared with the chunkier JST-PH these are 1mm pitch instead of 2mm, but still have a nice latching feel, while being easy to insert...

In Stock
[Buy Now](https://www.adafruit.com/product/4209)
[Related Guides to the Product](https://learn.adafruit.com/products/4209/guides)
### STEMMA QT / Qwiic JST SH 4-pin Cable - 100mm Long

[STEMMA QT / Qwiic JST SH 4-pin Cable - 100mm Long](https://www.adafruit.com/product/4210)
This 4-wire cable is a little over 100mm / 4" long and fitted with JST-SH female 4-pin connectors on both ends. Compared with the chunkier JST-PH these are 1mm pitch instead of 2mm, but still have a nice latching feel, while being easy to insert and remove.

<a...></a...>

Out of Stock
[Buy Now](https://www.adafruit.com/product/4210)
[Related Guides to the Product](https://learn.adafruit.com/products/4210/guides)

## Related Guides

- [Adafruit SensorLab - Gyroscope Calibration](https://learn.adafruit.com/adafruit-sensorlab-gyroscope-calibration.md)
- [Textile Potentiometer Hoodie](https://learn.adafruit.com/textile-potentiometer-hoodie.md)
- [Adafruit SCD-30 - NDIR CO2 Temperature and Humidity Sensor](https://learn.adafruit.com/adafruit-scd30.md)
- [Introducing Bluefruit EZ-Key](https://learn.adafruit.com/introducing-bluefruit-ez-key-diy-bluetooth-hid-keyboard.md)
- [Adafruit SensorLab - Magnetometer Calibration](https://learn.adafruit.com/adafruit-sensorlab-magnetometer-calibration.md)
- [3D-Printed Bionic Eye](https://learn.adafruit.com/3d-printed-bionic-eye.md)
- [Adafruit 2.8" and 3.2" Color TFT Touchscreen Breakout v2](https://learn.adafruit.com/adafruit-2-8-and-3-2-color-tft-touchscreen-breakout-v2.md)
- [Joy Featherwing](https://learn.adafruit.com/joy-featherwing.md)
- [Quickstart: Adafruit IO WipperSnapper ](https://learn.adafruit.com/quickstart-adafruit-io-wippersnapper.md)
- [Adafruit STM32F405 Feather Express](https://learn.adafruit.com/adafruit-stm32f405-feather-express.md)
- [Adafruit PyBadge and PyBadge LC](https://learn.adafruit.com/adafruit-pybadge.md)
- [Adafruit Feather RP2040 ThinkInk](https://learn.adafruit.com/adafruit-rp2040-feather-thinkink.md)
- [Adafruit Feather HUZZAH ESP8266](https://learn.adafruit.com/adafruit-feather-huzzah-esp8266.md)
- [Adafruit EYESPI Breakout Board](https://learn.adafruit.com/adafruit-eyespi-breakout-board.md)
- [Adafruit HMC5883L Breakout - Triple-Axis Magnetometer Compass Sensor](https://learn.adafruit.com/adafruit-hmc5883l-breakout-triple-axis-magnetometer-compass-sensor.md)
