Tuesday, November 12, 2013

Controlling toy quadcopter(s) with Arduino

The last couple of days I have done some more work on the small toy quadcopters (now dubbed HCD for Hamster Cage Drone). The goal was to hack the communication so that they could be controlled using computer vision software. Basically the poor mans version of this (don't bother you have already seen it).

UPDATE: I have made a Arduino library for controlling this particular Quadrotor (may work with similar products). You will need to build this simple hardware (discribed on this page) to use the library. All parts (apart from Arduino) may be found inside the remote controller that comes with the quadcopter.

The first thing I did was to take the remote control handset apart to see what kind of radio system was used.
 Inside was pretty much what you'd expect. A couple of cheap paper PCB's with not a lot on them.

The radio communication is handled by a small discrete radio module. After a lot of internet digging it turned out that the module was based on the BK2421 2.4GHz tranceiver IC. This also seem to be the choice for a lot of cheap RC toys coming out now.

With a datasheet for this chip and an oscilloscope it was simple enough to figure out the pin configuration for the SPI communication between the radio module and the handset.

Using an ArduinoUNO to eavesdrop on this comunication I was able to figure out the initialization and thereby the mode of communication. Here is a annotated list of the initialization sequence.

Without going into detail about the low level communication the following happen when the handset and
Quadcopter are turned on:
1) Handset broadcast it's unique network address or ID.
2) Quadcopter receives the broadcast it acknowledges this and start listening to data from that ID.
3) Upon acknowledge the handset then start transmitting flying data packet every 20 mS.

Multible Quadcopters can be controlled simultaneously by assigning them different addresses.
The passing of ID is done on one fixed radio channel and flying data is sent on one of about 12 random radio channels. The quadrotors seem to auto scan the radio channels until they find data.

Flying data is transmitted as 8 byte packets in following format:
Byte 0 = throttle 0-255
Byte 1 =Yaw 0-255
Byte 2 =Yaw_trim 0-128
Byte 3 = Pitch 0-255
Byte 4 = Roll 0-255
Byte 5 = Pitch_trim 0-128
Byte 6 = Roll_trim 0-128
Byte 7 = Fly/run 0=fly, 16=run (toggle button on handset)

Next I created a base station that would connect to the quadrotors. I happened to have some RFM-70 modules that contain the same BK2421 chip. Not reading the datasheet properly I initially thought that this module required 3.3V logic and hence all the resistors. They are not needed since the BK2421 has 5V tolerant data pins.

NOTE: CE goes to pin 8 (missing on drawing)

I eventually ended up with a much simpler set-up using just the module salvaged from the handset and an Arduino.
To enable future experimentation I have written a Arduino library for connecting to one or more of these quadcopters.
The library should work on any ATMEGA88 to ATMEGA328P based Arduino boards.
If you want to have a go yourself you may get the HCD's here or here among other places. These are just random hits on google, you may get them elsewhere.

Less crappy video here.

Please share if you find other toys that may be hacked using similar methods.
Happy hacking.


  1. THANKS A TON! What a usefull INSTRUCTABLE! Man you have to post it there for votes & Rewards! THANKS A LOT!

  2. Always wanted to try something like this :D.. In another note.. What laptop is that?

  3. Such a cool project. Nice work on keeping it incredibly budget-friendly too! I would be curious to hear more about the results! What are the benefits of adding the Arduino? Is this enough to program the quadcopter for an autonomous flight? (These may be silly questions... I'm new to this.)

    1. The arduino lets you fly the Quadcopter from a computer. I am currently using a kinect to make the Quads hover at a fixed point in space. I plan to release the code to do this later.

  4. Hi, I've just attempted this hack and while trying to remove the module from the remote ive taken the tips off the end and cannot seem to get the solder to stick to the pins. Do you know what i need as a replacement as i don't want to have to buy another drone just for the transmitter. Any help would be much appreciated. Regards Richard

  5. You can use any board with the BK2421 chip on it. I have used the RFM-70 breakout board available from e.g. farnell.
    Here is a couple of links:




  6. Thanks.

    Im in the UK and for some reason i cant seem to find an RFM-70. At farnell it says discontinued.

    Will this component work the same?

  7. It looks like it would be compatible. Nordic does not say which chip it is based on but registers and functionality seems to be the same.
    I may order a couple of these to see if they work.

    Actually the datasheet for this module is way better than the one I use and has much better discription of how to program it...

    If this module is compatible with my library then these will be too:


    And that would be really interesting...

  8. I've ordered some too, so if you could keep me posted on your progress that would be great.

    I'm very new to electronics and programming, I'm actually an Architecture student and my aim is to try and control the drone through a program called Rhino using firefly for grasshopper (http://fireflyexperiments.com/).

    From what i've read to control the drone I think i'm going to have to write to the arduino using a serial write command in firefly does that sound right?

    I want to do something similar to this http://www.youtube.com/watch?v=vaO3LBTyoAs

  9. That vision control software looks pretty awesome. You will propably need to write a little Arduino code that connects the serial comands from Firefly to pitch,roll,yaw and throttle on the Quadcopter. I suggest modifying the "flying" example from the HCD library.
    If you are completely new to this I suggest you team up with someone with a little Arduino experience.
    Happy hacking.

  10. Hi, the above components came and ive connected them up but it doesnt seem to be binding with the drone. Have you had any luck yourself?
    Any help would be great.

    1. Have you send a "0" (zero) followed by a return to the Arduino? It need this before it attempts to bind.
      The drone needs to be powered for some seconds while sitting completely still before it will bind. You may remove the black cap to reveal the drone circuit board. On the board there is a red and green LED. When un-bound these LED's flicker forth and back with about 5Hz when the binding starts the LED's flicker much faster around 25Hz. When binding is complete the green LED goes solid.
      Can you send me a schematic/picture of your set-up?
      I have not yet received my radios. Things are much slower here :)

  11. This comment has been removed by the author.

  12. I have got HCD to bind but I can't seem to get the controllers to work... I took them out of the controller, and I believe hooked them up to the correct ports. They just don't respond to anything. Thanks for the help

    1. Check the analog inputs. Make sure the quad is not moving while binding.

  13. This comment has been removed by the author.

  14. You did a great job in this post. it ia really helpful information to build a toy copter. I know one of the best copter that is flash copter. visit to be a vandor of flashcopter at www.flashcopter.com

  15. hi there i wanna to ask if there any possible to get a code for the quadcopter
    i am fresh in this field thanks :)

    1. I already posted the code here on this blog.
      Enjoy :)

  16. Hi
    I was wondering if you know if this will work on a http://www.banggood.com/Wholesale-WLtoys-V959-V949-V929-RC-Quadcopter-Spare-Parts-Receiver-Board-V959-06-p-61089.html

    And controlled in the same manner as you did with an arduino?

    1. Sorry i don't think so. The radio may be the same but the protocol is propably different.

    2. Is there a way for me to read the protocol frome the drone? How did you do it?

  17. Could you go into more detail about how you got the unique identifier of the handset (RX Address and TX address)? We're Comp sci students and this is an Electrical Engineering problem. ANY assistance would be GREATLY appreciated.