The GY-87 is a compact sensor module that integrates multiple motion and orientation sensors into a single board. It features a 3-axis accelerometer, a 3-axis gyroscope, and a 3-axis magnetometer, making it ideal for applications requiring precise motion tracking and orientation sensing. This module is widely used in robotics, drones, wearable devices, and other motion-sensitive systems.
The GY-87 is based on the MPU6050 (accelerometer and gyroscope) and the HMC5883L (magnetometer) chips, providing reliable and accurate data for a variety of projects. Its small size and I2C communication interface make it easy to integrate into microcontroller-based systems.
The GY-87 module has 6 pins, as described in the table below:
Pin | Name | Description |
---|---|---|
1 | VCC | Power supply input (3.3V to 5V). |
2 | GND | Ground connection. |
3 | SCL | I2C clock line. Used for communication with the microcontroller. |
4 | SDA | I2C data line. Used for communication with the microcontroller. |
5 | EDA | Auxiliary data line for the magnetometer (not commonly used). |
6 | ECL | Auxiliary clock line for the magnetometer (not commonly used). |
0x68
, and for the HMC5883L, it is 0x1E
. Verify these addresses in your code.Below is an example code to read data from the MPU6050 (accelerometer and gyroscope) and HMC5883L (magnetometer) using the Arduino UNO:
#include <Wire.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_HMC5883_U.h>
// Create sensor objects
Adafruit_MPU6050 mpu;
Adafruit_HMC5883_Unified mag = Adafruit_HMC5883_Unified(12345);
void setup() {
Serial.begin(9600);
while (!Serial) {
delay(10); // Wait for Serial Monitor to open
}
// Initialize MPU6050
if (!mpu.begin()) {
Serial.println("Failed to find MPU6050 chip");
while (1) {
delay(10);
}
}
Serial.println("MPU6050 initialized");
// Initialize HMC5883L
if (!mag.begin()) {
Serial.println("Failed to find HMC5883L chip");
while (1) {
delay(10);
}
}
Serial.println("HMC5883L initialized");
}
void loop() {
// Read accelerometer and gyroscope data
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
// Print accelerometer data
Serial.print("Accel X: "); Serial.print(a.acceleration.x);
Serial.print(", Y: "); Serial.print(a.acceleration.y);
Serial.print(", Z: "); Serial.println(a.acceleration.z);
// Print gyroscope data
Serial.print("Gyro X: "); Serial.print(g.gyro.x);
Serial.print(", Y: "); Serial.print(g.gyro.y);
Serial.print(", Z: "); Serial.println(g.gyro.z);
// Read magnetometer data
sensors_event_t event;
mag.getEvent(&event);
// Print magnetometer data
Serial.print("Mag X: "); Serial.print(event.magnetic.x);
Serial.print(", Y: "); Serial.print(event.magnetic.y);
Serial.print(", Z: "); Serial.println(event.magnetic.z);
delay(500); // Delay for readability
}
No Data from the Module:
Inaccurate Sensor Readings:
I2C Communication Errors:
Can the GY-87 be used with 3.3V microcontrollers?
Yes, the GY-87 is compatible with both 3.3V and 5V systems.
Do I need separate libraries for the MPU6050 and HMC5883L?
Yes, you will need libraries such as Adafruit_MPU6050
and Adafruit_HMC5883_U
to interface with the sensors.
How do I calibrate the sensors?
Use calibration routines provided in the sensor libraries or write custom calibration code to account for offsets and scaling factors.
By following this documentation, you can effectively integrate the GY-87 module into your projects and troubleshoot common issues.