Arduino: How to Use the Gyro-Modul Gy-521 MPU 6050
by ekcum in Circuits > Arduino
656 Views, 1 Favorites, 0 Comments
Arduino: How to Use the Gyro-Modul Gy-521 MPU 6050
Hey, what's up!!! For everybody who didn't know that the GY-531 is a small surprise bag, here is a small information box for everyone, who wants to use the gyrosensor GY-521! With this component you can get temperature, the acceleration and the angle.
Supplies
- Arduino Mega (U can use every board u want)
- GY-521
- Jumper Wires
Pin Layout
- VCC (The breakout board has a voltage regulator. Therefore, you can connect the board to 3.3V or 5V sources.)
- GND (Ground)
- SCL (Serial Clock Line of the I2C protocol.)
- SDA (Serial Data Line of the I2C protocol.)
- XDA (Auxiliary data => I2C master serial data for connecting the module to external sensors.)
- XCL (Auxiliary clock => I2C master serial clock for connecting the module to external sensors.)
- AD0 (If this pin is LOW, the I2C address of the board will be 0x68. Otherwise, if the pin is HIGH, the address will be 0x69.)
- INT (Interrupt digital output)
How to Connect It to Your Arduino Board
To the pin VCC you can connect 5 or 3.3 Volt and to the GND pin the GND on the board
For data connection I'm using the digital pins 20(SDA) and 21(SCL).
The other pins aren't used often, so I skipped them in this tutorial.
Coding
I used the libary MPU6050_light to read out the sensor, I only had one problem: The Output through the Serialterminal was the same all the time. To fix this problem i connected to the sda and scl pins on the board.
#include "Wire.h"
#include "MPU6050_light.h"
MPU6050 mpu(Wire);
void setup() {
Serial.begin(9600);
Wire.begin();
mpu.begin();
mpu.calcGyroOffsets();
Serial.println("Gyro works.");
}
void loop() {
mpu.update();
float tmp = mpu.getTemp();
float angle[3] = {mpu.getAngleX(),mpu.getAngleY(),mpu.getAngleZ()};
float gyro[3] = {mpu.getGyroX(), mpu.getGyroY(), mpu.getGyroZ()};
float accel[3] = {mpu.getAccX(), mpu.getAccY(), mpu.getAccZ()};
Serial.print("Device Temperature: ");Serial.print(tmp);Serial.println(" Celsius");
digitalWrite(tmp, "tmp");
Serial.print("Angles (degrees): x=");Serial.print(angle[0]);
Serial.print(", y=");Serial.print(angle[1]);
Serial.print(", z=");Serial.println(angle[2]);
Serial.print("Gyro (degrees/s): x=");Serial.print(gyro[0]);
Serial.print(", y=");Serial.print(gyro[1]);
Serial.print(", z=");Serial.println(gyro[2]);
Serial.print("Acceleration (g aka 9.81m/s^2): x=");Serial.print(accel[0]);
Serial.print(", y=");Serial.print(accel[1]);
Serial.print(", z=");Serial.println(accel[2]);
Serial.println("");
delay(1000);
}
If by turning the sensor around, the values don't change, please check your pin connections.