#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
#include <Servo.h>
Servo servo;
int pos = 0;
Adafruit_MPU6050 mpu;
void setup(void) {
servo.attach(8);
Serial.begin(9600);
if (!mpu.begin()) {
Serial.println("No MPU6050 found please check wiring!");
while (1) {
delay(50);
}
}
Serial.println("Found MPU6050");
mpu.setAccelerometerRange(MPU6050_RANGE_2_G); //you can change this range
mpu.setGyroRange(MPU6050_RANGE_500_DEG); //same here
mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);
delay(5);
pinMode(2, OUTPUT);
}
void loop() {
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
Serial.print("Acceleration X: ");
Serial.print(a.acceleration.x);
Serial.print(", Y: ");
Serial.print(a.acceleration.y);
Serial.print(", Z: ");
Serial.print(a.acceleration.z);
Serial.println(" m/s^2");
Serial.print("Rotation X: ");
Serial.print(g.gyro.x);
Serial.print(", Y: ");
Serial.print(g.gyro.y);
Serial.print(", Z: ");
Serial.print(g.gyro.z);
Serial.print(" rad/s");
Serial.print("Temperature: ");
Serial.print(temp.temperature);
Serial.print(" degC");
Serial.println("");
delay(500);
if(abs(a.acceleration.x) + abs(a.acceleration.y) + abs(a.acceleration.z) > 15.0){
delay(2000); //set your time delay
for (pos = 130; pos <= 0; pos += 1); //you can also change the pos it turns to
Serial.println(" deployment succsesfull");
servo.write(pos);
}else{
}
}