Description:
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
The analog pins are not set on INPUT because it's their default setting. The values read by the analog 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.
Works with Arduino or any Microcontrollers,
Its very easy to interface.
We can also provide sample code to get it working with Arduino.
Project to do with this module:
- Single wheel balancing robot
- Tilt sensing Joystick for games
- Robot control using gestures....
- Many more......
Creative projects limited only by your imagination
Code example for Arduino:
#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); }
Image:
Catalog: