noob question about the MPU-6050 accelerometer

I'm currently building a little lego segway and I thing I might have made a small misstake...

I'm using this formula to calculate an angle from the accelerometers raw data:

angle=((atan(y/sqrt(pow(x, 2)+pow(z,2))))*(180/3.14159265359));

This works just fine as long as the segway is lying down flat on a table. The accelerometer circuit board is mounted on my veroboard in such a way that it is also lying flat on a table when the entire segway is lying flat on a table. This position will give me an angle of about zero degrees. And if I raise the seaway up into an upright position the accelerometer shows around 90 degrees. So far so good. But if I tilt the segway more than 90 degrees the accelerometer shows less than 90 degrees. It seems as the accelerometer can't produce a value more than 90 degrees? As long as the segway is upright I have no way of knowing if it's tilting forwards or backwards. Is there a clever way to work around this or do I have no other choice then to mount the accelerometer the correct way?

Try mounting your accelerometer at a 45° angle with Y pointing up and forward and X pointing up an back. When they are equal your device is vertical. If your device tilts back the Y will go up and the X will go down. The opposite happens if you tilt forward. You should be able to just take the difference between X and Y and feed that into the PID library without trying to convert to angles.

I see your point but mounting the accelerometer in a 45 degree angle would still mean to re-mount the damn thing. In that case i might as well mount it correctly.