Read an MPU6050 over I2C
Read acceleration on three axes using an I2C register transaction.

Physics Phoebe
Predict the reading, then compare it with the measurement.
Wokwi ESP32
Third party ToolOpen the ESP32 editor, paste diagram.json, then paste sketch.ino.
Open Wokwi to paste in the files (new tab)Get the files
Use both prepared files. This is a paste-in setup; saving a project requires a Wokwi account.
sketch.ino
- Use the launch button above to open the ESP32 editor in Wokwi.
- Select the editor’s diagram.json tab and replace all its text with the supplied diagram.json.
- Select the sketch.ino tab, replace all its text with the supplied sketch.ino, then click Start Simulation.
Steps
Step 1
- Do
- In the Simulation panel, inspect the MPU6050 wiring after pasting both supplied files.
- You will see
- Input: inspect diagram.json and the running Wokwi circuit. MPU6050 power and ground connect to the ESP32 supply and ground. SDA reaches GPIO 21 and SCL reaches GPIO 22. Serial Monitor reports stationary Ax=0.000 g, Ay=0.000 g, Az=1.000 g.
- Why it matters
- The green and blue leads define the I2C data and clock paths. The circuit links one IMU to the live three-axis readout. The stationary Z value reflects this simulator orientation. Wiring inspection does not measure physical sensor accuracy.

Step 1 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) Step 2
- Do
- In the sketch.ino editor tab, find the address 0x68 and the acceleration divisions by 16384.0.
- You will see
- Input: inspect sketch.ino beside the active Wokwi simulation. The code opens I2C at address 0x68. It requests six bytes and divides signed axes by 16384.0. Serial Monitor prints Ax=0.000 g, Ay=0.000 g, Az=1.000 g.
- Why it matters
- The address and six-byte read identify the accelerometer transaction. The divisor maps the configured raw counts into g units. The stationary run produces zero X/Y and one g on Z. Changing range without changing scale would misstate motion.

Step 2 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) Step 3
- Do
- In the Simulation toolbar, click the play button and wait for compilation.
- You will see
- Input: click Start the simulation in the real Wokwi editor. The toolbar shows Stop and the clock reaches 00:07.199. Serial Monitor reports Wake status=0 (0 means ACK). It then prints Ax=0.000 g, Ay=0.000 g, Az=1.000 g.
- Why it matters
- The visible Stop control confirms a running simulation. The ACK line precedes the axis readings. The baseline values can be checked in the same tool window. This does not calibrate a physical IMU.

Step 3 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) Step 4
- Do
- In the Serial Monitor panel, compare Ax, Ay, and Az with the expected stationary readings.
- You will see
- Input: leave the MPU6050 at its stationary defaults. Observed: "Wake status=0 (0 means ACK)". Observed: "Ax=0.000 g, Ay=0.000 g, Az=1.000 g". Expected: zero X/Y and one g on Z.
- Why it matters
- ACK indicates the simulated I2C wake request succeeded. The axes match the stationary screenshot. Z measures gravity in this fixture orientation. This is simulated acceleration, not hardware calibration.

Step 4 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) Step 5
- Do
- In the Simulation panel, select the MPU6050 and set X acceleration to 0.5 g.
- You will see
- Input: set X acceleration to 0.5 g in the MPU6050 panel. Observed: "Ax=0.500 g, Ay=0.000 g, Az=1.000 g". Expected: only X rises by 0.500 g. The panel control read 0.5 during this run.
- Why it matters
- The changed X value reached the firmware I2C read. Y remained at zero and Z at one g. The run isolates one axis from the others. This does not test sensor noise or scale error.

Step 5 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) Step 6
- Do
- In the MPU6050 control panel, set Z acceleration to 0 g.
- You will see
- Input: keep X at 0.5 g and set Z acceleration to 0 g. Observed: "Ax=0.500 g, Ay=0.000 g, Az=0.000 g". Expected: Z falls to zero while X stays at 0.500 g. The panel control read Z=0 during this run.
- Why it matters
- The second axis change is visible independently. The serial axes match the screenshot values. The zero is a controlled simulator setting. No physical tilt or motion is measured.

Step 6 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) Step 7
- Do
- In the MPU6050 control panel, restore X acceleration to 0 g and Z acceleration to 1 g.
- You will see
- Input: restore X to 0 g and Z to 1 g in the MPU6050 panel. Observed: "Ax=0.000 g, Ay=0.000 g, Az=1.000 g". Expected: the original stationary three-axis line returns. Both panel controls showed their initial values again.
- Why it matters
- The final line repeats the baseline within displayed precision. This closes the change-and-restore comparison. The unchanged Y axis is a control for the exercise. The result is limited to this simulator run.

Step 7 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
Chapter checks
These questions refer to the chapter’s examples. Use the return links to review their answers.
What physically moves inside a MEMS capacitive accelerometer when the device accelerates?
Return to the chapter’s knowledge checkWhy can a single MEMS accelerometer not distinguish a slow tilt from a genuine horizontal acceleration?
Return to the chapter’s knowledge check