COMPONENTS :
Arduino Uno Board
Jumper Wires
Bread Board
GY - 521
THEORY :
The accelerometer measures the acceleration along one direction, while the gyroscope measures the angular acceleration on one axis.
CONNECTION :
1. Connect VCC to 3.3 V or 5 V.
2. Connect GND to GND
3. Connect SCL to A5 (Analog pin)
4. Connect SDA to A4 (Analog pin)
5. XDA, XCL, ADO, INT are not set on INPUT because it's their default setting. The values read by these analog pins will be sent to the serial port.
* Open the Serial Monitor, move the sensor and try to see how the values change.
![](https://static.wixstatic.com/media/a27d24_fb73889426ad4353b9636bcb40ff6746~mv2.png/v1/fill/w_980,h_415,al_c,q_90,usm_0.66_1.00_0.01,enc_auto/a27d24_fb73889426ad4353b9636bcb40ff6746~mv2.png)
CODE :
#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);
}
// If there is any problem while making this project feel free to ask in the comment.