Interfacing Accelerometer to Arduino
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.
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.
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
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.
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