Connecting an Arduino Uno to an MPU6050 via I2C: A Step‑by‑Step Guide
Learn how to wire an Arduino Uno to an MPU6050 accelerometer/gyroscope over I2C, upload a minimal sketch, verify serial output, and troubleshoot common pitfalls in a clear, step‑by‑step guide.
08 Apr 2026, 18:24 UTC

Desired Outcome
By the end of this guide you will have a fully functional Arduino Uno that reads raw acceleration and gyroscope values from an MPU6050 sensor over the I2C bus. You will be able to verify the connection with a serial monitor and troubleshoot common issues.
Prerequisites
- Arduino Uno (or any AVR‑based board with Wire library)
- MPU6050 accelerometer/gyroscope breakout
- 10 kΩ pull‑up resistors (one for SDA, one for SCL)
- Jumper wires and a breadboard
- Arduino IDE 2.x or 1.8.x
- Basic familiarity with the IDE and uploading sketches
Wiring
The MPU6050 uses only two signal lines for I2C, which keeps pin usage minimal. Connect the board as follows:
| MPU6050 Pin | Arduino Pin |
|---|---|
| VCC | 5V |
| GND | GND |
| SCL | Pin A5 (SCL) |
| SDA | Pin A4 (SDA) |
| INT | Not used for this example |
Place a 10 kΩ resistor between VCC and SDA, and another between VCC and SCL. These pull‑ups are required for proper I2C signalling.
Library Setup
Open the Arduino IDE and install the Wire library if it isn’t already included. The MPU6050 does not require a dedicated library for basic register reads; we will use Wire directly.
Sketch Structure
Below is a minimal example that initialises the sensor, reads 14 bytes from the data registers, and prints the raw values to the Serial Monitor. Replace the placeholder comments with your own logic if needed.
#include <Wire.h>
// MPU6050 I2C address (default)
const uint8_t MPU_ADDR = 0x68;
// Register addresses
const uint8_t ACCEL_XOUT_H = 0x3B;
void setup() {
Serial.begin(115200);
while (!Serial) ; // wait for serial
Wire.begin(); // join the I2C bus
// Wake the MPU6050 from sleep mode
Wire.beginTransmission(MPU_ADDR);
Wire.write(0x6B); // PWR_MGMT_1 register
Wire.write(0x00); // set to zero (wakes up)
uint8_t status = Wire.endTransmission();
if (status != 0) {
Serial.print("I2C init error: ");
Serial.println(status);
}
}
void loop() {
int16_t accel[3];
int16_t gyro[3];
// Request 14 bytes starting at ACCEL_XOUT_H
Wire.beginTransmission(MPU_ADDR);
Wire.write(ACCEL_XOUT_H);
Wire.endTransmission(false); // restart for read
Wire.requestFrom(MPU_ADDR, (uint8_t)14);
if (Wire.available() == 14) {
accel[0] = Wire.read() << 8 | Wire.read();
accel[1] = Wire.read() << 8 | Wire.read();
accel[2] = Wire.read() << 8 | Wire.read();
gyro[0] = Wire.read() << 8 | Wire.read();
gyro[1] = Wire.read() << 8 | Wire.read();
gyro[2] = Wire.read() << 8 | Wire.read();
}
Serial.print("Acc:");
Serial.print(accel[0]); Serial.print(",");
Serial.print(accel[1]); Serial.print(",");
Serial.println(accel[2]);
Serial.print("Gyro:");
Serial.print(gyro[0]); Serial.print(",");
Serial.print(gyro[1]); Serial.print(",");
Serial.println(gyro[2]);
delay(500);
}
Verifying the Connection
- Upload the sketch. The IDE will compile and flash the code to the Uno. Ensure the board is connected via USB and the correct port is selected.
- Open the Serial Monitor. Set the baud rate to 115200. You should see lines of acceleration and gyroscope values scrolling every 500 ms.
- Move the board. The numbers should change as you tilt or rotate the sensor. Static values close to zero indicate correct wiring.
- Run an I2C scanner. If no data appears, upload a standard I2C scanner sketch and confirm that the device responds at address 0x68.
Troubleshooting Common Issues
- No data in Serial Monitor. Verify pull‑up resistors are correctly placed. Without them, the I2C bus will not acknowledge.
- Wrong I2C address. The MPU6050 can be set to 0x69 by pulling the AD0 pin high. Check the datasheet if you have modified the address.
- Wire.endTransmission() returns non‑zero. This indicates a bus error. Check for short circuits on SDA/SCL lines and ensure the sensor is powered.
- Serial Monitor shows garbage. Ensure the baud rate matches the sketch (115200). Mismatched rates scramble output.
Recovery Options
If you suspect the sensor is damaged or the board is stuck in a bad state, power cycle the Arduino and unplug the sensor. Re‑upload the sketch after confirming the I2C scanner reports the sensor. If the scanner still fails, test the sensor on a different board or replace the pull‑ups.
Limitations and Practical Checks
The raw values from the MPU6050 are in sensor units (counts). To convert to g or degrees per second, divide by the appropriate sensitivity scale factor (e.g., accel 16384 counts/g for ±2g). This guide focuses on establishing communication; calibration and scaling are left as an exercise.
Always check that the sensor’s VCC pin is connected to 5 V on the Uno. Some breakout boards default to 3.3 V and will not work with a 5 V supply. Use a voltage regulator or level shifter if necessary.
When writing production code, consider adding a timeout to Wire.requestFrom() to avoid hanging if the sensor becomes unresponsive.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.