Arduino MPU6050 with the Adafruit Library: Wiring, Code and Simulator

To build this Arduino MPU6050 with the Adafruit Library project you need an Arduino Uno and an MPU6050 accelerometer. The Adafruit MPU6050 library reads acceleration in m/s² through the Unified Sensor API. Make the 4 connections in the wiring table, upload the Arduino C++ code, and move the accel sliders to tilt the board and watch gravity move between axes.

Open this circuit in the free Arduino Uno simulator

Parts list

QtyPartWhat it does
1Arduino Unothe microcontroller board
1MPU6050 accelerometerAccelerometer + gyroscope on I²C at 0x68 (0x69 with AD0 set). Write 0 to register 0x6B to wake it, then read 14 bytes from 0x3B.

Wiring

#FromTo
1Arduino Uno 5VMPU6050 accelerometer VCC
2Arduino Uno GNDMPU6050 accelerometer GND
3Arduino Uno A4MPU6050 accelerometer SDA
4Arduino Uno A5MPU6050 accelerometer SCL

Step by step

  1. Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the Arduino Uno. No install or account is needed.
  2. Add the parts. Add an MPU6050 accelerometer from the parts palette.
  3. Wire 1. Connect Arduino Uno 5V to MPU6050 accelerometer VCC.
  4. Wire 2. Connect Arduino Uno GND to MPU6050 accelerometer GND.
  5. Wire 3. Connect Arduino Uno A4 to MPU6050 accelerometer SDA.
  6. Wire 4. Connect Arduino Uno A5 to MPU6050 accelerometer SCL.
  7. Paste the Arduino C++ code. Paste the Arduino C++ code below into the code editor.
  8. Run it. Press Run. Move the accel sliders to tilt the board and watch gravity move between axes.

Arduino C++ code

// Adafruit MPU6050: accelerometer in m/s^2 through the Unified Sensor API.
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>

Adafruit_MPU6050 mpu;

void setup() {
  Serial.begin(9600);
  if (!mpu.begin()) {
    Serial.println("MPU6050 not found.");
    while (true) {}
  }
  Serial.println("MPU6050 ready.");
}

void loop() {
  sensors_event_t a, g, temp;
  mpu.getEvent(&a, &g, &temp);
  Serial.print("ax=");
  Serial.print(a.acceleration.x, 1);
  Serial.print(" az=");
  Serial.println(a.acceleration.z, 1);
  delay(300);
}

What to try

Move the accel sliders to tilt the board and watch gravity move between axes.

Frequently asked questions

How do I wire the MPU6050 with the Adafruit Library project on an Arduino Uno?

Make 4 connections: Arduino Uno 5V to MPU6050 accelerometer VCC; Arduino Uno GND to MPU6050 accelerometer GND; Arduino Uno A4 to MPU6050 accelerometer SDA; Arduino Uno A5 to MPU6050 accelerometer SCL.

What parts do I need for this Arduino project?

An Arduino Uno and an MPU6050 accelerometer.

Can I simulate this Arduino project online for free?

Yes. The BitForBytes Embedded Lab runs this exact circuit and Arduino C++ code in your browser for free, with no install and no hardware. The sketch is compiled with the real Arduino toolchain and runs on an emulated ATmega328P.

What does the code do?

The Adafruit MPU6050 library reads acceleration in m/s² through the Unified Sensor API.

More Arduino Uno projects