I am new to Arduino. I have an arduino mega board, which I need to interface with MPU6050 accelerometer-gyroscope module.

My connections are




Arduino_5 V->MPU6050_Vcc;

Arduino_Pin 2->MPU6050_INT;

I have uploaded the following code to the arduino mega.

#include "I2Cdev.h"
#include "MPU6050.h"
#include "Wire.h"

MPU6050 accelgyro;

int16_t ax, ay, az, gx, gy, gz;
double  time;
int i;

void setup() 
  time = millis();
  i = 1;

void loop() 
  // collect readings
  accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);

  // print result
  Serial.print(i);   Serial.print("\n");
  Serial.print(ax);   Serial.print("\t");
  Serial.print(ay);   Serial.print("\t");
  Serial.print(az);   Serial.print("\t\n");
  Serial.print(gx);   Serial.print("\t");
  Serial.print(gy);   Serial.print("\t");
  Serial.print(gz);   Serial.print("\t\n");

  i = i + 1;

My problem is when I observe the reading on serial monitor, it shows every reading as zero. Does this mean my sensor is damaged or there's some problem with my connection? Or is my code for fetching the data incorrect?


  • Have you put pullup rsistors on SDA and SCL wires? I2C expects these wires to be pulled up. Some dvices include pullup resistors, but not all. For MPU6050 I don't know, but probably not.
    – jfpoilpret
    Commented Nov 3, 2016 at 17:55
  • @jfpoilpret, most MPU6050 breakouts have pull-up resistors. I did some research before buying mine and most of them have pull-up resistors.
    – Dat Ha
    Commented Nov 3, 2016 at 20:06

1 Answer 1


If you are using the MPU6050 library from jrowberg/i2cdevlib, the library does not have any kind of error handling, so it is unfortunately not easy to guess what went wrong, or even if something went wrong. If the getMotion6 function fails, it will simply copy corrupt data into your return values and it is not possible after the invocation to tell if the function succeeded and you got a valid reading, or if the function failed and you only got garbage back.

One possible problem is that the MPU6050 can be configured to use one of two I²C addresses (0x68 or 0x69) and you are using the default address, as implemented in the MPU6050 library (0x68). It might be worth to try the other address, in case your module is configured that way:

MPU6050 accelgyro(0x69);

  • To change the module's adress, set A0 to HIGH.
    – Dat Ha
    Commented Nov 3, 2016 at 20:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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