El GY-521 module It is a component widely used in projects involving motion and orientation measurement, thanks to the fact that it integrates an accelerometer and gyroscope in a single device. This component is versatile and can be used in projects with development platforms such as Arduino, providing important data on three-axis acceleration and angular velocity.
This article will provide you with all the information you need to understand and work with the GY-521, from its more technical features to code examples that you can implement with Arduino. We will also look at how this module can be connected to Arduino and what kind of data can be extracted and used in your projects.
What is GY-521 and how does it work?
The GY-521 module is based on the MPU-6050 sensor, a chip that combines a three-axis accelerometer with a three-axis gyroscope. This means that the GY-521 can measure both acceleration and angular velocity in all three axes (X, Y and Z).
The accelerometer measures acceleration in three directions, including both acceleration due to motion and acceleration caused by gravity. This means it can detect the angle at which the device is tilted relative to the Earth.
the gyroscope, on the other hand, measures angular or rotational velocity in three axes. This way, you can find out how fast something is spinning and in which direction.
Technical characteristics of the GY-521

The GY-521 stands out not only for its integration of accelerometer and gyroscope, but also for a series of technical features that make it ideal for robotics projects, drones and other systems that require precise motion measurement.
- Operating voltage: It can be powered at both 3.3V and 5V, thanks to the voltage regulator included in the module itself.
- I2C connection: This module communicates with Arduino or any other platform using the I2C bus, making it easy to connect and control the device.
- Accelerometer measuring range: The accelerometer can measure in an adjustable range from ±2g to ±16g, allowing accuracy to be tuned to project needs.
- Gyroscope measuring range: Like the accelerometer, the gyroscope also has different adjustable ranges, namely ±250, ±500, ±1000 or ±2000 degrees per second.
In addition to these features, the GY-521 features a Analog to Digital Converter (ADC) 16-bit, which ensures high precision in converting analog signals from sensors into digital data that can be processed by your Arduino.
Connecting GY-521 to Arduino
Connecting the GY-521 module to Arduino is very simple thanks to the I2C interface. I2C bus It uses two pins: one for the data signal (SDA) and one for the clock signal (SCL).
To connect the GY-521 to a motherboard Arduino UNO:
- Connect the pin VCC from the module to the Arduino 5V pin.
- Connect the pin GND from the module to the Arduino GND pin.
- Connect the pin SCL to Arduino pin A5.
- Connect the pin SDA to Arduino pin A4.
Once you have connected the GY-521 to the Arduino, you can upload a simple code example to start reading data from the accelerometer and gyroscope.
Code example to read data from the GY-521 with Arduino
Below is a basic code example to start reading data coming from the accelerometer and gyroscope. The library wire.h which facilitates communication with I2C devices such as the GY-521.
#include
const int MPU = 0x68; // Dirección I2C del MPU-6050.
int16_t accelerometer_x, accelerometer_y, accelerometer_z;
int16_t gyro_x, gyro_y, gyro_z;
int16_t temperature;
void setup() {
Serial.begin(9600);
Wire.begin();
Wire.beginTransmission(MPU);
Wire.write(0x6B); // Registro de gestión de energÃa del MPU6050.
Wire.write(0); // Coloca a cero para activar el sensor.
Wire.endTransmission(true);
}
void loop() {
Wire.beginTransmission(MPU);
Wire.write(0x3B); // Comienza a leer desde el registro 0x3B (datos de aceleración).
Wire.endTransmission(false);
Wire.requestFrom(MPU, 14, true); // Solicita 14 registros del sensor.
// Leer datos de aceleración:
accelerometer_x = Wire.read() << 8 | Wire.read();
accelerometer_y = Wire.read() << 8 | Wire.read();
accelerometer_z = Wire.read() << 8 | Wire.read();
// Leer datos de giroscopio:
gyro_x = Wire.read() << 8 | Wire.read();
gyro_y = Wire.read() << 8 | Wire.read();
gyro_z = Wire.read() << 8 | Wire.read();
Serial.print("Acc: X="); Serial.print(accelerometer_x);
Serial.print(" | Y="); Serial.print(accelerometer_y);
Serial.print(" | Z="); Serial.println(accelerometer_z);
Serial.print("Gyro: X="); Serial.print(gyro_x);
Serial.print(" | Y="); Serial.print(gyro_y);
Serial.print(" | Z="); Serial.println(gyro_z);
delay(500);
}
This basic code will read acceleration and rotation data on all three axes, and display the values ​​on the Arduino Serial Monitor.
Scale and sensitivity adjustment
The GY-521 allows adjust the scale and sensitivity of both the accelerometer and the gyroscope, which is useful if you want to obtain measurements with greater precision or for projects in which you expect to detect more abrupt movements.
To change the scale of the gyroscope and accelerometer, you need to modify specific registers of the MPU-6050. Here's how to do this:
- Accelerometer scale: You can set the range to ±2g, ±4g, ±8g or ±16g using the register ACCEL_CONFIG. Depending on the value written to this register, the desired rank is assigned.
- Gyroscope scale: For the gyroscope, the range can be adjusted between ±250, ±500, ±1000 and ±2000 degrees per second by registering GYRO_CONFIG.
By making these changes, the sensor will change its sensitivity, allowing you to get more accurate data or detect a wider range of motion.
Data filtering: Supplementary filter
One of the challenges when working with sensors like the GY-521 is that acceleration and gyroscope data often have some level of noise. To improve data quality, a noise reduction can be applied. complementary filter that combines both sensors to obtain a more accurate estimate of the device's orientation.
A complementary filter uses gyroscope data to measure rapid changes in orientation, while accelerometer data is used to correct for drift and obtain a more stable long-term measurement.
Applications of GY-521
With its ability to measure acceleration and angular velocity, the GY-521 is used in a wide variety of projects and applications. Some of the most common include:
- Drone control systems: The information provided by the accelerometer and gyroscope is key to maintaining stability in flight.
- Robotics: Some robots use acceleration and rotation data to move and detect changes in their environment.
- Portable devices: Sensors like the GY-521 are used in devices such as fitness bands or smartwatches to measure the user's movement.
These are just a few examples, but the applications are truly limitless when it comes to measuring and interpreting motion and orientation data.
Conclusion: Why you should choose the GY-521 for your projects
The GY-521, with its integration of accelerometer and gyroscope in a single chip, is a powerful and versatile tool for any electronics project. Being Arduino compatible and having an I2C interface, it is really easy to integrate into any system. In addition, its sensitivity tuning capabilities and the fact that it can be implemented in a variety of robotics, motion control and other projects makes it an ideal choice for any maker or budding engineer.
If you are looking for a reliable, easy-to-use sensor with multiple applications, the GY-521 should definitely be on your must-have list.