How to Use MPU6050 with Raspberry Pi Pico

In this tutorial I will show how to use the MPU6050 acceleration sensor end to end, that is, I will show everything you need from the physical setup and code to start obtaining readings from your MPU6050 with your Raspberry Pi Pico W. The MPU6050 is a low-cost and accurate acceleration sensor you can use for any DIY project. It is especially useful in projects involving the Raspberry Pi Pico, Arduino, and other microcontrollers, arguably being the most popular choice of an accelerometer for those types of projects.

Step 1-) Gather the components required:

Step 2-) Attach Raspberry Pi to BreadBoard:

In this step you just have to attach your Raspberry Pi to the breadboard, it should sit nicely on the breadboard after applying some pressure. Do not worry if the pins go all the way into the board, that is actually better. Also, placement on the board, aside from the left and right regions where it indicates a plus/minus area, is trivial; I place it on the top and align it across the center for better practice and demonstration purposes. 

Step 3-) Attach the jumper wires to the board and to the MPU6050:

Plug in your MicroUSB from your computer to your Raspberry Pi Pico

Next, take four male-to-female jumper wires. Attach the ends as follows:

  • Red Wire: Pin 39
  • Black Wire: Pin 38
  • White Wire: Pin 1
  • Yellow Wire: Pin 2

The pins on the Pico are arranged like this:

*Note that the color of the wire does not affect the transmission of any signals.

On the MPU6050 you want to attach the wires like this:

As you can see you are using VCC for transmitting power, while GND is simply the ground pin. SCL and SDA pertain to the means of communication between the Raspberry Pi and the Accelerometer, the specifics of that are beyond this tutorial. 

Once you are done with this step you should see the MPU6050 light up red as you can see in the image. Now the only thing left is to get the code configured.

Step 4-) Setup the library and code scripts in your Pico in Thonny:

You can find the two scripts you need here:

I am assuming you have Thonny installed. If not, it is free and you can install it here:

  • https://thonny.org/

If you set up Thonny properly with your Raspberry Pi Pico you should see a window that looks as follows:

Where you see the files in your Pico on the bottom left. You can create two files, one for the library code (do not change the name of the library file) and the other for the main file (you can name this whatever you like), and just copy the code from the two links above into the corresponding files. 

Now you can run the main file and start getting readings! If you did everything correctly you should start seeing MPU6050 readings for all 6 degrees of acceleration plus temperature in the console below. 

Good luck!

Conclusion:

Hope you enjoyed the quick tutorial on how to get the MPU6050 setup with your Raspberry Pi Pico. If it helped you in any way please feel free to subscribe and comment on my Youtube Channel. Looking forward to making more content, helping more people, and developing new technology in the IoT space. 

Create a free account to access full content.

All access to code and resources on ShillehTek.

Signup Now

Already a member? Sign In

Explore More on Our Blog

How to Connect and Use the HCSR501 PIR Sensor with a Raspberry Pi Pico/Pico W

How to Connect and Use the HCSR501 PIR Sensor with a Raspberry Pi Pico/Pico W

Learn how to set up the HCSR501 PIR sensor with a Raspberry Pi Pico to detect motion and trigger...

Powering the Raspberry Pi Pico W with the MB102 Power Supply

Powering the Raspberry Pi Pico W with the MB102 Power Supply

Learn how to power your Raspberry Pi Pico W projects easily and flexibly with the MB102 Power Supply Module...

How to Use L298N Motor Driver with Pico W

How to Use L298N Motor Driver with Pico W

Learn how to use the L298N motor driver to control DC motors with the Raspberry Pi Pico W in MicroPython.

Controlling an LED with a Snap Using the KY-037 Sound Sensor and Raspberry Pi

Controlling an LED with a Snap Using the KY-037 Sound Sensor and Raspberry Pi

Discover how to set up, code, and activate the LED based on detected sound with the Raspberry Pi...

Getting Started with the KY-037 Sound Sensor and Raspberry Pi: Detecting Sound Using Python

Getting Started with the KY-037 Sound Sensor and Raspberry Pi: Detecting Sound Using Python

In this tutorial, I’ll guide you through setting up the KY-037 sound sensor with a Raspberry Pi using...

How to Post to Reddit Using Python

How to Post to Reddit Using Python

Post to reddit automatically using a Python script.

How to Create a Time-Lapse Video with a Raspberry Pi Camera

How to Create a Time-Lapse Video with a Raspberry Pi Camera

Learn how to make a timelapse with your Raspberry Pi in Python.

How to Integrate the MPU6050 with the STM32 Blue Pill

How to Integrate the MPU6050 with the STM32 Blue Pill

Learn how to measure acceleration with the STM32 and the MPU6050 in the Arduino IDE.

Getting Started with STM32 Blue Pill in Arduino IDE Using a USB to TTL Converter — Write Your First Program

Getting Started with STM32 Blue Pill in Arduino IDE Using a USB to TTL Converter — Write Your First Program

This comprehensive tutorial will guide you through the process of setting up and programming the STM32 Blue Pill...

Automate Task Scheduling in AWS with Lambda, Step Functions, and CloudWatch

Automate Task Scheduling in AWS with Lambda, Step Functions, and CloudWatch

In this tutorial, I'll show you how to automatically schedule tasks in AWS at regular intervals using AWS...

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.