This is an integrated MEMS Accelerometer and Gyroscope unit that is so popular and can be easily attached to Arduino.
The unit uses I2C protocol.
In the first example from Arduino website, we can read data and show it on the serial monitor application in Arduino IDE.
In the second project, you can read data from the unit and view data on Processing.
Project #1
This project is brought to you from Arduino create website.
Project Schematics:
GY-521 Arduino
VCC -> 3.3 V or 5 V
GND -> GND
SCL -> A5
SDA -> A4
XDA -> No Connection
XCL -> No Connection
ADO -> No Connection
INT -> No Connection
Here is the code for the project:
#includeconst 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); }
Project #2
And as another source of a project using the same unit GY-521, here it is:
You can download Arduino code, connect the project, get Processing code and then run it on http://sketchpad.cc
Project Schematics is just the same as the previous project. I repeated them to make things easy:
GY-521 Arduino
VCC -> 3.3 V or 5 V
GND -> GND
SCL -> A5
SDA -> A4
XDA -> No Connection
XCL -> No Connection
ADO -> No Connection
INT -> No Connection
Get Arduino Code from here
Get Processing Code from here
Check our books on Amazon we created on our way to find happiness.
No comments:
Post a Comment