Accelerometers measure acceleration forces and can detect motion, vibration, and orientation. They are fundamental to many modern devices and applications.
#include <Wire.h>
#include <MPU6050.h>
MPU6050 mpu;
void setup() {
Wire.begin();
mpu.initialize();
}
void getAcceleration() {
int16_t ax, ay, az;
mpu.getAcceleration(&ax, &ay, &az);
// Convert to g force
float gx = ax / 16384.0;
float gy = ay / 16384.0;
float gz = az / 16384.0;
}