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.

  • 222,354 views
  • 26 comments
  • 50 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

3D Artificial Horizon - Gyroscope with MPU6050 GY-521

Project tutorial by Gallax

  • 2,534 views
  • 1 comment
  • 7 respects

Near-Perfect Gyroscope

Project in progress by Team OZTL

  • 17,892 views
  • 1 comment
  • 49 respects

DHT11 Temperature/Humidity Sensor

Project tutorial by Zachary Haslam

  • 188,337 views
  • 53 comments
  • 120 respects

Gyroscope Fun with NeoPixel Ring

Project tutorial by danionescu

  • 27,447 views
  • 4 comments
  • 61 respects

8x8 Matrix LED Snake Game (Smartphone Motion)

Project tutorial by hmkim

  • 10,343 views
  • 4 comments
  • 28 respects
Add projectSign up / Login