Home > Projects > Metering – Instrument Projects > Interfacing Accelerometer to Arduino

Interfacing Accelerometer to Arduino

Summary of Interfacing Accelerometer to Arduino


This article explains interfacing the GY-521 (MPU6050) 6-DOF IMU with an Arduino Uno, covering the board pinout, specs, working principle of the accelerometer, and wiring (VCC, GND, SDA to A4, SCL to A5). It notes the onboard voltage regulator allows 5V input, sensor ranges for accel and gyro, the DMP for sensor fusion, and auxiliary I2C pins for connecting additional sensors.

Parts used in the GY-521 to Arduino Interfacing Project:

  • GY-521 breakout board (MPU6050)
  • Arduino Uno
  • Jumper wires
  • USB cable for Arduino power and serial monitor
  • Optional additional I2C sensor (e.g., magnetometer) for auxiliary bus

In this article, we are going to interface the GY-521 accelerometer with Arduino. The GY-521 has an InvenSense MPU6050 chip which contains a 3-axis accelerometer and a 3-axis gyro meter. This makes it a 6 DOF IMU (6 degrees of freedom inertial measurement unit). The chip also includes a 16-bit analog to digital converter on each channel and a DMP (Digital Motion Processor) unit. The DMP unit is responsible for combining the raw data and performing some calculations to remove the errors in each sensor.

Accelerometer_Pin_Out

Pin Out Diagram – GY-521

The GY-521 breakout board has a total of 8 pins which are as follows:

VCC: 5V or 3.3V pin

GND: Ground pin

SCL (Serial clock line): Responsible for the primary I2C communication

SDA (Serial data line): Responsible for the primary I2C communication

XCA (Auxiliary clock line): Responsible for the Auxiliary I2C communication

XDL (Auxiliary data line): Responsible for the Auxiliary I2C communication

ADO:  Responsible for slave or master interface

INT: Interrupt Pin

The breakout board has a voltage regulator for converting the voltage level from 5V to 3.3V and also has an InvenSense MPU6050 chip which holds the accelerometer and gyro meter sensors.

Specifications

The specifications of the GY-521 MPU6050 are as follows

  • The accelerometer sensor range is ±2, ±4, ±8, ±16g
  • The gyro meter sensor range is ±250, ±500, ±1000, ±2000 ͦ/s
  • The voltage range is from 3.3V to 5V. We can give 5V input because the sensor module has a voltage regulator for converting the 5V input into 3.3V

Working

The accelerometer sensors measure the acceleration by measuring the change in capacitance. Its structure has a mass attached to a spring which moves along one direction and has fixed outer plates. So, when acceleration is applied in any direction, the capacitance between the plates and the mass will change. This change in capacitance is measured and corresponds to the acceleration value.

The Arduino reads these acceleration values from the sensor and then calculate the pitch and roll values using the functions provided by the MPU6050 library. These pitch and roll values are shown on the serial monitor output screenshot given below. Whenever we move the sensor, the pitch and roll values on the serial monitor will change according to the movement.

Circuit Diagram

Connections of the GY-521 MPU6050 with the Arduino Uno are as follows

  • VCC of GY-521 to 5V or 3.3V of Arduino Uno
  • GND of GY-521 to GND of Arduino Uno
  • SCL of GY-521 to A5 of Arduino Uno
  • SDA of GY-521 to A4 of Arduino Uno

The SDA and SCL pins of the GY-521 are used for I2C communication, so these pins must be connected to the SDA and SCL pins of Arduino. The SCL and SDA pins on Arduino Uno are the A5 and A4 pins (look at analog pins) respectively. Therefore, we connect the SDA and SCL pins of GY-521 to A5 and A4 pins of Arduino Uno.

The GY-521 MPU 6050 also has two auxiliary SDA, SCL pins, which are an additional I2C controller for the GY-521 MPU6050. These additional pins allow GY-521 MPU6050 to act as a master for the second I2C bus. The purpose of this additional I2C is that if you want to add another sensor (for ex: magnetometer),  then you can directly attach it to the GY-521 which will then read the values.

Read More: Interfacing Accelerometer to Arduino

Quick Solutions to Questions related to GY-521 to Arduino Interfacing Project:

  • What does the GY-521 module contain?
    The GY-521 contains an InvenSense MPU6050 chip with a 3-axis accelerometer, a 3-axis gyrometer, a 16-bit ADC on each channel, and a DMP unit.
  • Can I power the GY-521 with 5V from Arduino?
    Yes, you can give 5V input because the sensor module has a voltage regulator that converts 5V to 3.3V.
  • Which pins on the GY-521 are used for I2C communication?
    The SCL and SDA pins are used for primary I2C communication; XCA and XDA are auxiliary I2C lines.
  • To which Arduino Uno pins should SDA and SCL of GY-521 be connected?
    Connect SDA of GY-521 to A4 and SCL of GY-521 to A5 on the Arduino Uno.
  • What sensor ranges does the MPU6050 accelerometer and gyro support?
    The accelerometer ranges are ±2, ±4, ±8, ±16g; the gyrometer ranges are ±250, ±500, ±1000, ±2000 degrees per second.
  • How does the accelerometer measure acceleration?
    It measures change in capacitance between a movable mass attached to a spring and fixed plates; capacitance changes correspond to acceleration.
  • What is the purpose of the DMP unit in MPU6050?
    The DMP combines raw data and performs calculations to remove errors in each sensor.
  • Can the GY-521 act as a master for another sensor?
    Yes, its auxiliary I2C pins allow it to act as a master for a second I2C bus to read additional sensors like a magnetometer.

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter
Scroll to Top