In this video tutorial we show how the MPU6050 can be used to measure acceleration in the x, y, and z directions, that is, Ax, Ay, and Az. We also introduce the idea of plotting the data to the Arduino Serial Plotter to make visualization of the data easier.
Below is the schematic we are using to access the MPU6050 on the GY-87 module.

Below is the code which we developed in the lesson to measure acceleration in all three axis.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
// ==================================================================== // DISCLAIMER: // This code is provided as-is for educational and experimental // purposes only. The author makes no representations or warranties of // any kind concerning the safety, suitability, or accuracy of this // code. Use at your own risk. The author assumes no liability for any // damages, system failures, security breaches, or network issues // resulting from the use or implementation of this script. // ==================================================================== #include <Adafruit_MPU6050.h> #include <Adafruit_Sensor.h> #include <Wire.h> float Ax; float Ay; float Az; Adafruit_MPU6050 mpu; void setup() { // put your setup code here, to run once: Serial.begin(115200); mpu.begin(); Serial.println("MPU6050 Started!"); mpu.setAccelerometerRange(MPU6050_RANGE_2_G); mpu.setFilterBandwidth(MPU6050_BAND_21_HZ); } void loop() { // put your main code here, to run repeatedly: sensors_event_t a, g, temp; mpu.getEvent(&a, &g, &temp); Ax=a.acceleration.x/9.81; Ay=a.acceleration.y/9.81; Az=a.acceleration.z/9.81; Serial.print("Ax:"); Serial.print(Ax); Serial.print(','); Serial.print("Ay:"); Serial.print(Ay); Serial.print(','); Serial.print("Az:"); Serial.print(Az); Serial.print(','); Serial.print("UL:"); Serial.print(1); Serial.print(','); Serial.print("LL:"); Serial.println(-1); delay(50); } |