Teach your PC to fly a Mini-Drone!

A few months ago, I watched this TED talk where they setup an indoor arena and did some amazing things with drones.  It got me thinking, and it inspired me to build something like that for myself – but on a much smaller and cheaper scale.

In the video they use an expensive real-time infrared motion tracking system (I am guessing something like these Optitrack systems) to measure the position of the drones, and then uses a computer to calculate and send control signals to coordinate the drones. At a high level, my setup works in a similar way, as shown in this diagram:

Here’s a photo of what my setup looks like:

drone setup
Photo of the first working setup.

This is a list of the items needed to build this:

Component Description
USB Camera ELP 2megapixel Hd Free Driver USB Camera Support Mjpeg Linux Android Windows Developing Board,usb Camera Module
Arduino Microcontroller Board Arduino UNO R3 Board Module With DIP ATmega328P(Blue)
Nordic Semiconductor 2.4GHz Wireless Card Addicore nRF24L01+ Wireless AddiKit with Socket Adapter Boards and Jumper Wires
Cheerson CX-10 Mini-Drone Cheerson CX-10 Mini 29mm Diameter 4CH 2.4GHz 6 Axis Gyro RC Quadcopter UFO RTF Green
2 blade guards for the Cheerson CX-10 Upgrade Cheerson Cx-10 Propeller Prop Blade Guard Cover Bumper Protection Protector Green White

Total cost for these items was around $85. In addition to the above, you might also need a folding table and stack of books to hold up the webcam as I did, but you can probably think up something more refined!
Here is a video of it working:

Here are some links to further information on how this all works:

  1. Setting up the programming environment on your PC
  2. Detecting the circles from the webcam
  3. Finding a low-latency web camera

Source code:

  1. nrf24_cx10_pc  – The source code for the Arduino to send 2.4GHz wireless signals to the drone
  2. pc-drone – The Python / OpenCV code used to track the drone and decide on how to adjust the drone controls

We will also be sharing this project at the Bay Area Maker Faire from May 20-22, so please stop by the MakeHardware.com booth and check it out!

