13. GY-521 Module
The GY-521 module, based on the MPU-6050 sensor, is a popular choice for motion sensing applications. This module combines a 3-axis gyroscope and a 3-axis accelerometer on a single chip, allowing for accurate motion tracking in various projects.
Materials
Component | Image |
---|---|
Breadboard | |
Jumper wires | |
Arduino Uno R4 Minima | |
GY-521 Gyroscope Module |
Instructions
- Make the following connections using the breadboard and jumper wires.
Connections
(GY-521 to Arduino)
- VCC to 5V
- GND to GND
- SCL to SCL
- SDA to SDA
-
Navigate to the Library Manager on the Arduino IDE and download the MPU6050 library.
-
Paste the following code into your main Arduino sketch:
Code
// Importing the necessary libraries
#include <Wire.h>
#include <MPU6050.h>
MPU6050 mpu;
//Setting to print on serial monitor 9600
void setup() {
Serial.begin(9600);
Wire.begin();
mpu.initialize();
Serial.println("Testing Gyroscope and Accelerometer MPU6050");
}
void loop() {
int16_t ax, ay, az, gx, gy, gz;
mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
// Printing the data from each of the 3 axes
Serial.print("a/g:\t");
Serial.print(ax); Serial.print("\t");
Serial.print(ay); Serial.print("\t");
Serial.print(az); Serial.print("\t");
Serial.print(gx); Serial.print("\t");
Serial.print(gy); Serial.print("\t");
Serial.println(gz);
delay(1000); // The data is set to print every second
}
-
Connect your Arduino to your laptop using a USB-C cable and upload the code to the arduino.
-
Test! Move your gyroscope and observe the changes in print statements on your serial monitor.
Prev | Next |
---|---|
12. MAX7219 LED Matrix | 14. PIR Motion Sensor |