Blog

Inspiring belief in a better tomorrow. Equipping kids with the tools to build it.

Dancing Drones

Hack a mini-quadcopter with Arduino

By Diego Araos

Several years ago, I had my first RC Helicopter and ever since then, I fell in love with flying controlled vehicles.

As many realize, actually having your own RC Helicopter, can be an expensive hobby, mainly because you are going to crash it lots of times, and so I stopped doing it after several crashes.

Just a few months ago, and after some years wanting to have a helicopter, I found that the new trend was the so-called multirotor helicopters and probable the most amazing one out there for entusiasts is the AR Drone from Parrot, which is a really good and capable piece of machinery. I was amused on how much the manufactures have improved the stability, control and price.

I decided to get involved one more time in this awesome hobby, and for starters I ordered a little UDI U816 quadcopter. You can get one for less than $40. It's a really stable mini quadcopter capable of doing flips in the air and stabilizing itself with its built-in accelerometer and gyroscope.

Dancing Drones.png

Arduino for the win

I started with Arduino some months ago, since I always wanted to hack my own hardware. I had some experience by hacking a HexBug Spider Robot and decoding the IR commands to control it using my computer.

So I decided to do the same for the mini quadcopter. The problem was that it uses a 2.4GHZ wireless controller instead, so I had basically two options. The first was to get an Arduino extension board to decode the signal and send the commands. After my first experience, I realized that it wasn't that easy thing to do. So I had a different idea: Why not to use the same controller that came with the quadcopter? 

And I was right, it is actually possible to connect some wires to the controller and command the quadcopter with a computer. It's really easy to do, since the only thing you actually do with the controller is to move some potentiometer and thus adjust voltages that control the little quadcopter. The only problem I found is that the signal sent by the Arduino is a PWM (Pulse-width Modulation), and the controller didn't like it so much. We'll see later how to solve this and how did it actually work.

Materials

  • 1x Arduino UNO Rev 3 or similar
  • 1x UDI U816 RC Quadcopter or similar
  • 1x mini-protoboard
  • 4x 630K ohm resistors
  • 4x 10nf capacitors
  • Arduino to Protoboard cables
  • Screwdriver with cross head
  • A wire cutting plier

Instructions

1. Disassemble the remote control

nr1.png

The control has 4 screws, you will have to remove them to get to the main board.

3.png
nr4.png

The mainboard has 6 tiny screws inside that you will have to remove, and the LED screen is also fixed by 2 screws.

5.png

The last thing to do is to crop the battery cables that we'll connect later to the Arduino power supply.

6.png

2. Locate the pins

The controller has 4 potentiometers, 2 on each joystick. They work in such way, that they basically regulate the voltage between 0V and 3V. And this is what we're going to replicate using the Arduino.

In the circuit you will have to locate the pins where you have to solder the cables that will go to the Protoboard.

7.png

You will also have to solder some cable extensions to the power supply input (positive and negative) to the wires you cut from the battery case.

3. Iron the cables to them

Once you have identified the pins, solder the cables. Your mainboard should look like this:

8.png

4. Wire the circuit on the protoboard

This is the tricky part. As mentioned on point 2, we have to output 0V to 3V analog voltages. The Arduino is capable of doing this by using PWM. The problem with this technique is that it uses a square wave to do so. This makes the controller act weird, so we will have to use a low-pass filter, which is basic circuit that uses a capacitor and a resistor to filter the square wave.

This is the schema of the low-pass filter, you have to build this for the 4 pins of the controller.

Resistor should be 630K ohms and capacitor 10nF.

It's a really easy circuit. This is how your protoboard should look like:

Remember to connect the power supply 5V and Ground from the Arduino to the controller:

dancingdrones3.png

And finally, hook up a groung wire to the capacitors.

6. Upload the code on your Arduino

nt _throttle = 3;

int _rotation = 9;

int _axisX = 10;

int _axisY = 11;

void setup()

{

// Set default voltages:

writeVolts(_throttle, 0);

writeVolts(_rotation, 1.5);

writeVolts(_axisX, 1.5);

writeVolts(_axisY, 1.5);

// WARNING:

// Changing freq. will affect millis() and delay() and all depending libraries

int divisor = 1;

setPwmFrequency(_throttle, divisor);

setPwmFrequency(_rotation, divisor);

setPwmFrequency(_axisX, divisor);

setPwmFrequency(_axisY, divisor);

Serial.begin(115200);

}

int debug = 0;

int triggered = 0;

void loop() {

if(debug) {

if(micros() > 1000000 && !triggered) {

  writeVolts(_throttle, 3);

  triggered = 1;

}

if(micros() > 2000000) {

  writeVolts(_throttle, 0);

  return;

}

float val = 5.00 * analogRead(5) / 1023.00;

Serial.print(micros());

Serial.print("\t");

Serial.println(val);

return;

}

if(Serial.available() > 1) { // > 1 because we expect at least 2 bytes here.

int command = Serial.read();

int value = Serial.read();

switch(command) {

  case 0x10:

    sendCommand(_throttle, value);

    break;

  case 0x20:

    sendCommand(_rotation, value);

    break;

  case 0x30:

    sendCommand(_axisX, value);

    break;

  case 0x40:

    sendCommand(_axisY, value);

    break;

}

}

}

void sendCommand(int pin, int value) {

writeVolts(pin, 3.00 * (value / 255.0));

}

void writeVolts(int pin, float volts) {

int pwm = (255.0 / 5) * volts;

Serial.write(pwm);

analogWrite(pin, pwm);

}

void setPwmFrequency(int pin, int divisor) {

byte mode;

if(pin == 5 || pin == 6 || pin == 9 || pin == 10) {

switch(divisor) {

  case 1: mode = 0x01; break;

  case 8: mode = 0x02; break;

  case 64: mode = 0x03; break;

  case 256: mode = 0x04; break;

  case 1024: mode = 0x05; break;

  default: return;

}

if(pin == 5 || pin == 6) {

  TCCR0B = TCCR0B & 0b11111000 | mode;

} else {

  TCCR1B = TCCR1B & 0b11111000 | mode;

}

} else if(pin == 3 || pin == 11) {

switch(divisor) {

  case 1: mode = 0x01; break;

  case 8: mode = 0x02; break;

  case 32: mode = 0x03; break;

  case 64: mode = 0x04; break;

  case 128: mode = 0x05; break;

  case 256: mode = 0x06; break;

  case 1024: mode = 0x7; break;

  default: return;

}

TCCR2B = TCCR2B & 0b11111000 | mode;

}

}

7. Load the software on your computer

To run the software you will need to download Node.js from www.nodejs.org

You will also need git to download the source code from <TODO: upload source-code>

8. Run the server and load the web-application

Run the server with a Terminal window and write down “node index.js”.

Then open your browser and type “http://localhost:3000/”

9. Control the Quadcopter and have fun!

To control the quadcopter just use your arrow keys or click on the virtual joysticks on screen.

Have fun!