#include <Wire.h>
#include <MPU6050.h>
MPU6050 mpu;
int led = 2;
void setup() {
Serial.begin(9600);
Wire.begin();
mpu.initialize();
pinMode(led, OUTPUT);
if (mpu.testConnection()) {
Serial.println("MPU6050 connection successful");
} else {
Serial.println("MPU6050 connection failed");
while (1);
}
}
void loop() {
int ax, ay, az;
int gx, gy, gz;
az = mpu.getAccelerationZ();
Serial.print("az:");
Serial.println(az);
if (az > 2000)
{
digitalWrite(led, HIGH);
}
else
{
digitalWrite(led,LOW);
}
delay(500);
}