RC Quadrotor Helicopter




This project is a RC quadrotor helicopter (quadrocopter, quadcopter, quadricopter, etc). It’s a RC helicopter that uses 4 rotors. You need some pre-requisite skills:

  • How to use Arduino, enough to get started
  • Soldering, wiring, basic electronic skills
  • Basic hand tool operation

A quadrotor helicopter flies with 4 spinning propellers on a + shaped frame.
When one rotor spins faster than the rotor on the opposing side, the faster side will have more lift, and thus the helicopter will tilt. When the helicopter is tilted, the air is being blown slightly sideways instead of directly down, and the helicopter will move.
The propellers also need to be in counter-rotating pairs, two spin clockwise and two spin counter-clockwise. This way, the helicopter does not spin on the vertical axis since the rotational enertia is cancelled out. But when the pair that’s spinning in one direction is faster than the other pair, the helicopter will spin on the vertical axis. This is how the helicopter controls its direction.
We will be building a flight controller circuit that contains an accelerometer and gyroscope sensor so that a microcontroller can detect undesired changes in the helicopter’s angle, and adjust each rotor’s speed accordingly to counter the variation. This microcontroller will do this hundreds of times per second, keeping the helicopter stable in the air.
The flight controller is a completely open source circuit. The circuit schematic and PCB files are provided. The flight controller is completely Arduino compatible. The source code is a modified version of AeroQuad (open source Arduino based quadrocopter control code). The flight characteristics can be adjusted using AeroQuad’s configurator utility.
Attached is a diagram that shows you the direction of spin for each motor, remember this diagram! You won’t be able to fly if your setup does not follow this diagram.
This microcontroller will also take input from a RC radio receiver, so you can control the helicopter from the ground using a RC radio transmitter.
This helicopter will use four brushless motors. Each motor will be controlled by an ESC (Electronic Speed Controller). The ESCs will be controlled by the microcontroller.
A lithium polymer battery will power the entire contraption.
Summary of Downloads:

  • Over 100 pictures in all the steps
  • Step 9 contains flight controller circuit and PCB files
  • Step 10 contains bootloader and core for microcontroller
  • Step 12, 13, 14 contains demo Arduino sketches
  • Step 26 contains the flight control software

Step 1: PartsYou need some pre-requisite skills:

  • How to use Arduino, enough to get started
  • Soldering, wiring, basic electronic skills
  • Basic hand tool operation

A quadrotor helicopter flies with 4 spinning propellers on a + shaped frame.
When one rotor spins faster than the rotor on the opposing side, the faster side will have more lift, and thus the helicopter will tilt. When the helicopter is tilted, the air is being blown slightly sideways instead of directly down, and the helicopter will move.
The propellers also need to be in counter-rotating pairs, two spin clockwise and two spin counter-clockwise. This way, the helicopter does not spin on the vertical axis since the rotational enertia is cancelled out. But when the pair that’s spinning in one direction is faster than the other pair, the helicopter will spin on the vertical axis. This is how the helicopter controls its direction.
We will be building a flight controller circuit that contains an accelerometer and gyroscope sensor so that a microcontroller can detect undesired changes in the helicopter’s angle, and adjust each rotor’s speed accordingly to counter the variation. This microcontroller will do this hundreds of times per second, keeping the helicopter stable in the air.
The flight controller is a completely open source circuit. The circuit schematic and PCB files are provided. The flight controller is completely Arduino compatible. The source code is a modified version of AeroQuad (open source Arduino based quadrocopter control code). The flight characteristics can be adjusted using AeroQuad’s configurator utility.
Attached is a diagram that shows you the direction of spin for each motor, remember this diagram! You won’t be able to fly if your setup does not follow this diagram.RC Quadrotor Helicopter




This microcontroller will also take input from a RC radio receiver, so you can control the helicopter from the ground using a RC radio transmitter.
This helicopter will use four brushless motors. Each motor will be controlled by an ESC (Electronic Speed Controller). The ESCs will be controlled by the microcontroller.
A lithium polymer battery will power the entire contraption.
Summary of Downloads:

  • Over 100 pictures in all the steps
  • Step 9 contains flight controller circuit and PCB files
  • Step 10 contains bootloader and core for microcontroller
  • Step 12, 13, 14 contains demo Arduino sketches
  • Step 26 contains the flight control software

Step 1: Parts

