I have copied this code from Github :

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

MPU6050 mpu;

// Timers
unsigned long timer = 0;
float timeStep = 0.01;

// Pitch, Roll and Yaw values
float pitch = 0;
float roll = 0;
float yaw = 0;

void setup() 

    // Initialize MPU6050
    while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G))
         //Serial.println("Could not find a valid MPU6050 sensor, check 

     // Calibrate gyroscope. The calibration must be at rest.
     // If you don't want calibrate, comment this line.

     // Set threshold sensivty. Default 3.
     // If you don't want use threshold, comment this line or set 0.

   void loop()
       timer = millis();

      // Read normalized values
     Vector norm = mpu.readNormalizeGyro();

     // Calculate Pitch, Roll and Yaw
      pitch = pitch + norm.YAxis * timeStep;
       roll = roll + norm.XAxis * timeStep;
       yaw = yaw + norm.ZAxis * timeStep;

         // Output raw
      //Serial.print(" Pitch = ");
        //Serial.print(" Roll = ");
       //Serial.print(" Yaw = ");

           // Wait to full timeStep period
      delay((timeStep*1000) - (millis() - timer));

Now the question is, whenever I try to change the baud rate Serial Monitor becomes empty.

How can this be resolved?

Some screen-shots :

At 03:38 At 03:39


  • where do you change the baud rate? – Juraj Apr 1 at 17:39
  • I changed, but nothing happened so I commented that line – Maifee Ul Asad Apr 1 at 17:43
  • please see there is a line //Serial.begin(9600); – Maifee Ul Asad Apr 1 at 17:43
  • And did you also change the baud rate in the serial monitor? – Majenko Apr 1 at 17:48
  • Yes, I have added screenshots ... – Maifee Ul Asad Apr 2 at 9:44

You are not very much clear but these are the possible reasons for your problem.

  1. You are using a while loop in your setup() function in your code. Your code might get stuck in there that's why you are not able to see pitch and roll. Try removing comment from the Serial.begin function over there.

  2. After Changing baudrate in your code please make sure you are changing it on your serial monitor as well.

  • I have changed the baud rate both in code & serial monitor. After printing 6/7 values it gets stuck. I have no idea whats going on :'( – Maifee Ul Asad Apr 1 at 17:53
  • I also added a Serial.println("ok") at the last line of Setup that worked. – Maifee Ul Asad Apr 1 at 17:54
  • can you provide screenshot of your serial monitor. – Vaibhav Apr 2 at 6:13
  • I have added screenshots, please see – Maifee Ul Asad Apr 2 at 9:44
  • 1
    i think so as i tried your code with mpu part commented and code works well. Try this library example – Vaibhav Apr 5 at 5:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.