It’s a wish of every engineer to Built their own Multirotor from scratch, Quadcopter to be more specific.It’s not at all a hard thing to build one, But many of them face a problem when it comes to Flight Controller aka the brain of the Multirotor.I know that there are plenty of ready-made pre-flashed Flight controllers in the market for cheap, But have you thought of building your own Flight controller with your Arduino? So this is the right place to understand and build your own Flight controller for your quadcopter or Multirotor with your Arduino.
Now the questions come, Where and how do I get the code for the quadcopter? So the answer is Multiwii.
MultiWii is a Very popular flight controller software for DIY Multi-rotors with a large community. It has Support various Multi-copters with advanced features such as Bluetooth Control by your Smartphone, OLED Display, Barometer, Magnetometer, GPS position hold and return to home, LED strips and many more.
So let’s build our Flight controller using Arduino!
In this tutorial, we are going to use an Arduino Nano and Build Flight controller for Quadcopter i.e Multi-rotor with 4 Propellers.You can use any Arduino that is available to you, But I personally prefer the Nano version of Arduino as it has the same Microcontroller as the Arduino UNO, Small in size, Light weight and also features a USB mini type B port.The pin configuration remains same for all Arduino types.
The Multiwii Supports a wide range of Gyroscope and Accelerometer Modules, But in this tutorial, we are going to use GY-521 cheapest available and consist of MPU 6050 i.e a Gyroscope as well as Accelerometer both in a single chip.If you want to have Altitude Control You can use GY-87 which has a barometer in addition.
You can use your traditional Transmitter Receiver for communication i.e to control your Quadcopter
If you want to control your Quadcopter using your smartphone via Bluetooth then you get this Functionality in Multiwii.For that, you will need a Bluetooth Module like JY-MCU, HC-05, HC-06 and much more.Using this Bluetooth functionality you get a range of 20 meters(Depends on module used and smartphone).This feature is completely OPTIONAL
We will use a small 3mm LED for indicator purpose.You can use a Buzzer instead of LED.This Feature is Optional but I recommend this feature.
Things You Need:
- Arduino UNO or Nano
- MPU-6050 Module
- Prototype Board
- Male and Female Headers
- LED and a 330 ohm Resistor
- Thin Wires
- HC-05 Bluetooth Module (Optional)
Let’s Follow the below schematics and build the controller.
D3 << ESC 1 Signal Pin
D9 << ESC 3 Signal Pin
D10 << ESC 2 Signal Pin
D11 << ESC 4 Signal Pin
Bluetooth Module Connections
TX << RX
RX << TX
A4 << SDA
A5 << SCL
D8 << Anode Leg of LED
D2 << Throttle
D4 << Elerons
D5 << Ailerons
D6 << Rudder
D7 << AUX 1
NOTE:- Ground all the ESC’s,Bluetooth Module,MPU-6050 and Receiver by connecting GND(Ground) Pins of all Mentioned parts to the GND Pin of Arduino in Your Flight Controller.
Wiring the Circuit
First, we Solder the Female Headers on to the prototype board so as it can accommodate the Arduino Nano in it.Make sure you solder them in the center of the Prototype board so that we can solder the headers for ESC’s, Receiver, Bluetooth Module, MPU and also have some room for other additional features which can be added later on.
Now we solder the Male headers for the ESC’s and Receiver on to the right side of the female headers for Arduino.
The Rows of Male headers for your copter ESC’s will depend on the type of multi-rotor your are Building.If you are Building a Quadcopter you are going to have 4 Motors with 4 ESC’s so you will need 4 Rows with 3 male headers in each Row.Out of the 3 Headers in Row, the First header is for Signal Pin, Second for 5v(Some ESC may not have this Pin), and Third for Ground.
Similary in Tricopter you will need 3 Rows, in Hexacopter 6 Rows and so on.
After we finish soldering the ESC’s headers we can now solder the Headers for the Receiver.
Now a Multirotor normally has Four Channels which are Throttle, Pitch, Yaw, and Roll.The fifth channel is Auxillary Channel (Used for changing Flight Modes).
So we need 5 Rows of male Headers out of which one will have 3 headers in a row and others will be having a single header in a Row.
We also need to solder two female headers for the MPU and Bluetooth Module.I soldered the Header for MPU on the Left and For Bluetooth Module on the bottom left.
Now we need to connect all headers to Respective Arduino Pins with wires.I used Breadboard wires for connections as in above Image.
Do the Connections in sequence so that you don’t miss out any connections
I first connected all The Grounds to the Ground of Arduino i.e connected Ground of all ESC’s (The rightmost Headers), Ground of Receiver (The rightmost header of the Throttle signal header, Ground of MPU and Bluetooth Module.
Then I connected the SDA and SCL of MPU to the A4 and A5 of Arduino and the TX and RX of Bluetooth Module to the RX and TX of Arduino.
After that, I connected all Signal pins of ESC1, ESC2, ESC3, ESC4 to D3, D10, D9, D11 and Then the signal pins of Receiver i.e Throttle, Elerons (Pitch), Ailerons (Roll), Rudder (Yaw), Auxillary to D2, D4, D5, D6, D7.
Also, we connect the positive Terminal (Long Lead of the LED to the D8 Pin of Arduino and the negative Terminal (Short Lead) to the Ground of Arduino with a 330-ohm resistor in between the Ground and Negative Terminal.
The only thing we are left with is, Powering the Circuit i.e providing Positive 5V to Arduino, MPU and Bluetooth Module.You will need a small 5v Battery to power all of these by connecting Everyone in Parallel i.e Connecting the Ground(Black wire) of the Battery to the Ground of Arduino and the 5V( Red Wire) to the 5V pin of Arduino, 5V pin of MPU, and the 5V pin of Bluetooth Module.
In my case, I used the 5V from my ESC’s to power On the circuit because they had a BEC (Battery eliminator circuit).Not all ESC’s have this Feature, So you may need to use a battery instead.
Solder male headers to your MPU 6050 or the one you wish to use.
Now Flip the board and connect all components i.e Arduino, MPU, and Bluetooth Module to the Prototype Board on to their respective Headers.
Now Our Flight controller is ready!! It’s time to Program the Arduino with the Multiwii Code for your Multi-rotor.
Flight Controller Code
First Download the Multiwii Code from the Below Download Link.
Extract ‘Multiwii_2.4.zip’ that you downloaded and Open it, now open the Multiwii Folder.
Search for Multiwii File with ‘.ino’ or File type specified as ‘Arduino File’ using Arduino IDE.
(Don’t open any ‘H File’ or ‘CPP File’ those are the support files for our Multiwii Code, Only open Multiwii.ino File)
After opening the Muiltiwii.ino file in Arduino IDE you will see many tabs Alarms.cpp, Alarms.h, EEPROM.cpp, EEPROM.h and many more.
Out of those many Tabs search for Config.h and Open it.
After you open the Config.h Tab Scroll down till you find ‘The type of multicoptor’
Search for the type of Multi-rotor you are Building and Uncomment it.
For example, I’m building Quadcopter with X configuration so I will uncomment QUADX by removing the ‘//’ before ‘#define QUADX’, similarly you can do it with your type of Multirotor.
Again scroll down till you find ‘Combined IMU Boards’ and uncomment the type of your Gyro+Acc Board.Mine was GY-521 so I uncommented GY-521.
You can even add more sensors like BMP 180 barometer or SRF-04 Ultrasonic sensor and many more by uncommenting them in this section.
Scroll down again till the ‘Buzzer Pin’ setup and uncomment it.
Scroll again and Find ‘Buzzer’ and uncomment the first 3 options.this are for Flight indicator Purpose.
Similarly, you can add many features like OLED Display, LCD Display, GPS etc just by uncommenting them in the config.h.Now the Code has to be flashed to Arduino.
Uploading the code
Remove the Arduino from the Flight controller Board and connect it to your computer via USB Cable.Don’t connect the Arduino directly while it is on the Flight controler Board, always remove it and then connect.
Go to Tools>>Board Manager and Select the Arduino that You are Using.In my case, it’s Arduino Nano.
Now go to serial Port and select the COM Port to which your Arduino Nano is connected to.
Upload the code by Clicking on the Arrow Symbol as shown in above Image, and wait for the code to get Uploaded.
Once the code is Uploaded Disconnect the Arduino From Computer and place it again on to your Flight Controller.Connect your Receiver to the Respective Headers.connect the 5V Battery to power ON the Flight controller.
I connected all ESC’S to Flight Controller Because I used the ESC’s to provide 5V to all parts of the Flight Controller i.e using the BEC (Battery Eliminator Circuit) of the ESC.So I didn’t use any external 5V Battery.
The Led Indicator Blinks, this indicates that the Flight Controller has Booted.
Now connect the Flight controller to the Computer via USB Cable and let’s see how it is performing.
After the connecting the flight controller to the Computer, Open the Multiwii 2.4 Folder >> MultiwiiConfig Folder.
Now open the Folder which will be compatible with your Operating system, mine is 64bit Windows so I will open ‘application.windows64’ Folder.
Run the MultiwiiConfig Application
Select the COM port to which your Arduino is connected and then click on Start.
Now You can see the Live Flight controller Data in the MultiwiiConfig.Moving your Flight Controller will reflect the Gyroscope and Accelerometer Data on Screen.You can see the Orientation of your Flight Controller at the Bottom Right.
Here we can Tweak the PID values of the Flight Controller for a Smooth Flight.We assign various Flight Modes to the Auxillary Switch from here.
Moving the Transmitter sticks will show the values of respective Channels.The Respective Motor Speeds are shown on the Right Box.
Just attach your Flight Controller to your Multirotor and it is ready to Fly!!!