Hi SarveshT1,

I'm too using an Arduino Uno R3 for making a quadcopter. I however use a MPU-9150 instead of an MPU-6050. But I do use the library called "MPU6050.h". You can download this library from github. It's part of the I2Cdev repo. Download this library and run some tests.

Like you've probably already guessed the MPU6050 runs on I2C. This protocol runs on digital signals, not on analog signals as described in this tutorial. For my quadcopter, I want to know the angle the drone's flying in, and from there calculate what to do with the motors. I think this is better because it makes the drone possible to fly on its own. I'm also planning to build an android app, and calculating the exact angle is needed for that too.

But let's not talk too much about dreams. I use the gyroscope and the accelerometer to calculate this angle. I use a 'Complementary Filter' to calculate this angle as good as possible. This filter picks the best of both worlds. The gyroscope can drift, and the accelerometer is unsteady. How I've implemented it is like this:

#include <Wire.h>

#include <I2Cdev.h>

#include <MPU6050.h>

//This one is the same for MPU9150 and MPU6050

#define GYROSCOPE_SENSITIVITY 32.8

#define RADIANS_TO_DEGREES 57.29577951

MPU6050 mpu = MPU6050();

//The timer which is needed for the Complementary Filter

long timer;

//The variables where the data from the imu is stored in

int16_t ax, ay, az, gx, gy, gz;

//Variables to store the calculated pitch and roll in

double pitch = 0;

double roll = 0;

void setup() {

Serial.begin(115200); //Personal favor

Wire.begin(); //The library doesn't do this by itself

mpu.initialize();

delay(100);

//Check if the MPU-6050 is connected, and wait one second before checking again

while (!mpu.testConnection()) {

Serial.println("MPU not found!");

delay(1000);

}

mpu.setFIFOEnabled(false); //Make sure you always get the newest messages

Serial.println("Setup executed!");

}

void loop() {

long begin = micros();

//Get the accel and gyro data from the mpu6050

mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);

//First calculating the angle of the accelerometer for the pitch.

//More information google 'Accelerometers and gyroscopes on a chip'

long squareSum = (long) ay*ay + (long) az*az;

double accelAngle = atan(ax / sqrt(squareSum)) * RADIANS_TO_DEGREES; //I want my angle in degrees

pitch += (-gy / GYROSCOPE_SENSITIVITY) * ((micros() - begin) / 1000000.0);

pitch = 0.98 * pitch + 0.02 * accelAngle;

//And all the same for the roll but different formula

squareSum = (long) ax*ax + (long) az*az;

accelAngle = atan(ay / sqrt(squareSum)) * RADIANS_TO_DEGREES;

roll += (-gx / GYROSCOPE_SENSITIVITY) * ((micros() - begin) / 1000000.0);

roll = 0.98 * roll + 0.02 * accelAngle;

//And print the values to the terminal

Serial.print("Pitch: ");

Serial.print(pitch);

Serial.print(" Roll: ");

Serial.println(roll);

}

Upload this to your Arduino and it will print the angle of your mpu to the screen. Check the baudrate!

About the ESC's I can't tell you very much now, I'm still figuring this one out. I've found out how to get angle, but now translating that angle to a pulse is the difficulty. I wish you good luck with your project!