Arduino Uno Strucks Randomly

Robin2:
Are you saying that if you add those lines into setup() in the code in your Original Post then it will work properly?

If that is not what you are saying then there is more to the change than you have suggested.

...R

No, its not working even i added those lines,for other changes I am still looking but didnt find any

Edit : After i added those lines in setup code is struck in

  while (!mpuInterrupt && fifoCount < packetSize) {
    //Do nothing while mpu is not working
    //they are saying it is a short delay .. i need a way to avoid this
    Serial.print("waiting for mpu");
  }//end of while loop