Dear all, referring to the video at here on how to make a PID balancing pendulum as shown in the picture and the author also provided the arduino code in the video description. May I ask whether this arduino code can be used on my MPU6050 gyroscope without any modifications because the author in the video does not provide the model of the gyroscope used. I have also searched countless of arduino code on web on balancing pendulum using propeller PID with a DC brushless motor (not 3 phase) and MPU6050 gyrocope, but couldn't find any and I hope someone could show me some examples code.
Thank you and have a nice day!!
// Chuong trinh dieu khien cân bang thanh ngang Nguyen Duc Sang 24/05/2018
//---------------------------------------------------------------
//875=0
//530=90 do
#define SENSOR A1
#define CONTROL 6
#define dongco 7
void setup() {
Serial.begin(9600);
pinMode(SENSOR,INPUT);
pinMode(CONTROL,OUTPUT);
pinMode(dongco,OUTPUT);
}
double error = 0;
double realAngle;
double lastrealAngle;
double
kP = 1,
kI = 0.005,
kD = 0;
double
P = 0,
I = 0,
D = 0;
double PID;
double setPoint = 90;
int controlPwm = 85;
long lastProcess = 0;
void loop(){
realAngle = map(analogRead(SENSOR), 1023, 0, -39.73, 229.47);
//Serial.println(analogRead(SENSOR));
//Serial.println('gia tri goc realAngle la');
Serial.println(realAngle);
Serial.println(setPoint);
//PID
error = setPoint - realAngle;
//thoi gian lay mau
float deltaTime = (millis() - lastProcess)/100.0;
lastProcess = millis();
// P
P = error * kP;
// I
I += (error * kI) * deltaTime;
// D
D = (lastrealAngle-realAngle) * kD * deltaTime;
lastrealAngle = realAngle;
// Sub pid
PID = P + I + D;
if (PID>255){
PID=255;}
controlPwm = (PID + 80);
analogWrite(CONTROL,controlPwm );
}

WireorSPIlibrary being used (since the MPU communicates through I2C or SPI). I can write an answer once you have included the complete code in your question