So I'm doing a project where the gyroscope on the MPU6050 module will move a servo. But every example I found online ether didn't work or used the accelerometer which is not what I want because this is going to go on a foam glider which is already accelerating. I tried a bunch of different ways but some how I couldn't get this code to use the gyroscope instead of the accelerometer (this code can move the servo using the accelerometer). I don't know what to do!
#include <GY6050.h>
//hammadiqbal12@gmail.com
//https://www.youtube.com/watch?v=Cvtr3LKdqvk
#include <GY6050.h> //library for GYRO
#include <Wire.h>
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int X = 0;
int Y = 0;
int Z = 0;
GY6050 gyro(0x68); //to save GYRO data
void setup() {
Wire.begin(); //initializing GYRO
gyro.initialisation();
delay(100);
myservo.attach(9);
}
void loop() {
X = map(gyro.refresh('A', 'X'), -90, 90, 0, 180); //mapping the gyro data according to angle limitation of servo motor
Y = map(gyro.refresh('A', 'Y'), -90, 90, 0, 180);
Z = map(gyro.refresh('A', 'Z'), -90, 90, 0, 180);
myservo.write(Y); //movement of Y axis will control servo
delay(15);
}