#include <Adafruit_MPU6050.h>
#include <CuteBuzzerSounds.h>

int buzzer_pin = 4;
Adafruit_MPU6050 IMU;

void setup() {
  pinMode(buzzer_pin, OUTPUT);
  digitalWrite(buzzer_pin, LOW);
  
  if (!IMU.begin()) {
    Serial.println("Sensor init failed");
    while (1)
      yield();
  }
  Serial.println("Found a sensor");
  IMU.setAccelerometerRange(MPU6050_RANGE_2_G);
  switch (IMU.getAccelerometerRange()) {
  case MPU6050_RANGE_2_G:
    Serial.print("+-2G");
    break;
  }
  IMU.setGyroRange(MPU6050_RANGE_250_DEG);
  switch (IMU.getGyroRange()) {
  case MPU6050_RANGE_250_DEG:
    Serial.print("+- 250 deg/s");
    break;
  }  
}

void loop() {
  sensors_event_t acc, giro, t;
  IMU.getEvent(&acc, &giro, &t);
  Serial.print("\n X: ");
  Serial.print(giro.gyro.x, 1);
  Serial.print(" Y: ");
  Serial.print(giro.gyro.y, 1);
  Serial.print(" Z: ");
  Serial.print(giro.gyro.z, 1);

  if(giro.gyro.x>0.5) //threshold
  {   
      digitalWrite(buzzer_pin, HIGH);
  }
  else
  {
    digitalWrite(buzzer_pin, LOW);
  }
}
$abcdeabcde151015202530fghijfghij