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.

  • 138,943 views
  • 20 comments
  • 39 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,914 views
  • 1 comment
  • 45 respects

8x8 Matrix LED Snake Game (Smartphone Motion)

Project tutorial by hmkim

  • 7,494 views
  • 4 comments
  • 23 respects

Arduino Gyroscope Game with MPU-6050

Project tutorial by Mirko Pavleski

  • 2,955 views
  • 2 comments
  • 12 respects

Gyroscope Fun with NeoPixel Ring

Project tutorial by danionescu

  • 21,873 views
  • 3 comments
  • 55 respects

Create a Game with Arduino and Processing

Project showcase by Nicholas_N

  • 9,846 views
  • 5 comments
  • 6 respects
Add projectSign up / Login