Low Cost Arduino Based Auto-Stabilizing System

There are a lot of choices when it comes to picking a flight controller for your quadcopter.   If you are looking for a low cost way to auto-stabilize your quadcopter, this is the guide for you!

Before we get into the details of this project, let me say there are cheaper ways of creating a auto-stabilizing system such as using the sensors out of the Nintendo Wii controllers, but I choice this method for it’s simplicity and small form factor.  The skill level for this project is Intermediate.  This guide requires you to have experience uploading Arduino code and reading schematics.  That said, let’s get started!

The parts list is as follows:
1 Arduino Nano Board / Arduino Nano from UK store
Breadboard
Jumpers Wires Set
Sparkfun 6DOF IMU
Logic Level Converter
Break-Away Headers

This project is based on the Arduino Nano board.   This board features a ATmega328 the same micro controller as the Arduino Uno.  The Nano pack the same functionality as a Uno (minus the DC power jack) all in a small form factor.   The sensor board (IMU) is the Sparkfun 6DOF IMU.  This IMU contains the 3-axis ADXL345 accelerometer and the 3-axis ITG-3200 gyro.  The IMU is used to sense the orientation of the quadcopter in space.   The next component in our parts list is the Logic Level Converter board.  This board converts a 5V signal to a 3.3V signal or convert a 3.3V signal to a 5V signal.  The Sparkfun IMU is 3.3 volts board and the Nano is a 5 volt board.  In order for the Nano to read the IMU’s data we need to bring the IMU signals voltage from 3.3 volts to 5 volts.

I am using a breadboard and jumper wire for demonstration and experimenting purposes.  If you choice to use this flight controller in a quadcopter, please use a ProtoBoard and solder your connections.

Let’s get started

First, place the Nano board along the center of the breadboard.  Each row of pins need to be on each side of the center divide (See photo).  Note: Each numbers row is electrically connected.   The center divide separates the numbered rows electrical connection.

Next place the Sparkfun 6DOF IMU along the F column.  Place the Logic Level board across the center divide.

Before we wire the components, we need to upload the flight controller code to the Nano.
The firmware and software I am using is the Aeroquad software.  The Aeroquad platform uses regular Arduino boards to run their flight controller software.

  1. Download the firmware
  2. Download Arduino version 0023
  3. Download the Software for PC or Mac
  4. Upload the firmware via Arduino.
  5. Install the software for your PC or Mac

Once the code is uploaded to the Nano and the software is installed on your computer, we can now wire up the boards.

The wiring in this picture looks scary but it’s actually pretty simple.

Use the following schematic diagram to wire your board with the jumper wires.  For this guide it is not necessary to wire the motors, RC Receiver and RC battery.   I have included those connections, if you wish to proceed further with this project.

Open the Aeroquad software type in ‘57600’ for the baud rate. Under ‘Com Port’ take note of the listed ports. Connect the Nano board to your computer. Click refresh under the ‘Com Port’ and select the newly listed ‘com port’ and click connect.

Once connected a 3D quadcopter will appear on the screen. Move the flight board around, the onscreen quadcopter will mirror your boards orientation.

This guide stops short of wiring the motors and RC receiver.  These connections should be soldered, but if you wish to experiment further and wire the motors and RC receiver here’s how.

Take the Straight Header pins and break them off into 3 pins headers. Place the 3-pin header into the female connector of the ESC.  Make the signal wire (usually the white wire) of the ESC is connected to the signal wire from the individual pins of the Nano board.

For the R/C receiver order this Jumper Wire and connect one female end to the signal row of your receiver.   Cut off the other female end and solder the individual wires to their respective pins on the Nano board.

