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
| Qty | Part | What it does |
|---|---|---|
| 1 | Arduino Uno | the microcontroller board |
| 1 | MPU6050 accelerometer | Accelerometer + 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
| # | From | To |
|---|---|---|
| 1 | Arduino Uno 5V | MPU6050 accelerometer VCC |
| 2 | Arduino Uno GND | MPU6050 accelerometer GND |
| 3 | Arduino Uno A4 | MPU6050 accelerometer SDA |
| 4 | Arduino Uno A5 | MPU6050 accelerometer SCL |
Step by step
- Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the Arduino Uno. No install or account is needed.
- Add the parts. Add an MPU6050 accelerometer from the parts palette.
- Wire 1. Connect Arduino Uno 5V to MPU6050 accelerometer VCC.
- Wire 2. Connect Arduino Uno GND to MPU6050 accelerometer GND.
- Wire 3. Connect Arduino Uno A4 to MPU6050 accelerometer SDA.
- Wire 4. Connect Arduino Uno A5 to MPU6050 accelerometer SCL.
- Paste the Arduino C++ code. Paste the Arduino C++ code below into the code editor.
- 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
- Arduino LED Blink: Wiring, Code and Simulator
- Arduino LDR Light Sensor: Wiring, Code and Simulator
- Arduino NTC Thermistor Thermometer: Wiring, Code and Simulator
- Arduino PWM to Analog RC Filter: Wiring, Code and Simulator
- Arduino Capacitance Meter: Wiring, Code and Simulator
- Arduino DC Motor PWM Speed Control with MOSFET: Wiring, Code and Simulator