MPU 6050 Z axis doesnt work...Please help!!

Hi all,

so i am learning how to control servo motors via the mppu6050 gyro module.

the x and y axis work perfectly without problem but when i try to get the z axis (yaw) it just gives me random values.

heres my code:
i am using the library from github

#include <I2Cdev.h>

#include <MPU6050.h>
#include <Wire.h>
#include <Servo.h>   

Servo sg90;          
int servo_pin = 2;
MPU6050 sensor ;
int16_t ax, ay, az ;
int16_t gx, gy, gz ;
void setup ( )

{ 
sg90.attach ( servo_pin );
Wire.begin ( );
Serial.begin  (9600); 
Serial.println  ( "Initializing the sensor" ); 
sensor.initialize ( ); 
Serial.println (sensor.testConnection ( ) ? "Successfully Connected" : "Connection failed"); 
delay (1000); 
Serial.println ( "Taking Values from the sensor" );
delay (1000);
}




void loop ( ) 
 { 
sensor.getMotion6 (&ax, &ay, &az, &gx, &gy, &gz);
//az = map (az, -17000, 17000, 0, 180) ;
Serial.println (az);
sg90.write (az); 
delay (200);
 }

I presume this is the library you are using.

You haven't posted any output for us to see what you consider to be random values. Are they random or do they just not meet your expectations?

Take a look at this at the section measurements.

oh i figured it out. thank you :slight_smile:
i had to do a seperate calculation for the z axis

U Calc you dos sir? Can u email me to cralmc@hotmail.es please? Thanks