Hey guys, in my previous posts, I have made the frame and the flight control system for the cheap drone we are making which you can check here (DRONE FRAME and FLIGHT CONTROL SYSTEM). Now we have to program the Arduino in order to operate as a receiver and flight controller. I am still working on my own code which is very difficult as the flight controller is very complex. So, I am using the Multiwii platform which is an open-source and I have modified it a little bit in order to suit our needs. You can find the download link below.

The receiver and Flight controller code (MultiWii)

So, guys, you can download the MultiWii from my google drive. Click on the LINK HERE to download the file(.RAR) or Click on the LINK HERE to download it in a '.ZIP format'. So make sure u have tool such as Winrar to extract the files. Note that this is a compressed file in which you will find 2 folders. Make sure you have the necessary tools to unzip it. I recommend using Winrar but if you have any other unzipping tool, that will work too.

Once you have downloaded the file, go to the downloads folder and search for it. It is named as “Multiwii_drone”. Right-click on it and select extract here as shown. This will extract the folders to the download folder. You can extract it in any other folder you are more comfortable with.
Once finished extracting, you will find two folders named as “Multiwuii_withNRF” and “MultiWiiConf”. Open the MultiWii_withNRF folder and click on MultiWii_RF24 and then select MultiWii_RF24 and open it in Arduino IDE.

Once open, perform the following checks. First of all, go to NRF24_RX.cpp and check if the CE and CSN pin initialized in the code is the same as you connected the Arduino with the NRF24l01 CE a CSN pin.

Also, check if the pipe address is the same as you are using for the transmitter (you can see the transmitter code here). This is very important for our transmitter and receiver to communicate. Now go to Config.h and scroll down to see if the following is uncommented.

Once everything is good, we can now upload the code to the Arduino. Connect the Arduino with your pc using the FTDI programmer.

Now go to “Tools” in your Arduino IDE, and select “Arduino pro or pro mini” from the “Board:” and then make sure that the “Atmega328p(5v,16Mhz)” is selected in the “processor”. If not, make sure to select it.

Now select the COM port that you have connected your Arduino with your PC in the “port” and you are good to go. Now upload the code to the Arduino and wait till it says “Done uploading”.

Now go to the download folder and go to the “MultiWiiConf” folder and open it. You will see the following folders.
Now open the folder depending on your operating system. Note that if you are using Windows with 64 bit and it is not opening, try to open the 32-bit version named “application.window32” and open the MultiWiiConf application. Note that this is a java application. Your PC will require the Java Runtime Environment (JRE) to run this. So, make sure you have it installed on your PC. 

If you do not have it, you can download it from this Link and run it. Click on next where required and click on install. Once it has been successfully installed, you are good to open the MultiWii. Now open the MultiWiiConf application again which will look like this.
Now go to the software, on the left side, select the COM port that your PC is connected to the Arduino board. Then click on the start, and then click on read. You should see the drone to appear on the screen like this.
Now take your drone, move it around and see it is detecting the movements. If it is detecting, that means our flight controller is good to use and if now, I recommend you to check your connections again. Now we have to see if it is receiving the signal from our transmitter. So, let's program the transmitter now.

Transmitter code:
/***************************************************************************/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

const uint64_t my_radio_pipe = 0xE8E8F0F0E1LL; //Remember that this code should be the same for the receiver

RF24 radio(9, 10);  //Set CE and CSN pins

// The sizeof this struct should not exceed 32 bytes
struct Data_to_be_sent {
  byte ch1;
  byte ch2;
  byte ch3;
  byte ch4;
  byte ch5;
  byte ch6;
  byte ch7;
};

//Create a variable with the structure above and name it sent_data
Data_to_be_sent sent_data;



void setup()
{
  radio.begin();
  radio.setAutoAck(false);
  radio.setDataRate(RF24_250KBPS);
  radio.openWritingPipe(my_radio_pipe);

  //Reset each channel value
  sent_data.ch1 = 127;
  sent_data.ch2 = 127;
  sent_data.ch3 = 127;
  sent_data.ch4 = 127;
  sent_data.ch5 = 0;
  sent_data.ch6 = 0;
  sent_data.ch7 = 0;
}

/**************************************************/


void loop()
{
  /*If your channel is reversed, just swap 0 to 255 by 255 to 0 below
  EXAMPLE:
  Normal:    data.ch1 = map( analogRead(A0), 0, 1024, 0, 255);
  Reversed:  data.ch1 = map( analogRead(A0), 0, 1024, 255, 0);  */

  if(analogRead(0) > 532 ){
    
  sent_data.ch1 = map( analogRead(A0), 532, 1024, 0, 255);
  }else{
    sent_data.ch1 = (0);
  }
  sent_data.ch2 = map( analogRead(A3), 0, 1024, 0, 255);
  sent_data.ch3 = map( analogRead(A2), 0, 1024, 0, 255);
  sent_data.ch4 = map( analogRead(A1), 0, 1024, 0, 255);
  sent_data.ch5 = digitalRead(2);
  sent_data.ch6 = digitalRead(3);
  sent_data.ch7 = map( analogRead(A4), 0, 1024, 0, 255);

  radio.write(&sent_data, sizeof(Data_to_be_sent));
}
/**********************************************************************/

Note that I am using the transmitter that I have made in my earlier tutorial. However, I have made some changes. I was using the 3.3V from the Arduino earlier to power our NRF24l01. But with the antenna one, this was a problem as it could not deliver enough current for it to work. So, I am using a bug converter instead. I have connected the input of the buck to the 7.4V lipo battery I am using and then I have adjusted the output till I got 3.3V at its output and then I connect it to the input of the NRF. Always adjust the voltage before connecting it to the NRF.

Now copy the code and upload it to your transmitter.

Open the MultiWii application, reset the Arduino and play with the joystick and see it is detecting the signal. You can see it on the top right side of the MultiWii application.


Now put Yaw to maximum and throttle to minimum and you should see the “ARM” tag turns green. This mean our drone can now fly. Increase the throttle and see if all the motors are working.


This is it guys. This tutorial ends here. Hope you guys like it.
See the videos of this tutorial on my YouTube channel here.