Project tutorial
How to use the accelerometer- gyroscope GY-521

How to use the accelerometer- gyroscope GY-521

Find out how the world turns. Read the values of the accelerometer and the gyroscope.

  • 79,245 views
  • 18 comments
  • 30 respects

Components and supplies

About this project

The accelerometer measures the acceleration along one direction, while the gyroscope measures the angular acceleration on one axis.

Connections:

VCC -> 3.3 V / 5 V (better)

GND -> GND

SCL -> A5

SDA -> A4

XDA ->

XCL ->

ADO ->

INT ->

The analogic pins are not set on INPUT because it's their default setting. The values read by the analogic pins will be sent to the serial port.

Open the Serial Monitor, move the sensor and try to see how the values change.

Accelerometers can be used for fun projects, for example to realize a game controller.

Code

Project codeArduino
#include<Wire.h>
const int MPU=0x68; 
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;

void setup(){
  Wire.begin();
  Wire.beginTransmission(MPU);
  Wire.write(0x6B); 
  Wire.write(0);    
  Wire.endTransmission(true);
  Serial.begin(9600);
}
void loop(){
  Wire.beginTransmission(MPU);
  Wire.write(0x3B);  
  Wire.endTransmission(false);
  Wire.requestFrom(MPU,12,true);  
  AcX=Wire.read()<<8|Wire.read();    
  AcY=Wire.read()<<8|Wire.read();  
  AcZ=Wire.read()<<8|Wire.read();  
  GyX=Wire.read()<<8|Wire.read();  
  GyY=Wire.read()<<8|Wire.read();  
  GyZ=Wire.read()<<8|Wire.read();  
  
  Serial.print("Accelerometer: ");
  Serial.print("X = "); Serial.print(AcX);
  Serial.print(" | Y = "); Serial.print(AcY);
  Serial.print(" | Z = "); Serial.println(AcZ); 
  
  Serial.print("Gyroscope: ");
  Serial.print("X = "); Serial.print(GyX);
  Serial.print(" | Y = "); Serial.print(GyY);
  Serial.print(" | Z = "); Serial.println(GyZ);
  Serial.println(" ");
  delay(333);
}

Schematics

circuit diagram
Gy 521 breadboard arduino t2lk2jvb4s

Comments

Similar projects you might like

Near-Perfect Gyroscope

Project in progress by Team OZTL

  • 14,285 views
  • 1 comment
  • 45 respects

8x8 Matrix LED Snake Game (Smartphone Motion)

Project tutorial by hmkim

  • 6,775 views
  • 2 comments
  • 20 respects

Arduino Gyroscope Game with MPU-6050

Project tutorial by Mirko Pavleski

  • 2,251 views
  • 1 comment
  • 12 respects

Gyroscope Fun with NeoPixel Ring

Project tutorial by danionescu

  • 20,845 views
  • 3 comments
  • 54 respects

Create a Game with Arduino and Processing

Project showcase by Nicholas_N

  • 6,553 views
  • 3 comments
  • 5 respects
Add projectSign up / Login