17 thoughts on “Teach your PC to fly a Mini-Drone!”

  1. Thanks for this project. I managed to implement the entire project. The only difficulty is the blobs detection. I don’t have a perfect brightness. Do you have a tip for an optimal detection ?
    I will soon post an article on my blog to show a demo. Thanks again 😉

    1. That’s awesome that you got it to work! Can’t wait to see your post about it!

      In order to help calibrate the lighting, I would take a couple of snap shots under your specific lighting conditions. You can do this by running the fly_drone.py script, and pressing the space bar, and it will save some of the images to the drive. THen I would try using the pc-drone/detectDrone/detectDrone.py script to loop through the images and see in which snapshots the blobs were detected. You can tweak the parameters in the detectDrone.py script, and then make the corresponding changes in the fly_drone.py code.

  2. Will the nRF24L01+ wireless transmitter work with the onboard Cheerson CX-10 rx? If not is there a tx card compatible with the current rx if soldering is not a strong point :)?

    As well, is there any way to relay images from the drone to the arduino for cv processing from the drones camera, can the images/ videos be streamed or processed on the PC?

    1. Yes, the nRF24L01+ does work with the onboard Cheerson CX-10 RX. This entire project was done without soldering! The only wiring needed is the jumpers from the Arduino Uno to the nRF24L01+ card which is described on the Github page https://github.com/perrytsao/nrf24_cx10_pc

      The Cheerson CX-10 doesn’t have a camera on it so there is no way to stream images. There are many other drones that do such as the CX-10W or the Hubsan H107D or Estes Proto-X. They use different transmitter/receivers though, so it would require some different hardware.

  3. Hi, is it possible to command the drone via serial monitor instead of using blob detection?
    Basically, can we do basic controls with it using just an arduino without python?

  4. Yes, you can control the drone just by sending serial commands to the Arduino. The commands can be generated by Python as they are here or any other language. You will still need to use the Arduino firmware in this repository https://github.com/perrytsao/nrf24_cx10_pc or something equivalent so that the Arduino can properly interpret the serial commands and send the radio signals to the CX-10.

  5. Hi, thanks for the post here, helping me to ultimately get a project up and running with a Syma X5C-1 which isn’t working yet. I plan to test with a CX-10 and then convert later.
    To get just the base CX-10 running though, could you explain which of the .ino files you load up in the Arduino ide, to enable just the connection phase.
    Do I need to run the test.py file you mention in the python environment to get some response or will running the arduino files alone give me enough to show that at least I have a connection to the CX-10.
    Some help here would be appreciated to put me down the right path before I look into it in real detail.

    1. The file to load onto your Arduino is:
      https://github.com/perrytsao/nrf24_cx10_pc/blob/master/nRF24_multipro/nRF24_multipro.ino

      That .ino file will already bind to the CX-10 after it reboots and you first turn on the CX-10. You can tell it is bound because the LED on the Arduino will go from blinking to solid.

      The serial_test.py file is only necessary if you want to send commands to the CX-10 in order to see if you have a response. It is not needed for just binding.

      1. Tks, I’ll try that out.
        Once I have the Syma up and running I will be trying to do something slightly different to yourself, get it tracking a moving object, but the work you did on the rest of the project could well help.
        rgs

      2. Hi mhadmin,

        Awesome work on the project and I am very excited to get this up and running on my own.

        I am also trying to get the CX-10 code up and running using nRF24_multipro.ino and I need a little push in the right direction. When I compile the .ino file I am getting a bunch of errors about functions that don’t exist in the current code. Just to verify with you – do I need to comment all the code that does not belong to the CX-10 such as process_CG023, process_V2x2, etc? I also verified that I do have in fact have all the libraries needed. Here is a list of all compile errors:

        Arduino: 1.7.11 (Windows 8.1), Board: “Arduino Uno”
        Drone_Test.ino: In function ‘void loop()’:
        Drone_Test.ino:201:24: error: ‘NRF24L01_Reset’ was not declared in this scope
        Drone_Test.ino:203:29: error: ‘NRF24L01_Initialize’ was not declared in this scope
        Drone_Test.ino:213:37: error: ‘process_CG023’ was not declared in this scope
        Drone_Test.ino:216:36: error: ‘process_V2x2’ was not declared in this scope
        Drone_Test.ino:220:36: error: ‘process_CX10’ was not declared in this scope
        Drone_Test.ino:223:34: error: ‘process_H7’ was not declared in this scope
        Drone_Test.ino:226:38: error: ‘process_Bayang’ was not declared in this scope
        Drone_Test.ino:229:37: error: ‘process_SymaX’ was not declared in this scope
        Drone_Test.ino:232:37: error: ‘process_H8_3D’ was not declared in this scope
        Drone_Test.ino: In function ‘void init_protocol()’:
        Drone_Test.ino:391:24: error: ‘CG023_init’ was not declared in this scope
        Drone_Test.ino:392:24: error: ‘CG023_bind’ was not declared in this scope
        Drone_Test.ino:395:23: error: ‘V2x2_init’ was not declared in this scope
        Drone_Test.ino:396:23: error: ‘V2x2_bind’ was not declared in this scope
        Drone_Test.ino:400:23: error: ‘CX10_init’ was not declared in this scope
        Drone_Test.ino:401:23: error: ‘CX10_bind’ was not declared in this scope
        Drone_Test.ino:405:21: error: ‘H7_init’ was not declared in this scope
        Drone_Test.ino:406:21: error: ‘H7_bind’ was not declared in this scope
        Drone_Test.ino:409:25: error: ‘Bayang_init’ was not declared in this scope
        Drone_Test.ino:410:25: error: ‘Bayang_bind’ was not declared in this scope
        Drone_Test.ino:413:24: error: ‘Symax_init’ was not declared in this scope
        Drone_Test.ino:414:24: error: ‘SymaX_bind’ was not declared in this scope
        Drone_Test.ino:417:24: error: ‘H8_3D_init’ was not declared in this scope
        Drone_Test.ino:418:24: error: ‘H8_3D_bind’ was not declared in this scope

        Error compiling.
        This report would have more information with
        “Show verbose output during compilation”

  6. Hi mhadmin again,

    Sorry for keeping on bugging. I am trying to figure out how you used the python test script to work (serial_test.py) with the already present Arduino code to command/test the drone. Can you please push me in the right direction?

    Thank you for your help!

    1. Ha! I got it to work. If anybody else is having trouble. Upload the Arduino code first (do not open the serial monitor), execute the python script (assuming you have python installed and the necessary modules), turn on the CX-10, wait for it to connect, then control it via your keyboard.

      Excellent work mhadmin and thank you for your project! My next step is incorporating the camera.

  7. Have you heard if anyone has tried this with a raspberry pi zero w? I would like to try, but am a bit new to this whole thing. The RPI zero w has wireless already, and a sweet camera module, and all that is less than $40.

Leave a Reply

Your email address will not be published. Required fields are marked *