MPU6050 I2C Build

MPU6050 I2C Build

Arduino/ESP32 I2C Example

The transaction diagrams and address explorer above are the beginner path. Use this sketch only when you are ready to test a real I2C sensor.

Look at the blue sensor board before the build checklist. The edge labels show VCC, GND, SCL, and SDA, with other pins beside them and a mounting hole near each end.

Real photograph of mpu6050 6-axis imu (accelerometer + gyroscope)
This real example (GY-521 MPU-6050 Module 3 Axis Gyroscope + Accelerometer 0487) shows a physical form of mpu6050 6-axis imu (accelerometer + gyroscope). Use the visible package, interfaces, scale, mounting, and surrounding context as evidence; a catalogue label alone does not establish deployment fit. Photo: Nevit Dilmen (talk); CC BY-SA 3.0

Use the visible labels to locate the four basic connections, then confirm the board’s voltage and pinout from its specification before powering it. The photo cannot prove the installed wiring or the scanner result; the checklist below supplies those tests.

Task I2C concept being tested Success evidence
Wire SDA/SCL correctly Shared two-wire bus Scanner detects 0x68 or 0x69.
Wake the sensor Write transaction to a control register The device stops reporting sleep/default values.
Select the X-axis register Write phase before a register read Logic trace shows address + write, register byte, repeated START.
Read two data bytes Repeated START and read phase Two bytes arrive and combine into a signed acceleration value.
Repeat slowly first Stable bus before performance tuning Values update without missing ACKs or bus lockups.

Before wiring anything, it helps to recognise the board this checklist assumes. Figure 1 shows one, with every pin you will touch printed beside it.

A small blue GY-521 breakout board carrying an MPU6050 6-axis motion sensor chip, with a row of pin headers along one edge
Figure 1: A GY-521 breakout carrying the MPU6050 – the board this checklist wires up. The scanner step above is checking for exactly this chip’s I2C address, 0x68 by default or 0x69 with AD0 pulled high. Photo: Nevit Dilmen, CC BY-SA 3.0

Read the printed labels down the left edge of Figure 1. Power and ground come first, then SCL and SDA, the only two signal wires this bus needs and the pair the scanner step drives. Four pins further down are the ones beginners mis-wire. XDA and XCL are a second bus for an extra sensor, not spares for the first. AD0 is the address select: leave it alone and the chip answers at 0x68, pull it high and it answers at 0x69, which is exactly the difference the scanner reports. The chip in the middle carries its own part number, so a board can be identified from a photo before any code runs.

ESP32 wiring reference:

ESP32 pin Sensor pin Note
GPIO 21 SDA Data line; add a pull-up if the sensor board lacks one.
GPIO 22 SCL Clock line; keep wires short for reliable fast mode.
3.3 V VCC Match the sensor module voltage.
GND GND All I2C devices need a shared ground.

Back to the chapter