Hi there! I am doing a drone project with an arduino Uno board. My drone consists of four BLDC motors each hooked up to an ESC and all powered by a big LiPo battery. Then I have the arduino board controlling the ESCs with a bluetooth module so I can control my drone from my phone.
My drone can take off, but not for long because it is imbalanced and veers off to the side. I would like to use the MPU6050 gyro/accelerometer sensor to keep my drone level, but I'm quite new to all this stuff and I don't know how to make this chip communicate with the ESCs to keep them level. Is it possible to code this on my own? Is there software I could use for this? Libraries that might help out? Just looking for a place to start.
Currently my code looks like this without any gyroscope:
#include <Servo.h> //Servo library
#include <Dabble.h> //Dabble library for bluetooth connection
#define INCLUDE_GAMEPAD_MODULE //Includes Dabble Gamepad module
#define CUSTOM_SETTINGS
Servo ESC1; //define the 4 motors
Servo ESC2;
Servo ESC3;
Servo ESC4;
int Speed; //create a variable for speed of motors
void setup() {
Dabble.begin(9600); //Set the baud rate for the HM10 to 9600
ESC1.attach(11); //Set the motors to their corresponding pins on the arduino
ESC2.attach(12);
ESC3.attach(9);
ESC4.attach(10);
}
void loop() {
Dabble.processInput(); //Refresh information from the Dabble application
Speed = GamePad.getRadius(); //Get a value from the Dabble application corresponding to the distance of the joystick from center (0 to 7)
Speed = map(Speed, 0, 7, 0, 180); //translate the value from the Dabble application (0 to 7) into the "language" of the motors (0 to 180)
ESC1.write(Speed); //Set the motors to the new speed
ESC2.write(Speed);
ESC3.write(Speed);
ESC4.write(Speed);
}