Arduino MPU6050 Raw Accelerometer (I2Cdev): Wiring, Code and Simulator

To build this Arduino MPU6050 Raw Accelerometer (I2Cdev) project you need an Arduino Uno and an MPU6050 accelerometer. The Electronic Cats MPU6050 library reads raw accelerometer counts: 16384 per g. Make the 4 connections in the wiring table, upload the Arduino C++ code, and move the accel sliders and divide by 16384.0 to print g.

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 and divide by 16384.0 to print g.

Arduino C++ code

// MPU6050 (Electronic Cats / I2Cdev): raw accelerometer counts, 16384 per g.
#include <Wire.h>
#include <MPU6050.h>

MPU6050 mpu;

void setup() {
  Serial.begin(9600);
  Wire.begin();
  mpu.initialize();
  Serial.println(mpu.testConnection() ? "MPU6050 connected." : "MPU6050 not found.");
}

void loop() {
  int16_t ax, ay, az;
  mpu.getAcceleration(&ax, &ay, &az);
  Serial.print("ax=");
  Serial.print(ax);
  Serial.print(" az=");
  Serial.println(az);
  delay(300);
}

What to try

Move the accel sliders and divide by 16384.0 to print g.

Frequently asked questions

How do I wire the MPU6050 Raw Accelerometer (I2Cdev) 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 Electronic Cats MPU6050 library reads raw accelerometer counts: 16384 per g.

More Arduino Uno projects