117 Responses to “Low Cost Arduino Based Auto-Stabilizing System”

  1. Giovanni says:

    Im trying to upload the FLIGHT CONTROL code to the arduino board but its detecting an error in the code please help!

  2. Giovanni says:

    Error problem resolved. I deleted the code and downloaded a fresh one and it works now. Another question: can I use the Arduino Mega 2560 for this project as I already have one. If yes what other electronics Do I need?

    • Russell says:

      Yes, I think it is possible to use a Arduino Mega. The code supports the Arduino Mega, however I am not sure if the pins are the same for the Arduino Mega and Mini. You may have to define the Arduino Mega in the code and change the upload board to the Arduino Mega 2560. If you do proceed with the Arduino Mega, I would like to know how you made out. And no other electronics is needed.

  3. A.Amr says:

    Hi
    i am trying to use the code you provided and giving me hundreds of errors ! should i do something special before uploading the code

    i am using arduino uno …
    regards

  4. Eduardo says:

    It would be possible to use the 3.3V output of the Arduino and dispense the logic level converter?
    Why you didn’t used this output? Instead of the 5.5v.

  5. CHulla says:

    its awesome. I m gonna try this at home.

  6. Federico says:

    You can connect a barometric sensor and a magnetometer to stabilize both axes X and Y axis Z
    thanks
    best regards

  7. Brendan says:

    To build a full quodcopter, are there any other electronics that I need other than these three parts? I have an Arduino UNO which I was going to use instead of the NANO. Other than the motors, R/C receivers, and battery what do I need?

    Basically, what I’m asking is, what does this low-cost alternative replace in your parts list under ‘Intelligence (Electronics Guide)’? From what I understand is that it replaces the ArduPilot Mega and ArduPilot Mega IMU. Is that right?

    I’m a complete beginner at this, but I like the trial-and-error aspect of making everything myself.

    • Russell says:

      The Arduino Nano or Uno is the substitute for the ArduPilot Mega. The Sparkfun IMU is a substitute foe the ArduPilot Mega IMU. As far as thing you need for auto-stablizing flight, all you need is a Arduino Board, the Sparkfun IMU and Logic Level board.

      • andrea says:

        i’m a beginner too, i’m going to make this project, can you show me a complete scheme that shows the esc connection and the tx module. Thanks a lot.

        • Russell says:

          The diagram above does show how to connect the ESC’s and Radio Receiver to the flight controller. What exactly are you looking for?

          • Andrea says:

            I calculated the total cost of these 3 modules about 100€, what do you think about this module selled by hobbyking
            HobbyKing Multi-Rotor Control Board V3.0 (Atmega328 PA) less than 20€?

          • Russell says:

            I haven’t tried the HobbyKing Flight controllers. What I can say about the parts in this tutorial are high quality parts. I am interested in knowing how good the HobbyKing Control performs.

  8. Brendan says:

    I’m having a problem with running the AeroQuad Configurator.app. It keeps coming up with “AeroQuad Configurator.app Alert Could not find the LabVIEW Runtime, you may need to install it.” I have installed it. Twice. What am I doing wrong? I’m also unsure of how to upload the firmware to the Arduino. I’ve downloaded the firmware but there are 25 files in the folder and I’m not sure which one to use to upload to the Arduino Nano.

  9. Rahul Vyas says:

    Hi,
    I have a arduino pro mini 5v 16Mhz. Will it work? And also have LLC nd IMU 6dof.

    Thanks,
    Rahul

  10. Rahul Vyas says:

    But my arduino dosnt have the same ports?
    I am new to quads so do you think my this quad wil fly or i should go by a shield first?

    Will buy Urgently.

    Thanks,
    Rahul

    • Russell says:

      If you have a Arduino and the other parts already, then it is free to try and get it working. You certainly need to have some knowledge on wiring electronics and programming an Arduino. If you feel comfortable enough with the tutorial then I would give it a try.

  11. deepan says:

    hi,,,i m using this software for the first time…..
    i m getting an error while trying to connect my arduino uno rev3 with aeroquad… do need to do anything with my uno??? first??

  12. Hiwa says:

    For controlling signal coming to the arduino from receiver, do we need to use timer or how to capture the PWM signal coming from radio controller receiver?
    why did you connect the receiver output to pin number 2,4,5,6,7,8? is these pins contain some special feature or what?

    Thanks

    • Russell says:

      These ports are just used to reading the PWM signals from the receiver. These ports are nothing special. The Arduino board can read the PWM signal natively.

  13. Hiwa says:

    Dear Russell,

    How to read 6 channels while there is only one input capture in the arduino nano? is it possible to read all signals simultaneously? like reading Pitch and throttle at the same time? and how?

    thanks

    • Russell says:

      Why do you have only one input left on the Nano? Any of the pin can be an input pin. If you want to read more than one input on the same channel then you will have to use “serial” communication to concatenate various signals.

  14. Hiwa says:

    I am not saying that I have only one pin left, I meant there is only one Timer to be used for capturing PWM signal from receiver. my question was how to capture PWM signal coming from receiver using Arduino nano like you use ?

  15. allanGEE says:

    Nice write up!

    However, I believe you need to connect the 3.3V on the sensor and on the line converter to the 3.3V on the arduino — not to each other.

  16. Peter Depudyt says:

    Hi Russel,

    Why don’t you use I2C instead ? much easier and only 2 wires needed.

    It is also possible to use both 5v and 3.3v are analogue inputs. You can use the VRef input for setting the correct reference voltage level.

    Just my 2cts

    Peter

  17. Suraj Srinivas says:

    Hello, that’s an awesome website that you have got here! I have tried to implement this system myself, using analog gyros and accelerometers. I am experiencing a lot of magnetic disturbance once I get the motors running, and hence the angle readings are all getting distorted. Did you not experience any such effects? Do you think that digital IMUs are immune to such problems?

    • Russell says:

      Are sure the reading are not due to vibration? Analog and Digital accelerometers and gyros work the same way but a digital accelerometers have ADC to convert the signal to a digital signal.

  18. Fernando says:

    it will not compile with arduino 1.0 can you please edit your article and specify the arduino version that you are working with. thank you =)

  19. Alex says:

    Hello,

    can I use this software + hardware with arduino uno?

  20. Aditya Bhat says:

    To what pins should I connect the barometer if I use the aeroquad software?
    Regards Aditya

  21. tensa says:

    i just want to ask how to relate the values obtained from the 6 DOF to the motor speed so i can stabilize the quadcopter? what are the common equations used in stabilizing the quadcopter?

  22. Ben says:

    Hi Russel,

    Im using your code with the Arduino Uno R3
    Had to make some minor adjustments to find the gyro and acclerometer on the serial monitor. Having an issue with aeroquad and a driver i seem to be missing, managed to sort it downloading driver now.

    However my problem is that regardless of the aeroquad configurator. after i upload the code to the board. remove the usb and attach my battery, i cannot seem to get the gyro to calibrate or the motors to arm. Im using a Topfire R/C 6 channel but after the intial start up sequence i go to arm and there is no confirmation beep. even throttling up nothing spins for me. After unplugging all the motors and re plugging this time listening to their beeps. I have not managed to get any further.

    Is there any paramters that i need to adress in this Aeroquad Configurator or should i be able to just fly it.

    Really stuck so please reply asap

    regards Ben

    • Ben says:

      Looking at the configuration i see a motor setup so after ive uploaded the code to the board do i need to upload from the configuration aswell?

  23. Ernie says:

    Hey, I’m a Videographer & I’ve been trying to make a Quadcopter for my GoPro H3 with useing an Arduino. I’ve seen people use an XBee Pro for wireless controll, you think this software will work with XBee instead of a Regular RC controller if so there’s soooo much more that can be done with this setup. Like useing pan & tilt on cam, GPS, etc. Can you help me with this? I’m great with elecronics but not so much with the programing side, thank you for any help.

    • Russell says:

      You can use Xbee’s for telemetry. For controlling the quad via Xbee along with pan & tilt controls, GPS you will want to use a ArduPilot Mega or similar controller. The nano simply doesn’t have enough inputs and outputs.

  24. Paul says:

    I am trying to upload it but i get lots and lots of errors in the AEROQUAD.H file. Can someone help me?
    Best regards
    Paul

    • CHulla says:

      Same problem here. I connected Arduino nano and tried to upload Aeroquad Firmware given above. But Error shows in Aeroquad.h that are

      ” are not declared in this scope”.
      secondly “byte does not name a type”.

      need help.

  25. Alex Morin says:

    Do we still need 4 ESC to run the four motor i assumed we still need them but in case, and my other question is do we need to run the power and ground from the r/c reciver and of yes where do the go?

    • CHulla says:

      Hi Alex,
      Offcourse! we need ESC for each motor on Copter installed (e.g Xcopter need 4ESCs and hexcopter needs 6ESCs).

      About the second question, i m not sure what you asked, but the reciever gets power from Flight Controller and Flight controller gets power from ESCs (There is a power supply(5V) inside ESC called BEC).

  26. Fbrand619 says:

    Thank u so much for this write up… Getting ready to do my build in about a week and had some questions…
    1. Does the esc only connect to the board with one wire?
    2. If the other 2 wires do connect where do they go?…

  27. Jamie says:

    Hello, I am new to all this UAV stuff but I am keen to learn and play around, what I wanted to ask is would I be able to use a Arduino Mega 2560 Board and the use a MinIMU-9 v2 Gyro, Accelerometer and Compass?
    What I would like to also ask is would there be enough input and out puts to later mount a gps etc to make fully unmaned.
    Thanks for your time.

  28. brian says:

    Hi
    I have a hobby king multirotor v3 board.
    I found a way to upload arduino code to that board.
    Will the code work??

  29. Abhijit Kumar says:

    Can i use 6 channel PS2 controller to control the flight…if yes can u tell me more abut the connection to be made when connecting it with rx mode…?????

    • Chris says:

      I believe you could, using something like an OpenLRS transmitter (Which is just an arduino with a TX module in it) and look up the PS2 protocol. If you are talking about the PS2 as in the peripheral interface, then some libraries for ardunio have already been made for PS2 keyboards and mice.

  30. Rik says:

    I uploaded the code to my uno, however the configurator can’t connect.
    When i send a Q or S via the serial monitor it does respond but when i use the configurator i get VISA: timeout expired before operation completed.

  31. rezazulfan says:

    i just want to ask how to relate the values obtained from the 6 DOF to the motor speed so i can stabilize the quadcopter? and how to give a command from remote to quadcopter?

  32. Sree says:

    How can I replace normal RC with Xbee? Can you explain the procedure?
    To which pins I can connect the Xbee module? How to create a PC interface of control using Xbee? Will I be able to stream the video data recorded in Xbee to my PC?

    I am newbie and any help is greatly helpful.

    Thank you.

    • Russell says:

      For this project you will need a radio. Xbee’s can provide telemetry data and depending on flight controller be able to send commands to the aircraft. For video streams you will need a separate video transmitter and receiver. The bandwidth of video is too large for Xbee’s bandwidth.

  33. sagar g bhoi says:

    i am an E&C eng. student . i want to make a quad copter as my last year project.please guide me that how can i achieve this.? and how can i make this.? please guys help me..

  34. johnleo says:

    is the code perfectly compatible with atmega328 ? and can i connect those motors without esc’s?

    • Russell says:

      The Nano uses a atmega318. If you are not going to use a Nano, then you you will have to match up the pinout with your board and the code. You will have to use ESC’s to control your motors. There is really no way around it.

  35. steven says:

    Can I use the 10dof board to simply hookup to the UNO and still use the AEROquad software or does the software not support it

  36. montupet says:

    is radio controlled or not?

  37. Saur says:

    Can you tell me other cheap options than this freedom IMU?

  38. Germany says:

    hello everybody
    I had an error for compiling the firmware could you please help???

    error: ‘BYTE’ was not declared in this scope

    it’s not used any more by arduino!! what could i do??

    regards

  39. Eocke says:

    I would like to know if there is a way to use the same project on a helicopter and use it the same way as the quadcopter? thanks!

  40. sukkhi says:

    Awesome russell…….
    Surely i’d get some help…..

  41. Coriolanus says:

    Is it possible to use IMU to correct the position of an UAV because of the drift? In the cases where GPS unit is not precise enough.

    Thank you.

    M.

  42. Mohammad.z says:

    Hi:
    I want to use 9DOF IMU with arduino mega 2560 is that possible ???
    what are requirements ???? what should I do to make it possible ???
    libraries ???? what should I change in codes ???
    sorry for that much question !!! :)

  43. Bobarry says:

    Can’t wait to see it in a Quad! Interesting. Bo

    • Mike McCary says:

      The reciever connections have 3 wires a signal, ground and voltage. I assume that only the signal wire is used because there are no servos. The electronic speed controller or throtle supplies the reciever with power and uses the signal wire to control the motor speed. On this the speed controllers are connected to the nano. Do I have to put the ground and voltage from one of the speed controllers to the reciever. I have spectrum 7 channel radio do I set it up as an airplane with no mixing

  44. Ssr says:

    Hi i have a arduino uno with me . Want to know how different the code is from the one for arduino nano? Can we use the same code or do we have to make any changes?

  45. michael says:

    i am new in audino, and when i upload the code to ATMEGA168 board, it keeps showing the wrong signal:
    AeroQuad:203: error: ‘Motors_PWMtimer’ does not name a type
    AeroQuad:216: error: ‘BatteryMonitor_AeroQuad’ does not name a type
    AeroQuad.cpp: In function ‘void setup()':
    AeroQuad:506: error: ‘motors’ was not declared in this scope
    AeroQuad:545: error: ‘batteryMonitor’ was not declared in this scope
    AeroQuad.cpp: In function ‘void loop()':
    AeroQuad:775: error: ‘batteryMonitor’ was not declared in this scope
    AeroQuad.cpp: In function ‘void readPilotCommands()':
    FlightCommand:33: error: ‘motors’ was not declared in this scope
    FlightCommand:47: error: ‘motors’ was not declared in this scope
    FlightCommand:64: error: ‘motors’ was not declared in this scope
    AeroQuad.cpp: In function ‘void calculateFlightError()':
    FlightControl:29: error: ‘motors’ was not declared in this scope
    FlightControl:36: error: ‘motors’ was not declared in this scope
    AeroQuad.cpp: In function ‘void processCalibrateESC()':
    FlightControl:49: error: ‘motors’ was not declared in this scope
    FlightControl:53: error: ‘motors’ was not declared in this scope
    FlightControl:57: error: ‘motors’ was not declared in this scope
    FlightControl:62: error: ‘motors’ was not declared in this scope
    FlightControl:65: error: ‘motors’ was not declared in this scope
    AeroQuad.cpp: In function ‘void processHeading()':
    FlightControl:130: error: ‘motors’ was not declared in this scope
    AeroQuad.cpp: In function ‘void processMinMaxMotorCommand()':
    FlightControl:181: error: ‘motors’ was not declared in this scope
    FlightControl:198: error: ‘motors’ was not declared in this scope
    AeroQuad.cpp: In function ‘void processHardManuevers()':
    FlightControl:223: error: ‘motors’ was not declared in this scope
    FlightControl:229: error: ‘motors’ was not declared in this scope
    FlightControl:235: error: ‘motors’ was not declared in this scope
    FlightControl:241: error: ‘motors’ was not declared in this scope
    AeroQuad.cpp: In function ‘void processFlightControlXMode()':
    FlightControl:284: error: ‘motors’ was not declared in this scope
    FlightControl:300: error: ‘motors’ was not declared in this scope
    FlightControl:306: error: ‘motors’ was not declared in this scope
    FlightControl:317: error: ‘motors’ was not declared in this scope
    AeroQuad.cpp: In function ‘void readSerialCommand()':
    SerialCom:151: error: ‘motors’ was not declared in this scope
    AeroQuad.cpp: In function ‘void sendSerialTelemetry()':
    SerialCom:350: error: ‘batteryMonitor’ was not declared in this scope
    SerialCom:355: error: ‘motors’ was not declared in this scope
    SerialCom:380: error: ‘motors’ was not declared in this scope
    SerialCom:406: error: ‘motors’ was not declared in this scope

    can u please help me,thanks

  46. Max says:

    I am unsure how to wire the esc to the board, could I get some closer shots on how exactly the easc is wired to the receiver and nano?

  47. rob1 says:

    hello I am a french teenager and I don’t understand how to install the software and the firmware on my arduino board..could you explain to me how I can do, because I would like to make a french “tutoriel” but if I can’t install the firmware..

    sorry for the english mistake ,
    on the waiting of an ansxer
    bye !!

  48. Sathya says:

    Hey could u please send me the circuit diagram of how to connect the auto-stabilizing system to the motors and RC receiver…Plzzz help me….

  49. Abhishek says:

    Hello,
    I want to make a quadcopter using brushed motor and arduino. Please mind high rpm brushed motor not brushless. Can you guide me whether it is feasible or not. If yes then what stuffs are required.

  50. Usman Samie says:

    Hi,
    first of all awesome guide!!! kudos on that… i am using GY-80 instead of sparkfun 6DOF IMU but after i upload the flight control code to the nano and hook up the IMU the serial monitor says “Gyro not found” and the 3D quad in the configurator doesnt move at all. please could you help me out

    • Alhaidar says:

      Hi
      That’s right because your IMU has another giro chip (L3G4200D) which is different form what sparkfun has (ITG-3200) , so what you need now, is to change the gyro address in the code and also some calibration parameters in order to make it work with your IMU .
      I hope my explanation will help you.
      Regards

  51. Ajinkya says:

    Hi,

    I am really interested in making this one. But my question is that, Can i use 6DOF IMU from another manufacturer…??? Is it necessary to use Sparkfun’s IMU only…??? If yes, can you please explain me reasons..??? I am thinking of using this one: http://www.ebay.in/itm/6DOF-MPU-6050-Module-3-Axis-Gyroscope-Accelerometer-Module-for-Arduino-MPU-6050-/261441716471?pt=LH_DefaultDomain_203&hash=item3cdf2400f7&_uhb=1

    Thanks in advance

    • Alhaidar says:

      Hi
      You can use any IMU but you need to change the i2c addresses and some other parameters for sensor calibrations according to the new sensor chip on your IMU .
      My suggestion to use sparkfun or any other IMU with the same giro and accelerometer chips that sparkfun use, in order to keep the code as it is.
      Regards

  52. Gyula says:

    Nice post, though by the number of posts it lacks in
    detailed information. Why don’t you please revive
    the post and write everything eligible and detailed,
    so any beginner can follow.

    Just a thought.

  53. Andrew.W says:

    If you have difficulties with this post visit multiiwii site because this post is close to the multiwii, and multiwii has real true professional diagrams, software, tutorials, as a good engineer would do.

    http://www.rcgroups.com/forums/showthread.php?t=1340771#post16588187

  54. Charles Barnes says:

    I am not able to push the code,I get a lot of errors about incorrect semicolons and how something isn’t a byte. help will be appreciated

  55. Tyrone says:

    Hello Russell. Once you have this set up constructed with the arduino nano and the software installed on it is it ready for flight? Or can you program it with the software in the above video that we downloaded to check orientation? Also can this then be used with the the aeroquad mission planner software that is shown in the scout build tutorial? Let me know. Thanks!

  56. Tyrone says:

    Charles I had the same issue until I went on to the archives of the arduino website and actually downloaded the arduino 0023 version. It’s an old version and it compiles perfectly on arguing 0023. The new versions will trigger several errors. Hope this helps. Try that.

  57. MRH says:

    Hi
    can i use MPU6050 GY-521 IMU for this board?is it good?

  58. mahdi says:

    I can not find the source code.where is it? thanks for your help.

  59. typesof says:

    It’s awesome in favor of me to have a web site, which is good in support of my experience.
    thanks admin

  60. newbie91 says:

    Is the code given compatible with a arduino micro? Or is there a need to configure the coding?

  61. Newbie_aj says:

    whats the size of the frame you have and where can I buy it?

  62. Dishant Parikh says:

    It works great. I used nano and as it uses atmega 318 I got it perfectly .
    thanks for the advice.

    and newbie91 I can solve your problem.
    If you are using an adruino micro then you have to specifically mention in the code.
    you won’t need anything else just a perfect code on it .
    otherwise its perfect.

  63. Newbie_aj says:

    how much weight this set up can carry? i wanna build one using bigger servos and frame.

Leave a Reply