Watch the demo video:
Circuit used
I used "GY-521" which has "MPU-6050" sensor which contains an accelerometer and a gyro on one chip.
Connections:
VCC on GY-521 ----> to 3.3v pin on ArduinoGND on GY-521 ----> to GND pin on Arduino
SCL on GY-521 ----> to PinA5 on Arduino
SDA on GY-521 ----> to PinA4 on Arduino
Codes
I used 2 codes. The first one should be uploaded to the Arduino board. It is responsible for detecting one of the 3 angles of the sensor, and sending its value to the computer via USB.
The other code is a Matlab code responsible for receiving the angle from the Arduino and visualizing it on a 2D object.
Arduino Code, Matlab code, and Libraries needed:
https://drive.google.com/folderview?id=0Bx4uoJmyE27YOHBqUzVsLU9XTVE&usp=sharing
Move "I2Cdev" & "MPU6050" folders to
Documents > Arduino > libraries