RC radio transmitter and receiver
You need 4 channels minimum but I am begging you to get one with 6 channels. Also get one that uses 2.4 GHz technology if you can. Turnigy has a 9 channel model that is actually very inexpensive, and it runs on an AVR microcontroller that you can put custom firmware on. Personally, I have a old $25 radio that uses 75 MHz FM but I’ve converted it into a 2.4 GHz radio using a conversion kit.
Four brushless outrunner motors are needed. I used hexTronics 20-22L (this number represents the diameter and coil winding configuration of the motor, there’s also a kv value that relates speed and power, higher kv = more powerful faster motor (thanks to the correction from slick8086, I was incorrect to relate power to Kv, it’s the RPM that’s faster if Kv is higher), 800 to 1200 is acceptable motors. They come with a ton of parts (the bullet connectors, heatshrink, propeller adapter, the screws you need, mounting plate, spare shaft and spare C-clip, all included). Get extras just in case one gets damaged in a crash.
Four brushless motor electronic speed controllers (ESC) are needed. One that is rated for 18 amps is enough. I have heard good things about the Turnigy Plush ESCs because they support high update frequencies (more frequent adjustments means more stable flight). I got the HobbyKing brand clones of the Turnigy Plush ESCs because they are cheaper.
Some ESCs are “card programmable”, meaning you can change their configuration using a cheap ($6) programming card, which is really convenient. Buy the programming card that is compatible with the ESCs you’ve chosen. I got the Turnigy ESC programming card because they are compatible with my ESCs.
You’ll obviously need a battery. You will use a 3S1P lithium polymer battery that is rated at least 20C (this is the discharge rating). 3S means 3 cells in series, 1P means one set in parallel. This will give you a combined 11.1 volts. I suggest a 2500 mAH capacity battery (or more). A general rule of thumb is doubling the capacity of the battery means 50% increase in flight time (due to the extra weight).
More info on batteries here: http://www.rcgroups.com/forums/showpost.php?p=1315199&postcount=1
Make sure you pay attention to the type of connector that comes attached to your battery. You’re going to need to get the matching connector. I’ve personally built my entire helicopter using bullet connectors. 4.0mm bullet connectors for the battery and 3.5mm bullet connectors for everything else (the motors come with 3.5mm bullet connectors). (You can get other connectors such as XT-60 connectors, just watch your polarities, also note that all my pictures show bullet connectors)
You need a lot of heat-shrink tubing to act as insulation when using the 3.5mm bullet connectors. Get different colours so you can tell which wire is which.
You need 12 gauge stranded core wire. It must be 12 gauge or thicker to handle the current. It must be stranded core so that it is flexible. Get different colours so you know which wire is which polarity. The best wire is fine stranded copper wire with silicon insulation, but this is expensive.
Get a good battery charger, it must be able to balance and charge multi-cell lithium polymer batteries. I have one of these Turnigy chargers that have many settings, a LCD, and cooling fan, very nice. I also use a laptop power brick to power the charger since an ordinary wall adapter won’t be able to handle the current required.
Get a battery monitor so you know when your battery is low. A lithium battery will become permanently damaged if you drain it below a certain threshold. Having a monitor will prevent you from damaging your battery. I have one of these that reports the status of each cell.
The quadcopter’s frame I use is this one from HobbyKing. For $15, you get every part you need, plus every screw and nut you need. In comparison, a stick of aluminum would cost me $10 from Home Depot, which is not economical in comparison. I suggest you buy several frames so you have plenty of spare “arms” if you crash (plus plenty of spare screws and nuts).
The propellers must be in counter-rotating pairs (a “pusher” and a “puller”). I use 10×4.7 APC slow-fly propellers. 10 indicates diameter in inches and 4.7 indicates pitch. Larger diameter means more lift but requires more powerful motors. 10 inches is about right for the frame size I am using.
You’ll need a entire flight controller circuit (meaning another entire bill of material), I will talk about this in detail later. Meanwhile, you’ll need a USB-to-serial cable (FTDI cable) and an AVR programmer.
Plenty of servo cables are required to connect stuff. A minimum of 6 female-to-female cables is required for the 6 channels from the RC radio receiver to the flight controller.
Velcro tape and double sided velcro strapping will be useful as a lightweight way of mounting things and strapping in the battery.
Get a bubble/spirite level (like this one) to help with sensor calibration.
Make sure you get plenty of extras, stock pile on wire, cables, connectors, heat-shrink tubing, electrical tape, glue, screws, etc.

Step 2: Bullet Connector Soldering

You’ll be doing a lot of soldering, especially with these rather large connectors. I’m writing this section because of the special connectors we’ll be using requires some special soldering techniques. There’s a lot of current going through these wires, and they have to withstand crashes and you yanking on them. So you should do this properly.
You need a good hot soldering iron for this, since the connectors are rather large and act as a heatsink.
First, take a piece of wood, and drill some holes into it to hold your connector while you solder. This is your soldering jig.
Strip your wire, the length of exposed wire should be as long as the cavity in the connector’s end. If you are soldering the 4mm connectors with the polarized housing, make sure the housing goes on first before you solder (see pictures).
Place the connector into the hole in the wood. Then stick your soldering iron’s tip into the small hole on the side of the connector. Fill the cavity with solder (fill the cavity about 60%). While the solder is hot, put the wire into the cavity, continue heating for a few seconds until you are sure the wire has reached thermal equibrium with the solder, and then remove the iron. Hold the wire still until the solder cools and solidifies.
Wait until the entire connector is cool enough to touch. Clean the solder joint with rubbing alcohol.
If you are using the plastic housing, pull on the wire into the housing until the connector clicks into the housing. If you are not using the housing, then use heat-shrink tubing to insulate the connector. See pictures.

Step 3: Preparing the Motors

If you got the same motors that I did (hexTronics 20-22L), then you’ll notice that the shaft sticks out the bottom of the motor. I cut this off with a cutoff-disk attached to a rotory tool. This is because I don’t want the motor to be damaged from a minor bump with the ground.
When you are cutting off the shaft, make sure you first wrap the entire motor with tape first to prevent metal shavings and debris from entering the motor. Dust and debris can damage the windings and bearings. Also when you are done, thoroughly clean the motor by spraying it with compressed air.
Assemble the motor, attach the large propeller adapter, and the bottom mounting plate, using the appropriate screws that are provided.
The motors comes with 3.5mm bullet connectors and heat-shrink. Solder the male connectors to the motor. The female connectors are meant for the ESC (we’ll do that later).

Step 4: Understanding Brushless Motors

It is important for you to understand how brushless motors and ESCs work, so that you don’t destroy your ESCs.

To reverse the direction of motor spin, DO NOT REVERSE THE POWER INPUT TO THE ESCs.
You’ll note that there are three wires that goes between the motor and the ESC. These motors are three phase motors, meaning there are three coils inside. The coils are energized in sequence to make the motors spin. So the ESC’s job is to energize the coils in sequence, but it needs to time each energization correctly so the motor can actually accelerate to the right speed. The ESC has a microcontroller inside that turns on or off the coils using FETs and also determines timing by measuring the feedback in the coils caused by the movement of the magnets.
Now you should understand that to reverse the direction of spin of the motor, you can swap any two of the three wires between the motor and ESC. To visualize this, if the original sequence was:
123123123123123
and we swap 2 and 3, we get:
132132132132132
and thus the direction of spin is reversed.
Also, the ESCs contains a 5V voltage regulator (most likely a cheap 7805), and a low battery cut-off feature. Our flight controller will use this 5V power supply.
The cut-off feature means when your lithium polymer battery is drained, it will stop spinning the motor to protect the battery. This is because permanent damage can occur to your battery if it is drained below a threshold. But when the motor stops spinning, the voltage regulator still provides the 5V. This is so that servos on an airplane can still function using that 5V supply, and the RC airplane can still glide to a safe landing even without an engine.
However, in our helicopter situation, if one motor dies, the helicopter will spin out of control in the air. It will become a safety hazard to everybody around it. Thus, we set the cut-off voltage to “low” so we maximize flight time. We rely on our battery monitor instead, so we avoid over-draining the battery.
A side note: some ESCs can be hacked! You like hacking, right? Read this: http://www.rcgroups.com/forums/showthread.php?t=766589 . The advantage of I2C controlled ESCs is higher update rates, more precision, and only takes two wires to control up to 127 motors. It’ll take some small changes in the compilation options of our flight software to use them since the code is already available. However, for the rest of this instructable, I’m still using PWM controlled ESCs.

Step 5: Preparing the ESCs

Solder the female 3.5mm bullet connectors to the ESC’s output wires. Also solder connectors to the power input wires of the ESC. Make sure you keep track of what polarity of your connectors are so you don’t connect positive to negative.
Also, please load the following settings to all 4 ESCs using the programming card:

  • Brake: Off
  • Battery Type: Li-xx
  • Cut Off Type: Soft-Cut
  • Cut Off Voltage: Low
  • Start Mode: Normal
  • Timing Mode: High
  • Li-Po Cells: 0 (meaning auto-detect)
  • Governor Mode: Off

Also see these links (not by me):

Step 6: Preparing the Battery Monitor

This step is optional but I recommend it so you never plug in your battery monitor backwards.
Get some 4 pin JST connectors to replace the existing connector on your battery monitor.
I also used a permanent marker to indicate the connection polarity.
Place some velcro on the battery monitor so you can mount it to the helicopter easily. This is optional, I usually just leave it dangling off the battery.
Watch the monitor all the time. As soon as one of the lights go red, then land as soon as possible. Draining any one of the three cells below the threshold will cause permanent damage to that particular cell.
The flight controller also has battery monitoring capabilities, but it does not monitor all 3 cells like this one does. Other battery monitors have a buzzer which is better than lights, but they also do not monitor individual cells.

Step 7: Making the Power Distribution

This is sometimes called a “power spider”.
You need to split the power from the battery into the four ESCs. Solder some of your 12 gauge wire into a spider-like shape to distribute the power. You need two of these “spiders”, one for positive, one for negative. I suggest you colour code the positive as red and the negative as black (or blue).
One pair of the wires should be significantly longer, this is the wire that connects to the battery. I have cut this wire and placed a pair of 3.5mm bullet connectors there so I can swap out the battery connector if I decide to buy a battery with a different connector.
Make sure you insulate these two sets from each other. I placed the center solder joint into a bottle cap and filled it with hot glue.
Solder 3.5mm bullet connectors to the split-off ends so you can connect to your ESCs, make sure you don’t screw up the polarity.
On my setup, I added a 5th wire pair just in case I need it later (maybe to power a camera). I suggest you do the same, but note that the male bullet connector will be exposed, so make some “insulated dummy connectors” (the yellow things in my pictures) with spare connectors and heat-shrink to put over the exposed connector.
There is no power switch in this setup. A switch that has a decent current rating would be too heavy. To turn off the helicopter, just disconnect the battery, which is a good habit anyways.

Step 8: Flight Controller Overview

The flight controller is a system that uses a microcontroller to control the quadcopter. It needs to take inputs from the user via a RC radio receiver, input from a accelerometer and gyroscopic sensor. Its outputs are to the four ESCs.
The sensors being used are the BMA180 3-axis accelerometer, and the ITG-3200 3-axis gyro. Both of these are available in a breakout-board format from SparkFun so you don’t have to solder the chips. Note that both of these are digital sensors, this means they both have internal analog-to-digital converters (ADC) that perform better than the integrated ADCs of most microcontrollers. Both of these sensors use the I2C bus, which means only two wires are required to interface both sensors. The I2C bus can run at 400 KHz.
The RC radio receiver will have 6 or more channel signal pins, each signal will be connected to one pin on the microcontroller. These signals will be pulse width modulated signals, so the microcontroller will measure the width of each pulse to take input from the user.
The ESCs each expect a pulse width modulated signal. One pin on the microcontroller will be connected to one ESC. The microcontroller will output pulses to each ESC to control their individual speeds.
Although an ordinary Arduino would have enough performance as the microcontroller, I decided to use an ATmega644P in my design so I have more memory and more pins to experiment with. My design still uses 16 MHz, uses the Arduino bootloader, and it is compatible with the Arduino IDE.
The ATmega runs at 5V because 5V is required at 16 MHz, this 5V power supply will be provided by the ESCs since they all have a built-in 5V voltage regulator.
The sensors run on 3.3V and thus our circuit will contain a 3.3V low-dropout voltage regulator that converts the 5V to 3.3V so we can safely interface with the sensors.

Step 9: Flight Controller In-Depth

It’s hosted on Google Code, I am the sole author of all the wiki pages, the circuit, PCB, and bill-of-materials. The code is heavily modified versions of AeroQuad and MultiWiiCopter with all original copyright notices, but also including modifications by me.
You may try to replicate it, all the design files (I’ve included the Gerber files too) and bill-of-materials are provided. I am also in the process of designing a “retail” version, which may be sold once I test the design and finalize it.
See this wiki article about how to assemble my flight controller design, it’s written by me, and the part-list is provided here.
To make the PCB, generate the Gerber files from the Eagle CAD PCB files, there are plenty of guides on the internet showing you how to do this. Here’s the SparkFun tutorial. I usually send the Gerber files to Seeed Studio’s Fusion service (10 PCBs for $28, takes 5 days to make + shipping time).
Below is a short version of the assembly guide, for more detail, see the full guide (linked above).

Note that all resistors are in 0805 packaging, although 0603 will also fit perfectly fine. They should be 1/16 watt or greater. Note that all capacitors, unless otherwise specified, are ceramic chip capacitors in 0805 packaging (or 0603 since they will also fit perfectly fine). They should be rated 16V or greater.

This assembly guide also contains some notes about the various areas on the circuit.

The ATmega644PA obviously must be installed, solder in a 40 pin DIP socket so you are able to replace the IC if you need to.

The ATmega644PA requires a 16 MHz resonator.

You must solder C1 and C2, which are 0.1 uF decoupling capacitors for the ATmega644PA. Also solder C9 which is a 0.1 uF decoupling capacitor for the analog reference.

On the bottom of the board, there is a footprint labelled “AREF-SEL”, which allows you to choose the analog reference voltage by soldering over the pads labelled 5V or 3V3. You may also use a 0 ohm resistor here, or an ferrite bead. Note that AVCC is always connected to 5V.

Microcontroller Supporting Areas

The reset switch must be installed, R13 10K ohm is the pull-up resistor for the reset switch. This resistor is optional because the ATmega644PA has a built-in pull-up resistor on the reset pin. You should install this if you do not trust the built-in resistor.

A push button labelled “BOOT” can be installed only if you are using a non-Arduino-standard bootloader. I personally hate the way “time sensitive” bootloaders work. This button is active low and connected to PB6 on the ATmega. Be sure to enable internal pull-up resistors for this button.

The ISP header (labelled AVRISP) should be installed if you need to use an AVR programmer (perhaps to load the bootloader for the first time, etc). The long line at the side indicates the side that the “red wire” (also pin 1) of the cable should be, and the short line at the bottom indicates where the notch of the connector should be.

LED Indicators

LED1, LED2, LED3 are 3 mm LEDs, choose your own colours. They can be mounted vertically or horizontally (pointing out). Please watch the polarity indicated by the hole shape and silkscreen. R3, R4, and R5, are all 1K ohm resistors to limit current to these LEDs.

Power Supply

Solder a LM1117 3V3 regulator in SOT-233-3 packaging where indicated on the PCB. Also solder the accompanying C3, which is 1 uF.

LED-PWR is a 3 mm LED that indicates that there is power present on the 3V3 supply bus. You may solder this vertically or sideways (pointing out). R12 is the 1K ohm current limiting resistor for this LED.

Two rows of 3 pin male headers should be installed at “3V3-TAP”, these headers give you access to the 3V3 supply bus. Two rows of 3 pin male headers should be installed at “5V-TAP”, these headers give you access to the “SYS” 5V supply bus.

If you are powering this circuit from a battery, you must install a LM1117 5V regulator in SOT-233-3 packaging where indicated on the PCB. This may be omitted if you are using the ESCs as the power supply (be sure to set SJ1 correctly), or under other circumstances that you are under.

The 1 uF capacitor C4 should be always soldered regardless of whether or not you are using a 5V regulator.

The battery power input is used if you need to connect a battery. There are four ways to do this:

  • Using a barrel jack
  • Solder wire directly onto PCB (you can enlarge some holes to act as strain relief)
  • using a screw terminal
  • Using a 3 pin header

A beefy diode should be installed at D2 to protect the circuit from a battery connected backwards (so omit this diode if you believe in your own competence, you must bridge the pads of the diode footprint with solder if you omit this diode). This must be a diode that can handle 20V of reverse voltage, and handle 1.5A of forward current. The footprint is SMB or similar.

C5 and C6 are aluminum electrolytic 5.3mm x 5.3mm capacitors that must be installed, solder them in the correct orientation according to polarity.

RC Input

PORTC’s pins PC7 to PC2 are connected to 6×3 headers, solder in male headers here. These are dedicated to taking RC pulse signals from your RC receiver. The voltage for the center pin can be connected to 5V or 3V3 using SJ2, and remember that there is a “5V-TAP” and “3V-TAP” if your receiver needs power from a 7th cable.

Important: If you select V-RC with SJ15 (to use the same voltage that the RC inputs are using) and you have selected 3V3 using SJ3, then you must not use SJ17 to select anything. Doing so will cause the 5V supply to be joined with the 3V3 supply, which can cause damage to 3V3 devices.

Sensors

Solder R1 and R2, which are 4K7 pull-up resistors for the I2C bus. Be sure that you disable internal pull-up resistors in the software (note: already done for you in my modified software). This allows you to use 3V3 I2C sensors without using a level shifter.

Install a BMA180 accelerometer breakout board and a ITG-3200 gyro breakout board, both from SparkFun.

You may also choose to install a BMP085 barometric sensor breakout board, and a HMC5842 compass breakout board. These are optional and you can configure the software to use them for altitude-hold and compass-heading-hold.

Outputs to Motors and Servos

Four sets of 3-pin male headers should be soldered near “ESC” labels, these are connections for standard RC pulse signal ESCs. SJ1 can be used to connect the voltage supplied by the ESCs to the main system supply bus. (note, for this instructable, please connect SJ1)

Serial Ports

There are a few possible serial port devices. The ATmega644PA has two serial ports, US ART0 and USART1, they are labelled SER0 and SER1 on the PCB.

Use horizontal mount male headers for the FTDI cable connection. This connection is always powered by 5V, RX and TX are at 5V level. Use SJ9 and SJ10 to decide whether to connect this to SER0 or SER1. (note, for this instructable, select SER0)

If you just want something that flies and don’t care about the details, then just build the circuit and upload the code. If you want to know how I designed this circuit, continue reading this step.
The first step is to draw out the circuit.
I started with the microcontroller. I knew it needed a reset button, a clock source (16 MHz ceramic resonator), a 6-pin header so I can program it with an AVR programmer, a serial port connection for the Arduino bootloader, and also 5V of power.
The sensors are connected to the I2C pins of the microcontroller. I2C busses require 4.7 kilo-ohm pull-up resistors to 3.3V to work. I can’t use the ATmega’s internal pull-up resistors because those go to 5V, which will damage the sensors.
The 3.3V voltage regulator is connected to the 5V power supply. Some capacitors are added in various spots to decouple and filter.
Connections to the RC radio receiver and the ESCs are simply male header pins connected to the microcontroller. The three pins are always “signal, +5V, ground”.
This gave me a basic circuit. After, I alter it to add features such as indicator LEDs, solder-jumpers for configuration, xBee socket, etc.
Laying out the PCB is also simple.
I start out with a square outline. Then I added slots to each corner of the square so I can mount it to any frame. Although I highly suggest you design the mounting hole patterns to suit whatever frame you get.
Next, I put down a ground plane on both sides.
The sensors needs to be placed in the correct orientation, as you can see, they are at a 45 degree angle.
The microcontroller is sort of the center piece. Header pins are placed where they are needed. The ESC pins are placed in each corner of the square to make them easy to identify later. The RC radio receiver input pins are placed in order to make them easy to connect. Any external connections such as the FTDI serial port are placed on the edge to make it easy to connect/disconnect. LEDs are also placed on the edge to make them more visible.
Remember that:

  • Power rails might require a thicker trace on the PCB
  • Avoid sharp corners
  • Place capacitors physically close to the component they are meant for
  • Label as much as possible
  • Just because your PCB manufacture says they can do 6 mil trace thickness or clearance, doesn’t mean you should try
  • 0805 sized surface mount components have pads that are as big as through hole components, so to save space and weight, I suggest you use surface mount components. For the big ATmega644P, I used a through hole version because I wanted to use a chip socket so it’s replacable.

When you think the design is ready, print out a 1:1 scale copy on paper to make sure that all the text will be readable, and all the component footprints are correct.
Keep tweaking the design until you are ready for manufacturing the PCB. Export the Gerber files and send them to the manufacture. I usually use Seeed Studio who will make ten copies for $28 + shipping within 5 days + shipping.
Solder your circuit together and it should be good-to-go.

Step 10: Preparing the Microcontroller

If you don’t have the Arduino IDE, download it and install it. I am using version 0022.
The following steps are explained in detail in this wiki article: http://code.google.com/p/ro-4-copter/wiki/GeneralSoftwareSetup
This page is just a really short summary of what is already in the above wiki article!
The Arduino bootloader should be programmed into the microcontroller first. This step requires the use of an AVR programmer. However, after the bootloader is flashed into the microcontroller, you will only need an USB-to-serial cable (such as an FTDI cable) to upload code from the Arduino IDE.
The bootloader (I’ve attached it) is modified slightly since I’m using the ATmega644P instead of the usual Arduino’s ATmega328P. The files are provided. The fuse-bits need to be written to the correct values as well.
AVRDUDE is the utility that we use to flash the bootloader .hex file into the microcontroller. The AVRDUDE commands you’ll need is
“avrdude -c programmer_name -p atmega644p -U flash:w:bootloader_filename.hex -U lfuse:w:0xFF:m -U hfuse:w:0xD8:m”
Pay attention to the programmer_name and the bootloader_filename! The fuses are to get the ATmega to use the 16 MHz resonator, set the bootloader size, enable the bootloader, disable JTAG and enable SPI downloading.
Also copy the bootloader folder “Ro4Copter_Boot” (remember to rename it without the date version) as …/arduino-0022/hardware/arduino/bootloaders/Ro4Copter_Boot.
Also, download the Arduino “core” I’ve provided here (called Ro4Copter_Core, remember to rename it without the date version), and place it into the “core” directory within Arduino so you get …/arduino-0022/hardware/arduino/cores/Ro4Copter_Core . Also modify the boards.txt file to include an entry to use this core. This will allow the Arduino IDE to compile for the ATmega644P instead of the original Arduino’s ATmega328P. Be sure to select the correct board entry inside the Arduino IDE menus. For more details on this step, check out the wiki page I linked above.

The sketch you need to compile is provided in step 26. Compile it and upload it to the ATmega644P using the bootloader later.
The next few steps will help you understand what exactly the code is doing. Skip them if you don’t care.

Step 11: Explaination of Source Code

As with all Arduino sketches, there is a setup routine and a main loop. The setup initializes everything, and the main loop performs the input, calculation, and output.
The PWM signals from the RC radio receiver is taken in using “pin change interrupts”. When the voltage on the input pin changes, the interrupt routine is called, and a time stamp is taken. The pulse width is calculated from the differences between the time stamps.
The PWM signal output to the ESCs is generated using several timers with “compare match outputs”, which means the pulse width is set, and the timer will automatically pulse the pin for the set period of time.
The sensors communicate using the I2C bus, which is a synchronous data bus that has excellent support for multiple devices communicating using only 2 wires.
The main loop is divided into tasks, each of which is executed at a different frequency. This gives each task a priority. The code that keeps the quadcopter stable has the most priority. Stuff like communicating with the computer has less priority. It is possible for you to add GPS navigation code if it is given lower priority.

The later steps will have demonstrations that specifically demonstrate each technique and technology individually.

Step 12: Arduino Demo: PWM Input

Here is a Arduino sketch that shows you exactly how pin-change-interrupts and a timer is used to read in pulse widths from several signal wires. Whenever a change in pin state is detected, the interrupt vector records a timestamp using the timer, and the difference between timestamps is the pulse width.
Also I’ve attached a logic analyzer screenshot to show you what the signals from my RC radio receivers look like. Each one of those pulses have a pulse width between 1000 and 2000 microseconds, the period is about 20 milliseconds.
For more information, research:

  • PWM
  • Servo Signals
  • ISRs in AVR (Interrupt Service Routine)
  • PCINT, Pin Change Interrupt
  • 16 bit timers in AVR

Step 13: Arduino Demo: PWM Output

Attached is an Arduino sketch that shows you how our code generates PWM signals so each ESC knows how fast to spin the motor.
The timer compare output feature of the timer is used to generate PWM signals. When the timer reaches 0, it turns on a pin, when it reaches a certain number (that we specify), it turns off the pin. This generates a square wave with a variable duty cycle.
Although normal servo signals usually have a period of about 20 ms (meaning a frequency of about 50 Hz), the output from our microcontroller have a shorter period (thus a higher frequency, about 250 to 300 Hz). The Turnigy Plush ESCs (and the HobbyKing brand clones) have been reported to be able to handle the higher frequency, and thus more adjustments in motor speed can be made per second, therefor the quadrocopter will become more stable.
I’ve also attached screenshots from my logic analyzer to show you what the 4 signals look like.

Step 14: Arduino Demo: Sensor Reading

This step contains an Arduino sketch that will take readings from the two sensors (BMA180 accelerometer and ITG-3200 gyro).
These two sensors are connected to your microcontroller using a I2C bus. This type of bus is designed to allow multiple devices to communicate together using only two wires.
I’ve also attached the logic analyzer waveforms of the I2C bus signals. (both screenshot and Saleae Logic 1.1.8 session file)
For more information:

The flight controller software will initialize the accelerometer by first resetting it, then setting up a 10 Hz low-pass filter and setting the read range to +/- 2 G. Read its datasheet and see my demo code for more details about how to do this. There are other features such as interrupts, tap detection, etc, that we are not using.
The flight controller software will initialize the gyro sensor by first resetting it, then setup its 10 Hz low-pass filter, and telling it to use its own internal oscillator. Read its datasheet and see my demo code for more details about how to do this. This sensor allows you to use an external oscillator and also has digital temperature outputs, but we don’t use those features. RC Quadrotor Helicopter SchematicStep 15: Control Principle

The code allows you fly the quadcopter in 2 modes:
One is where the accelerometer is ignored, and you control the helicopter’s angular velocity with your joystick. This is refered to as “aerobatic” mode. In is mode, the code’s job is to spin the helicopter when you want it to, and stop it from spinning when you don’t. The advantage of this mode is that you can perform stunts like flips and barrel rolls.
The other mode is where the accelerometer is used with the gyro sensor to calculate the quadcopter’s current angle with respect to the ground. You control the angle of the quadcopter instead. So in this mode, if you let go of the joystick, the quadcopter should stay at a horizontal level. If you move the joystick to a non-center location, the quadcopter will spin to one angle, then stay at that angle (and move since it’s blowing air at an angle instead of straight down). This mode is refered to as “stable” mode or “attitude” mode. This mode requires an accelerometer to work, and will not allow you to perform flips and rolls (since your joystick does not do 360 degree rotations).
To calculate the quadcopter’s current angle, the angular velocity is read using the gyro sensor. Angular velocity multiplied by time equals the amount of rotation during that time. There’s a lot of error in this process due to drift and noise in the gyro sensor. To correct this error, the accelerometer is used to measure gravity, which is mixed into the calculation. For more details on this, please see:

The flight controller uses the this information along with a PID controller to control the motors. PID means “Proportional, Integral, Derivative”. See these links:

To understand the “P” term, imagine you are trying to park a car. If you are very far away from the parking spot, you drive fast towards the spot. As you get closer, you should slow down. If you drive over the line, you need to reverse (and thus your velocity is negative). Speed = distance to spot * “P” in this case.
To understand the “I” term, imagine you are trying to park your car but your car is tied to a rope that won’t let you reach the spot. You keep trying harder and harder until the rope snaps. Engine RPM = I term * integral of distance to spot over this period of time.
To understand the “D” term, say you moved 10 meters towards your spot, since you know you made progress, you should slow down a bit. Speed = difference between position * D term.
Now imagine instead of a parking spot and car, you use this PID controller to get your quadcopter from one angle to another angle by adjusting the difference in the rotor’s spinning speed. By tuning the values of the PID terms, we can get the flight controller to make big adjustments and small adjustments accordingly, keeping the quadcopter stable in flight.

Step 16: Quadcopter Assembly

Since your circuit is now done, you can assemble the entire helicopter. I can’t let you tune the helicopter without it being able to fly first.
Remember to unplug the battery whenever you make electrical changes (connecting and disconnecting things).
The entire frame takes several steps to assemble, there are way too many pictures for one “step” so I’ve divided them. I’ll be going into a lot of details because the kit does not come with instructions.
Also the pictures may not follow chronological order, this is because I may have decided to re-order some steps.

Step 17: Reinforce Arms

The frame kit comes with the arms pre-assembled. Although the joints are glued, I found them too unreliable and prone to cracking. Also some joints have gaps which are too big.
Get some Gorilla Glue, the general purpose kind. Apply it to the joints. When this glue cures, it expands to three times its original volume, it will actually fill in the cracks for you.
By doing this, the amount of vibration in the frame is lowered, giving your sensors much better readings.

 

For more detail: RC Quadrotor Helicopter




This Post / Project can also be found using search terms:

  • Here is a Arduino sketch that shows you exactly how pin-change-interrupts and a timer is used to read in pulse widths from several signal wires Whenever a change in pin state is detected the interrupt vector records a timestamp using the timer and the dif
Clip to Evernote

Leave a Comment

(Spamcheck Enabled)

Read previous post:
The Zeta minimal Z80 toggle-switch computer
The Zeta minimal Z80 toggle-switch computer

The Zeta is a minimal Z80 toggle-switch computer. It has a Zilog Z80 microprocessor, 256 bytes of RAM and the...

Close
Scroll to top