MPU-6050 Accelerometer Values

Hello,

I would like use only the accelerometer values of MPU-6050, when I was testing the sensor, the values of accelerometer were changing the reference as I was tilting the board like the gyroscope [sometimes i think that it is inverted]

I have tested too with an ADXL335 and it don’t occurured

i have used this codes to test see the values

Code 1:

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

MPU6050 mpu;
int ax, ay, az, gx, gy, gz, rx, ry;

void setup() {
  Serial.begin(9600);
  Wire.begin();
  mpu.initialize();
  if (!mpu.testConnection()) {
    while (1);
    }
}

void loop() {

  mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
  
  // I tryed use this varation but it don't works
  //mpu.getAcceleration(&ax, &ay, &az); 

  rx = -(ax); 
  ry = -(ay);

  Serial.print("ax ");
  Serial.print(ax);
  Serial.print("  ay ");
  Serial.println(ay);
  
  Serial.print("rx ");
  Serial.print(rx);
  Serial.print(" ry ");
  Serial.println(ry);
 
  delay(1000);
}

Code 2:

//Carrega a biblioteca Wire
#include<Wire.h>

//Endereco I2C do MPU6050
const int MPU=0x68;  

//Variaveis para armazenar valores dos sensores
int AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
int AnAcX; 
int AnAcY; 
int AnAcZ;

void setup()
{
  Serial.begin(9600);
  Wire.begin();
  Wire.beginTransmission(MPU);
  Wire.write(0x6B); 
   
  //Inicializa o MPU-6050
  Wire.write(0); 
  Wire.endTransmission(true);

}
void loop()
{
  AnAcX = analogRead(A0);
  AnAcY = analogRead(A1);
  AnAcZ = analogRead(A2);
  Wire.beginTransmission(MPU);
  Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
  Wire.endTransmission(false);
  //Solicita os dados do sensor
  Wire.requestFrom(MPU,14,true);  
  //Armazena o valor dos sensores nas variaveis correspondentes
  AcX=Wire.read()<<8|Wire.read();  //0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)     
  AcY=Wire.read()<<8|Wire.read();  //0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
  AcZ=Wire.read()<<8|Wire.read();  //0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
  Tmp=Wire.read()<<8|Wire.read();  //0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
  GyX=Wire.read()<<8|Wire.read();  //0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
  GyY=Wire.read()<<8|Wire.read();  //0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
  GyZ=Wire.read()<<8|Wire.read();  //0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
   
  //Envia dados do acelerometro digital MPU6050 para a serial
  Serial.print("MPU6050:  ");
  Serial.print("AcX = "); Serial.print(AcX);
  Serial.print("  | AcY = "); Serial.print(AcY);
  Serial.print("  | AcZ = "); Serial.print(AcZ);
   
  //Envia valor da temperatura para a serial
  //Calcula a temperatura em graus Celsius
 // Serial.print("  | Tmp = "); Serial.print(Tmp/340.00+36.53);
     
  //Envia valor giroscopio para a serial
  Serial.print("  | GyX = "); Serial.print(GyX);
  Serial.print("  | GyY = "); Serial.print(GyY);
  Serial.print("  | GyZ = "); Serial.println(GyZ);

  //Envia dados do acelerometro Analogico ADXL335 para a serial
  Serial.print("ADXL335:  ");
  Serial.print("AcX = "); Serial.print(AnAcX);
  Serial.print("  | AcY = "); Serial.print(AnAcY);
  Serial.print("  | AcZ = "); Serial.println(AnAcZ);
   
  //Aguarda 300 ms e reinicia o processo
  delay(500);
}

Have an way of to make the accelerometer and gyroscope work indenpendently?

Thanks

The accelerometer and rate gyro are completely independent.

The accelerometer measures the acceleration due to Earth's gravity (g), in addition to the accelerations caused by other forces. When you [u]tilt[/u] the accelerometer, the components of g measured along the X, Y and Z accelerometer axes change.