Measuring Rotation and acceleration with the Raspberry Pi

MPU-6050 Module    Send article as PDF   

Acceleration and rotation sensors are most known from smartphones. The rotation of the device can be detected and can be addressed directly.

With the Raspberry Pi and a Gyroscope / Accelerator sensor it is possible to measure the rotation as well as the acceleration of the 3 axes.
In this tutorial use the MPU 6050 Gyroscope / Accelerator sensor interferfaced to a Raspberry Pi, and reads the values using I2C.


For this tutorial I have used the following components:

  • Raspberry Pi
  • MPU 6050 sensor module
  • Jumper Cables

MPU-6050 Module


The practical thing about I2C is that very few pins are used. Of the eight pins of the sensor, we only need to connect the upper 4:

MPU-6050 Module Pinout

Raspberry Pi MPU 6050
Pin 1 (3.3V) VCC
Pin 3 (SDA) SDA
Pin 5 (SCL) SCL
Pin 6 (GND) GND

MPU-6050 Module to Raspberry Pi

Activate I²C on the Raspberry Pi:

First we enable SPI and I2C. If you have already done this in a previous tutorial, you can skip this step.

Here we find the menu for activating services. Under “8. Advanced Options” there is the entry “A7 I2C”, which we activate (This can differ in other Raspbian versions). For older Raspbian versions, the entries in the /etc/modprobe.d/raspi-blacklist.conf file must be excerpted (with #).

We then edit the modules file:

If the following lines are not already included, add them and restart the Pi (sudo reboot):


Now we can quickly install the necessary tools:

Let’s start a small test. The parameter -y 1stands for revision 2. If you have a completely old Pi (before 2013), you would have to specify a 0 instead:

If the gyroscope is properly connected, you will see this output (if you have other I2C modules connected, their hex addresses should be displayed):

To address the device with address 68 (Attention: Hexadecimal) under the register, enter the following:

MPU6050 Gyroscope Raspberry Pi

Read the MPU-6050 Module:

The most convenient way to read the acceleration sensor is probably Python. Therefore, we create a file and paste the following code.

Python Script:

Save it with CTRL + O and exit the editor with CTRL + X. You can then run the script.

Now you’ll see an output that contains all the captured data:

If you want to know more about accelerometers and gyroscopes, you should read this article.

Previous Post
Keyestudio GPS Plate

Installing the Keyestudio Raspberry PI GPS Plate

This Keyestudio KS0216 Raspberry Pi GPS Plate (shield) features high performance and low power consumption. It utilizes the NEO-6M Module developed by U-blox. The GPS Module is connected through the 2*20 ... Read more

Next Post

Interfacing the Neo-6M GPS Module & Raspberry Pi with LCD Readout

One of the coolest embedded platforms like the Raspberry Pi has given makers and DIYers the ability to get location data easily using GPS module and thus build things that ... Read more

Short URL:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Do NOT follow this link or you will be banned from the site!