ESP32 MPU6050 I2C wiring, GPIO21 SDA and GPIO22 SCL

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.

MPU6050 accelerometer wiring diagram for ESP32

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 / connectionMPU6050 6-axis motion sensor breakout connection
3V3MPU6050 VCC
GNDMPU6050 GND
GPIO21MPU6050 SDA
GPIO22MPU6050 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.

0 Comments

Leave a reply

Your email address will not be published. Required fields are marked *

*

or

Log in with your credentials

Forgot your details?