Interfacing MPU6050 accelerometer with Raspberry Pi

In this article, we will look at the MPU6050 accelerometer and interface it with a Raspberry Pi. The MPU6050 sensor module is a complete 6-axis Motion Tracking Device. It combines a 3-axis Gyroscope, a 3-axis Accelerometer and a Digital Motion Processor all in a small package. It has an I2C bus interface to communicate with the host controller (R-Pi).


The MPU6050 has 8 pins as mentioned below:

  1. VCC: +5V DC power supply pin
  2. GND: Ground pin
  3. SCL: Serial Clock pin
  4. SDA: Serial Data pin
  5. XDA: Auxiliary Serial Data pin
  6. XCL: Auxiliary Serial Clock pin
  7. AD0: Slave Address select pin
  8. INT: Interrupt pin

The AD0 pin is used to change the I2C address of the MPU6050. Connecting this pin to +5v sets the address of the sensor to 0x69 and connecting it to ground sets it to 0x68. This is helpful if you have two MPU6050’s or another sensor with the same I2C address on the I2C bus.


The connection diagram is as shown below. This will work for both Raspberry Pi 3 B and Raspberry Pi 3B+ variants.

connection diagram for rapberry pi & MPU6050

In the image above the pin connections are as follows:

MPU6050-Raspberry Pi (board pins)






Refer to the python code for reading accelerometer readings from the MPU6050 and displaying on the terminal. Link for the code:


Upload the above code to a raspberry pi and run it using python3. Running it will print the accelerometer and gyroscope value along the three axes once every 500 ms on the terminal.




In the code above we have created a class for the mpu6050 which abstracts all the functions that will be required to get readings from and set parameters of the mpu6050. You can use that class as a tool to develop various applications using the mpu6050.

This application can be extended much further to detect the orientation of robots, their location (using a technique called inertial navigation), to build self-balancing bots, in quadcopters for roll, pitch, yaw angle calculations and many more.


The MPU6050 accelerometer can be used with other microcontrollers as well. Libraries for a few microcontroller platforms are given below.





Leave a comment

Please note, comments must be approved before they are published