Sample mpu6050 accelerometer sensor data for different time

I am using Arduino UNO and MPU 6050 accelerometer sensor.
I wanted to get the sample reading of x axis in A1 and wait for 3 seconds and get the new value after three seconds to new variable A2, I have attached the below code but I am getting the same reading at A1 and at A2 even after three seconds How can i get different values after three seconds?

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

MPU6050 mpu;

void setup() 
{
  Serial.begin(9600);

  Serial.println("Initialize MPU6050");

  while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G))
  {
    Serial.println("Could not find a valid MPU6050 sensor, check wiring!");
    delay(500);
  }

}

void loop()
{
  Vector rawAccel = mpu.readRawAccel();
  Vector normAccel = mpu.readNormalizeAccel();
    float  A1 = normAccel.XAxis;
    Serial.print(" A1= ");
    Serial.print(A1);
     delay(3000);
    float A2 = normAccel.XAxis;
    Serial.print(" A2= ");
    Serial.print(A2);
    float A3= A2-A1;
    Serial.print(" A3= ");
    Serial.print(A3);
    Serial.print('\n'); 
  delay(10);
}

Result:
A1= 10.38 A2= 10.38 A3= 0.00
A1= 10.40 A2= 10.40 A3= 0.00
A1= 10.42 A2= 10.42 A3= 0.00
A1= 10.30 A2= 10.30 A3= 0.00

Is the sensor moving while reading the values?

No I am not moving it

Why should the sensor give you different data for the same position? If it's not moving it will show you the same values

even if I move both A1 and A2 are the same values but it has to read different values for a delay of 3 seconds right
Now I am moving it
A1= 10.36 A2= 10.36 A3= 0.00
A1= 9.77 A2= 9.77 A3= 0.00
A1= 9.67 A2= 9.67 A3= 0.00
A1= 10.92 A2= 10.92 A3= 0.00
A1= 9.83 A2= 9.83 A3= 0.00
A1= -3.35 A2= -3.35 A3= 0.00
I want the result to be like A1 at current time is 10.36 and after 3 seconds that is A2 should be 9.77 but here I am getting A1 and A2 as same values after 3 seconds delay. Instead I want value of A1 as current time value and A2 as current time+ 3 seconds value

Ah, now I know what you mean. You have to call the read-command again after these 3 secs

You are right it worked

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.