> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/wokwi/wokwi-docs/llms.txt
> Use this file to discover all available pages before exploring further.

# MPU6050 6-Axis Accelerometer & Gyroscope

> 3-axis accelerometer, 3-axis gyroscope and temperature sensor with I2C interface

Integrated sensor with 3-axis accelerometer, 3-axis gyroscope and a temperature sensor with I2C interface.

## Pin names

<ParamField path="VCC" type="Power">
  Voltage supply
</ParamField>

<ParamField path="GND" type="Ground">
  Ground
</ParamField>

<ParamField path="SCL" type="I2C">
  I2C clock line
</ParamField>

<ParamField path="SDA" type="I2C">
  I2C data line
</ParamField>

<ParamField path="XDA" type="Not Implemented">
  Unused - not currently implemented in the simulator
</ParamField>

<ParamField path="XCL" type="Not Implemented">
  Unused - not currently implemented in the simulator
</ParamField>

<ParamField path="AD0" type="Digital Input">
  Address select pin
</ParamField>

<ParamField path="INT" type="Digital Output">
  Interrupt
</ParamField>

<Note>
  The XDA and XCL pins are not currently implemented in the simulator. If you need them, please [open a request](https://github.com/wokwi/wokwi-features/issues/new), and describe your use case.
</Note>

You normally only need to connect the VCC, GND, SCL, and SDA pins. The I2C address of the device is 0x68. You can change the address of 0x69 by connecting the AD0 pin to VCC.

## Attributes

<ParamField path="accelX" type="string" default="0">
  Initial x acceleration value (g)
</ParamField>

<ParamField path="accelY" type="string" default="0">
  Initial y acceleration value (g)
</ParamField>

<ParamField path="accelZ" type="string" default="1">
  Initial z acceleration value (g)
</ParamField>

<ParamField path="rotationX" type="string" default="0">
  Initial x rotation value (deg/sec)
</ParamField>

<ParamField path="rotationY" type="string" default="0">
  Initial y rotation value (deg/sec)
</ParamField>

<ParamField path="rotationZ" type="string" default="0">
  Initial z rotation value (deg/sec)
</ParamField>

<ParamField path="temperature" type="string" default="24">
  Initial temperature value (celsius)
</ParamField>

## Units

All the acceleration values (x/y/z) use g-force units, where 1g = 9.80665 m/s². The gyroscope measures angular rotation and returns the number of degrees per second.

## Arduino code example

The example below uses the Adafruit MPU6050 library to read and display the acceleration values from the sensor. On Arduino Uno, connect the SDA pin to A4, and the SCL pin to A5.

```cpp theme={null}
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>

Adafruit_MPU6050 mpu;

void setup(void) {
  Serial.begin(115200);

  while (!mpu.begin()) {
    Serial.println("MPU6050 not connected!");
    delay(1000);
  }
  Serial.println("MPU6050 ready!");
}

sensors_event_t event;

void loop() {
  mpu.getAccelerometerSensor()->getEvent(&event);

  Serial.print("[");
  Serial.print(millis());
  Serial.print("] X: ");
  Serial.print(event.acceleration.x);
  Serial.print(", Y: ");
  Serial.print(event.acceleration.y);
  Serial.print(", Z: ");
  Serial.print(event.acceleration.z);
  Serial.println(" m/s^2");
  delay(500);
}
```

[Run this example on Wokwi](https://wokwi.com/projects/305937248748044864)

## Automation controls

The mpu6050 sensor can be controlled using [Automation Scenarios](/wokwi-ci/automation-scenarios). The names of the controls match the names of the attributes defined above:

<ParamField path="accelX" type="float">
  Set the x acceleration value (g)
</ParamField>

<ParamField path="accelY" type="float">
  Set the y acceleration value (g)
</ParamField>

<ParamField path="accelZ" type="float">
  Set the z acceleration value (g)
</ParamField>

<ParamField path="rotationX" type="float">
  Set the x rotation value (deg/sec)
</ParamField>

<ParamField path="rotationY" type="float">
  Set the y rotation value (deg/sec)
</ParamField>

<ParamField path="rotationZ" type="float">
  Set the z rotation value (deg/sec)
</ParamField>

<ParamField path="temperature" type="float">
  Set the temperature value (celsius)
</ParamField>

The following example set the temperature to 25°C:

```yaml theme={null}
- set-control:
    part-id: imu1
    control: temperature
    value: 25
```

## Simulator examples

* [MPU6050 X/Y/Z acceleration plotter](https://wokwi.com/projects/305937156771152449)
* [Adafruit MPU6050 Demo](https://wokwi.com/projects/305936654686749250)
* [3D gyro/acceleration visualization on an OLED display](https://wokwi.com/projects/306115576172905024)
* [3D Wokwi "W" controlled by Gyroscope rotation](https://wokwi.com/projects/306399551789466177)
* [ESP32 with many MPU6050 sensors](https://wokwi.com/projects/394777263927329793)
