Hi All, I really wants to learn deeply how mpu6050 (GY-521) works based on programming lang in Arduino IDE.
In this case, I have this code to detect if the mpu6050 is moved or lifted or vibrated by a thing or me. First, I place the mpu6050 on flat surface and tight it. Besides, I also add double foam tape at the bottom of the module to reduce the vibration if exist.
Here's the code I've been trying:
void detectStableSurface() {
int16_t ax, ay, az, gx, gy, gz;
mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
float accZ = az / 16384.0;
float totalGyro = sqrt(gx * gx + gy * gy + gz * gz) / 131.0; // degrees/sec
// Check if Z-axis points to gravity (1g), and no rotation
if (accZ > 0.95 && accZ < 1.05 && totalGyro < 0.5) {
Serial.println("Flat and Stable");
} else {
Serial.println("Moved or Tilted");
}
}
But, even though I dont lift or move or shake the mpu6050, it still detects being lifted or moved.
Use Serial.print()
statements to print out sensor values, and study them to learn why your if statements aren't working as expected.
Hint: forum members and experienced programmers in general call numbers like 0.95 and 1.05, which appear in code without any explanation "magic numbers", because they seem to appear out of nowhere.
1 Like
Thanks for fast reply. Yes, I consider the value as an accuracy of a measurement based on continuous observation. For examples, I can detect accurately the tilt angle of a ship when sailing to execute safety command., etc.
And, Again and again! my bad.
I checked again and again if my flat is on a very Flat Surface and it is!
But my mpu6050 is not on flat surface on a flat media.
It shows "Flat and Stable" now. Thanks.
My QUestion: Is the mpu6050 so sensitive like that?????
Yes, the MPU6050 is very sensitive, but also has high measurement noise, as printing out some measurements will demonstrate.
It has also been obsolete for years. The new replacements are more sensitive, and have much less measurement noise.
1 Like
Noted! (high measurement noise,new replacements are more sensitive, and have much less measurement noise.)
Thanks, it gives me much clue about this sensor 