Skip to content

Read an MPU6050 over I2C

Read acceleration on three axes using an I2C register transaction.

Physics Phoebe, your practice guide

Physics Phoebe
Predict the reading, then compare it with the measurement.

Wokwi ESP32

Third party Tool

Tier 2 · Web · paste-in setup · Account needed to save a project

Version tested: Compiled with arduino-cli 1.5.2-rc.1 for esp32 core 3.3.11; booted headlessly with wokwi-cli 0.26.1 on 2026-09-07; serial line 'Ax=0.000 g, Ay=0.000 g, Az=1.000 g' seen at 7.268 s (wall time from CLI start; scenario timeout 20 s simulated time); captured in the Wokwi web editor on 2026-09-09. Date: 2026-09-06.

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

diagram.json

871 bytes · Circuit connections

Download

sketch.ino

600 bytes · ESP32 program

Download

  1. Use the launch button above to open the ESP32 editor in Wokwi.
  2. Select the editor’s diagram.json tab and replace all its text with the supplied diagram.json.
  3. Select the sketch.ino tab, replace all its text with the supplied sketch.ino, then click Start Simulation.

Steps

Screens captured against Wokwi ESP32 Compiled with arduino-cli 1.5.2-rc.1 for esp32 core 3.3.11; booted headlessly with wokwi-cli 0.26.1 on 2026-09-07; serial line 'Ax=0.000 g, Ay=0.000 g, Az=1.000 g' seen at 7.268 s (wall time from CLI start; scenario timeout 20 s simulated time); captured in the Wokwi web editor on 2026-09-09 on 2026-09-06; the tool may have moved on — the text steps are the contract.

  1. 1 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: The sensor power, ground, and signal wiring connect to the ESP32. The ring marks the sensor.
    Step 1 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  2. 2 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: The named source lines show the sampling and conversion calculations. The ring marks those code lines.
    Step 2 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  3. 3 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: The simulation is running and Serial Monitor is open. The ring marks the Stop control.
    Step 3 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  4. 4 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: Stationary acceleration is 0, 0, and 1 g. The ring marks the three axes.
    Step 4 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  5. 5 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: X acceleration changes to 0.500 g while Z remains 1.000 g. The ring marks the axes.
    Step 5 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  6. 6 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: Z acceleration changes to 0.000 g. The ring marks the axes.
    Step 6 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  7. 7 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: The baseline 0, 0, and 1 g readings return. The ring marks the restored axes.
    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.

  1. What physically moves inside a MEMS capacitive accelerometer when the device accelerates?

    Return to the chapter’s knowledge check
  2. Why can a single MEMS accelerometer not distinguish a slow tilt from a genuine horizontal acceleration?

    Return to the chapter’s knowledge check

Caution

Tool versions change and screens may differ. Reopen the supplied setup, check the tool documentation, and use the site feedback control if the problem remains. The screenshots show browser measurements, not hardware calibration; values may vary slightly between runs.

Return to Protocol Diagnostics and Bus Design · Browse Labs