The MPU6050 is a 6-axis motion sensor — accelerometer plus gyroscope — for tilt alarms, self-balancing robots and gesture input. The GY-521 board has its own regulator and pull-ups, so it is happy on the SuperMini’s 3V3.
Wire SDA to GPIO5 and SCL to GPIO6. The sketch sets a ±4 g / ±500 °/s range with a 21 Hz filter, a sensible start for hand-held or robot use.
Wiring
| ESP32-C3 SuperMini | MPU6050 (GY-521) | Wire | Notes |
|---|---|---|---|
| 3V3 | VCC | red | |
| GND | GND | black | |
| 6 | SCL | yellow | |
| 5 | SDA | blue |
3.3–5 V (on-board 3.3 V regulator) part, 3.3 V board. The GY-521 has a 3.3 V regulator and pulls SDA/SCL up to 3.3 V, so it works on both 3.3 V boards and a 5 V Uno without a level shifter.
Board quirks
- I2C on GPIO5/6: the core’s defaults (GPIO8/9) are the SuperMini’s LED and BOOT button, both strapping pins.
- Leave AD0 open for 0x68. Tied to 3V3 it moves to 0x69 — useful for two IMUs, or when a DS3231 (also 0x68) shares the bus.
- The SuperMini is light enough to mount on the moving part itself; keep the IMU rigidly fixed, because a loose board reads as vibration.
Code
// MPU6050 (GY-521) accelerometer + gyro on an ESP32-C3 SuperMini over I2C (address 0x68).
// VCC → 3V3, GND → GND, SDA → GPIO5, SCL → GPIO6. AD0 open (0x68), INT unused.
#include <Wire.h>
#include <Adafruit_MPU6050.h>
constexpr int SDA_PIN = 5;
constexpr int SCL_PIN = 6;
Adafruit_MPU6050 mpu;
void setup() {
Serial.begin(115200);
delay(1500); // let the native USB serial port enumerate
Wire.begin(SDA_PIN, SCL_PIN); // GPIO8/9 are strapping pins on the C3 — not used for I2C
if (!mpu.begin(0x68, &Wire)) {
Serial.println("MPU6050 not found at 0x68 — check wiring (AD0 high = 0x69)");
while (true) delay(1000);
}
mpu.setAccelerometerRange(MPU6050_RANGE_4_G);
mpu.setGyroRange(MPU6050_RANGE_500_DEG);
mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);
Serial.println("MPU6050 ready");
}
void loop() {
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
Serial.printf("Accel X %.2f Y %.2f Z %.2f m/s² Gyro X %.2f Y %.2f Z %.2f rad/s %.1f °C\n",
a.acceleration.x, a.acceleration.y, a.acceleration.z,
g.gyro.x, g.gyro.y, g.gyro.z, temp.temperature);
delay(500);
}// MPU6050 (GY-521) accelerometer + gyro on an ESP32-C3 SuperMini over I2C (address 0x68).
// VCC → 3V3, GND → GND, SDA → GPIO5, SCL → GPIO6. AD0 open (0x68), INT unused.
#include <Wire.h>
#include <Adafruit_MPU6050.h>
constexpr int SDA_PIN = 5;
constexpr int SCL_PIN = 6;
Adafruit_MPU6050 mpu;
void setup() {
Serial.begin(115200);
delay(1500); // let the native USB serial port enumerate
Wire.begin(SDA_PIN, SCL_PIN); // GPIO8/9 are strapping pins on the C3 — not used for I2C
if (!mpu.begin(0x68, &Wire)) {
Serial.println("MPU6050 not found at 0x68 — check wiring (AD0 high = 0x69)");
while (true) delay(1000);
}
mpu.setAccelerometerRange(MPU6050_RANGE_4_G);
mpu.setGyroRange(MPU6050_RANGE_500_DEG);
mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);
Serial.println("MPU6050 ready");
}
void loop() {
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
Serial.printf("Accel X %.2f Y %.2f Z %.2f m/s² Gyro X %.2f Y %.2f Z %.2f rad/s %.1f °C\n",
a.acceleration.x, a.acceleration.y, a.acceleration.z,
g.gyro.x, g.gyro.y, g.gyro.z, temp.temperature);
delay(500);
}Library: Adafruit MPU6050 (Adafruit (also install Adafruit Unified Sensor and Adafruit BusIO)) — compiled with Adafruit MPU6050 2.2.9.
Expected serial output
MPU6050 ready
Accel X 0.21 Y -0.15 Z 9.79 m/s² Gyro X -0.01 Y 0.02 Z 0.00 rad/s 31.2 °C
Accel X 0.19 Y -0.14 Z 9.81 m/s² Gyro X -0.02 Y 0.01 Z 0.00 rad/s 31.2 °CMPU6050 ready Accel X 0.21 Y -0.15 Z 9.79 m/s² Gyro X -0.01 Y 0.02 Z 0.00 rad/s 31.2 °C Accel X 0.19 Y -0.14 Z 9.81 m/s² Gyro X -0.02 Y 0.01 Z 0.00 rad/s 31.2 °C
Common errors
“MPU6050 not found at 0x68”
Check the I2C pins and AD0. Some clone chips report a different WHO_AM_I and the library rejects them. Full fix.
Gyro values drift when still
Normal offset. Average 200 readings at rest at start-up and subtract them.