In this easy CircuitMagic tutorial you will build measure x y z acceleration using esp32 and mpu6050 using ESP32 DevKit and one simple sensor. The project needs only a few connections and a short Arduino IDE sketch.
What does the sensor do?
The MPU6050 measures acceleration along three axes and rotation rates. A stationary board typically reads about 9.8 m/s² along the gravity-aligned axis.
Required components
ESP32 DevKit, 3.3V-compatible MPU6050 I2C breakout, jumper wires, USB cable.
Connection diagram
The diagram below is a pin-to-pin connection map: each colored line shows one separate wire between labeled terminals, not a photograph of a particular board’s header layout.

Pin connections
Unplug USB power before wiring. The pin table is authoritative; always verify your board’s printed pin labels and your module’s pinout.
| ESP32 DevKit pin / connection | MPU6050 6-axis motion sensor breakout connection |
|---|---|
| 3V3 | MPU6050 VCC |
| GND | MPU6050 GND |
| GPIO21 | MPU6050 SDA |
| GPIO22 | MPU6050 SCL |
Arduino IDE setup
Install Adafruit MPU6050 and its dependencies from Arduino IDE Library Manager. Select the matching board and serial port, then upload this sketch.
Complete Arduino code
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
Adafruit_MPU6050 mpu;
void setup() {
Serial.begin(115200);
Wire.begin(21, 22);
if (!mpu.begin()) {
Serial.println("MPU6050 not found");
while (true) delay(1000);
}
}
void loop() {
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
Serial.print("X: "); Serial.print(a.acceleration.x);
Serial.print(" Y: "); Serial.print(a.acceleration.y);
Serial.print(" Z: "); Serial.println(a.acceleration.z);
delay(500);
}
Expected output
Rotate the sensor and observe X, Y and Z acceleration changing. Open Serial Monitor at the baud rate specified by Serial.begin().
Troubleshooting
Module voltage regulator and pull-up designs differ. Use a breakout explicitly rated for 3.3V power and I2C.
If there is no output, double-check the board and port, USB data cable, common ground, sensor pin labels and Serial Monitor speed.
Try next
Once the basic example works, experiment with the sampling delay, add an LED indicator, or log the sensor output to a computer. See more CircuitMagic electronics projects for related beginner tutorials.










