Read Motion with MPU6050 (Arduino)
Read acceleration and rotation from an MPU6050 6-axis IMU over I²C — the heart of tilt, gesture, and balancing projects.
Intermediate25 min
What you need
Wiring
Hover a pin or a wire to trace the connection.
Code
mpu6050.ino
// Print acceleration (m/s^2) from an MPU6050 over I2C.
// Install "Adafruit MPU6050" + "Adafruit Unified Sensor".
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
Adafruit_MPU6050 mpu;
void setup() {
Serial.begin(9600);
if (!mpu.begin()) {
Serial.println("MPU6050 not found");
while (1);
}
}
void loop() {
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
Serial.print("Accel X:"); Serial.print(a.acceleration.x);
Serial.print(" Y:"); Serial.print(a.acceleration.y);
Serial.print(" Z:"); Serial.println(a.acceleration.z);
delay(300);
}
Steps
- Install "Adafruit MPU6050" and "Adafruit Unified Sensor".
- Wire: VCC to 5V, GND to GND, SDA to A4, SCL to A5.
- Upload and open the Serial Monitor — tilt the board and watch the axes change.