Arduino MPU6050 Sensor Module

Welcome to this beginner-friendly Arduino tutorial on the mpu6050. By the end of the guide, you'll wire the module to an Arduino UNO, flash a short sketch, and read live values on the Serial Monitor — no prior electronics experience required.
What you'll learn
- How the module works in plain language
- The exact parts you need and how to wire them safely
- The full Arduino IDE sketch with comments
- Common issues and how to fix them

Hardware you'll need
| Component | Qty | Notes |
|---|---|---|
| Arduino Uno/Nano | 1 | Microcontroller board |
| MPU6050 Module | 1 | Accelerometer + Gyroscope sensor |
| Jumper Wires | As req. | Male-to-female for connections |
| Breadboard | 1 | For prototyping |
| USB Cable | 1 | For Arduino programming |

Arduino code
Open the Arduino IDE, paste the sketch below into a new file, install any libraries the sketch #includes (Tools → Manage Libraries), select your board and COM port, then click Upload.
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
Adafruit_MPU6050 mpu;
void setup(void) {
Serial.begin(115200);
// Try to initialize!
if (!mpu.begin()) {
Serial.println("Failed to find MPU6050 chip");
while (1) {
delay(10);
}
}
Serial.println("MPU6050 Found!");
// set accelerometer range to +-8G
mpu.setAccelerometerRange(MPU6050_RANGE_8_G);
// set gyro range to +- 500 deg/s
mpu.setGyroRange(MPU6050_RANGE_500_DEG);
// set filter bandwidth to 21 Hz
mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);
delay(100);
}
void loop() {
/* Get new sensor events with the readings */
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
/* Print out the readings */
Serial.print("Acceleration X: ");
Serial.print(a.acceleration.x);
Serial.print(", Y: ");
Serial.print(a.acceleration.y);
Serial.print(", Z: ");
Serial.print(a.acceleration.z);
Serial.println(" m/s^2");
Serial.print("Rotation X: ");
Serial.print(g.gyro.x);
Serial.print(", Y: ");
Serial.print(g.gyro.y);
Serial.print(", Z: ");
Serial.print(g.gyro.z);
Serial.println(" rad/s");
Serial.print("Temperature: ");
Serial.print(temp.temperature);
Serial.println(" degC");
Serial.println("");
delay(500);
}




How it works
The sketch initialises serial communication and the mpu6050 driver in setup(), then in loop() it samples the sensor at a regular interval and prints the result to the Serial Monitor at 9600 baud. Open the Serial Monitor (Ctrl+Shift+M) after upload to see live readings.
Project ideas & applications
- DIY Self-Balancing Robot using Arduino
- Hand Gesture Controlled Robotic Arm using Arduino Nano
- Portable Step Counter using ATtiny85
- Motion sensing in drones and robotics
- Orientation detection in wearable electronics
Troubleshooting checklist
- No readings: verify the baud rate in Serial Monitor matches the sketch (usually 9600).
- Garbage characters: wrong baud rate or loose GND wire.
- Library not found: install the exact library referenced in the
#includeline via Library Manager. - Sensor not detected (I²C): run an I²C scanner sketch to confirm the address.
What to build next
Once the basic readout works, try logging values to an SD card, sending them over Wi-Fi with an ESP32, or pushing them to a Blynk IoT dashboard. Pair this module with our simulator round-up to prototype the circuit before soldering.
You may also like
Frequently Asked Questions
Q.What library do I need for the mpu6050?
Open Arduino IDE → Tools → Manage Libraries, then search for any library named in the sketch's #include lines and install the latest version.
Q.Why does the Serial Monitor show nothing?
The most common cause is a baud-rate mismatch — set the Serial Monitor to 9600 baud (bottom-right dropdown) so it matches Serial.begin(9600) in the code.
Q.Can I use this with an ESP32 instead of Arduino UNO?
Yes. The mpu6050 works with any 3.3-5 V microcontroller. Just remap the wiring to ESP32 I/O pins and keep the rest of the sketch the same.
The Engineer Post
Embedded systems engineer and educator. Writes weekly tutorials at EmbedLab to help beginners ship real hardware.
Related projects
 — Arduino UNO tutorial cover image](/uploads/arduino-covers/interfacing-ir-sensor-module-with-arduino.webp)
Interfacing IR Sensor Module with Arduino
Step-by-step Arduino tutorial: wire the ir to an Arduino UNO, upload the example sketch, and read live values on the Serial Monitor.

Water Level Sensor with Arduino
Step-by-step Arduino tutorial: wire the water level to an Arduino UNO, upload the example sketch, and read live values on the Serial Monitor.

Arduino Micro SD Card Module Project
Step-by-step Arduino tutorial: wire the sd card to an Arduino UNO, upload the example sketch, and read live values on the Serial Monitor. Use it for data loggers (temperature, humidity, gps).

Rain Detection Sensor with Arduino
Step-by-step Arduino tutorial: wire the rain detection to an Arduino UNO, upload the example sketch, and read live values on the Serial Monitor.

Pulse Sensor with Arduino
Step-by-step Arduino tutorial: wire the pulse to an Arduino UNO, upload the example sketch, and read live values on the Serial Monitor.



