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.
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.
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. |