Using the MPU6050 Gyro With Raspberry Pi Pico

Cartoon robot spins happily while IMU detects z-axis rotation with arrows screens and motion lines in colorful laboratory scene background

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.

Next, click the run button and you should see the following in the console.

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.

Main Topic

The Raspberry Pi Pico

Raspberry Pi Pico on a breadboard with sensors and jumper wires arranged neatly on a desk, ready for an electronics project.

Raspberry Pi Pico is an affordable, efficient microcontroller offering flexible GPIO, strong performance, and versatile hardware features for beginner electronics projects.

Other Tutorials in this Topic

Cartoon Raspberry Pi Pico on a breadboard with glowing LED and wires beside a computer screen showing the Thonny picozero plugin installation.

Getting Started With The Raspberry Pico

Getting started guide showing how to set up a Raspberry Pi Pico on a breadboard and install…

A cheerful orange octopus adjusts wires on a breadboard with a Raspberry Pi Pico, potentiometer, and glowing LED beneath the text Basic Input / Output On the Pico.

Basic Input and Output With The Raspberry Pi…

The article explains how a Raspberry Pi Pico uses a potentiometer to control LED brightness, demonstrating basic…

A cheerful cartoon duck turns a control dial beside a spinning motor while an oscilloscope displays a squarewave showing PWM motor control.

Pico Motor Control Using the L9110 Control Board

A tutorial showing how to control a motor using PWM modulation to varying the speed of a…

Cartoon computer and Raspberry Pi Pico shout echo into a glowing cave with bold title Using Bluetooth On The Raspberry Pico.

Using Bluetooth on the Raspberry Pico

The article explains how to use Bluetooth Low Energy on the Raspberry Pi Pico, set up BLE…

Small educational robot uses ultrasonic sensor to navigate obstacles like cones and boxes while moving through a bright indoor course

Getting Started with an Ultrasonic Sensor Module on…

Beginner guide explaining how an ultrasonic sensor module works with Raspberry Pi Pico to measure distance using…

Cartoon LCD on breadboard shows Hello from Tinkimo heart while silly banana sparks and googly eyed hammer watch Pico project

Using an LCD with the Pico

Beginner friendly guide explains using an LCD with the Raspberry Pi Pico for wiring, control signals, and…

Raspberry Pi Pico on breadboard drives LCD showing Hello message surrounded by colourful wires LEDs creating playful beginner electronics scene

Controlling an ST7789 Display With a Raspberry Pi…

Beginner guide explains using an ST7789 LCD with a Raspberry Pi Pico to create simple colourful display…