How to use GY-521 sensor

I am new to the world of Arduino.
I have recently bought a Arduino Mega 2560 and a Gyroscopic sensor with accelerometer, but can’t get it to work correctly.
I did some research on the net to find code with some potential, Here is what I got…

int gyroPin = 0;               
float gyroVoltage = 5;       
float gyroZeroVoltage = 2.5;   
float gyroSensitivity = .007;  
float rotationThreshold = 1;  

float currentAngle = 0;         

void setup() {
  Serial.begin (9600);

void loop() {
float gyroRate = (analogRead(gyroPin) * gyroVoltage) / 1023;

gyroRate -= gyroZeroVoltage;

  gyroRate /= gyroSensitivity;

  if (gyroRate >= rotationThreshold || gyroRate <= -rotationThreshold) {
    gyroRate /= 100;
    currentAngle += gyroRate;

  if (currentAngle < 0)
    currentAngle += 360;
  else if (currentAngle > 359)
    currentAngle -= 360;



Any help would be much appreciated!

Thanx in advance

moderator update: -added code tags == #button above smileys

There is no gyro-pin. There is no analog output.
It is a digital chip with I2C (also called 'Wire') interface.
You have to connect it to the I2C bus. And you request the data via the I2C bus.

However, the Arduino Mega 2560 has a 5V I2C bus, and the MPU-6050 is a 3.3V chip. So you need a level converter.

This page is a start for the MPU-6050 : Arduino Playground - MPU-6050