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