How do you balance an Arduino quadcopter using calculated gyro values? I was working on an Arduino quadcopter project. I setup all my hardware and was having balancing problems with my software end. I am using an MPU-6050 gyro and accelerometer. I have calculated the angle of the quad in relation to the ground and was trying to implement these values by adjusting the output values to each of the four motors. 

Here is some of my code:

    x=(-computedGyroAngleX-3.5)*10;
    y=(-computedGyroAngleY-2)*10;
    esc1.writeMicroseconds(rc_values[RC_CH1]+x-y);
    esc2.writeMicroseconds(rc_values[RC_CH1]+x+y);
    esc3.writeMicroseconds(rc_values[RC_CH1]-x-y);
    esc4.writeMicroseconds(rc_values[RC_CH1]-x+y);


If the quad is leaning forward I increase the power at the front of the quad and reduce it at the back. I do the same for the y axis. But I run into problems when I test out the quad. It flips over to the side or forward. How would I fix this?
That was happening with me too. Check if the weight distribution of the drone is perfect. Lets say if the battery is placed a little more to one side of the frame than the other side, your drone will try to hover from the other side. 
The center of gravity should be taken care of when the drone is not balancing properly.