The MPU6050 is a popular Inertial Measurement Unit (IMU) that combines two sensors in one small chip: a 3-axis accelerometer and a 3-axis gyroscope. Together, these sensors let a microcontroller measure movement, orientation, and rotation in three dimensions. The accelerometer detects linear motion and tilt (for example, knowing which way is “down”), while the gyroscope measures rotational movement, such as how fast something is turning. By combining data from both, you can get a much more accurate picture of how an object is moving.
Because of this, the MPU6050 is widely used in projects like robots, drones, game controllers, wearables, and motion-controlled interfaces. It’s especially useful when you want a device to react to motion — balancing a robot, detecting gestures, or tracking orientation over time. Many projects also apply sensor fusion techniques (often using built-in features of the chip or software libraries) to smooth out noise and improve accuracy.
Communication with the MPU6050 happens over the I2C bus, a simple two-wire protocol used by many sensors. I2C uses just SDA (data) and SCL (clock) lines, allowing the MPU6050 to share the same bus as other devices. The microcontroller acts as the controller (or “master”) and requests data from the MPU6050 using its I2C address. This makes the sensor easy to wire up, efficient on pins, and ideal for compact embedded systems like the Raspberry Pi Pico.
You can read more about the operation of an IMU here and the I2C bus on this page.
Wire up the circuit
In order to run the project firstly the IMU circuit needs to be connected as shown in the diagram below. The circuit diagram below is shown for clarity and the actual connection on the breadboard follow.

The circuit looks as shown below on the set up that was used to create this tutorial.

Running the Code
In order to get started you will need to follow this tutorial, which will ensure that your environment and Pico are configured correctly.
The Python code uses a library that is used to interpret the measurements from the IMU. The library can be found here and the files that are required are imu.py and vector3d.py.
Download the two files and paste the contents into the Thonny editor then save them to the Pico. Keep the filenames the same.
Now create a file called main.py on the Raspberry Pico with the following content.
from imu import MPU6050
from time import sleep
from machine import Pin, I2C
i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)
imu = MPU6050(i2c)
while True:
ax=round(imu.accel.x,2)
ay=round(imu.accel.y,2)
az=round(imu.accel.z,2)
gx=round(imu.gyro.x)
gy=round(imu.gyro.y)
gz=round(imu.gyro.z)
tem=round(imu.temperature,2)
print("acceleration x:",ax," y:",ay," z:",az)
print(" gyro x:",gx," y:",gy," z:",gz)
print(" temperature:",tem)
print("\n\n")
sleep(0.2)
Next, click the run button and you should see the following in the console.
acceleration x: 0.97 y: -0.04 z: -0.37
gyro x: -2 y: -9 z: 7
temperature: 21.42
The output represents the measurements from the IMU. Moving the breadboard will make the values change. Try moving the board in different axis and see how it affects the values that are reported.








