Skip to main content
2 of 3
added 228 characters in body
Dat Ha
  • 2.9k
  • 6
  • 25
  • 46

Problem fetching data from MPU6050

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_SCL->MPU6050_SCL;

Arduino_SDA->MPU6050_SDA;

Arduino_GND->MPU6050_GND;

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() 

{

  Wire.begin();

  Serial.begin(9600);

  accelgyro.initialize();

  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;

  delay(1000);

}

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?

Thanks