Jump to main content

How to Control a DIY Mini Drone with an Arduino™

1
2
3
4
5
45 reviews

Abstract

Most drones fly with a mix of human input and autonomous control based on feedback from electronic sensors. This allows the drone to fly up and down when the human operator presses a joystick on a controller, but automatically hover at a fixed distance above the ground when the operator lets go of the joystick. In this project, you will explore drone programming with an Arduino. What types of inputs and sensors can you make your drone respond to? What behaviors and responses can you program your drone to perform? Try it and find out!

Summary

Areas of Science
Difficulty
 
Time Required
Short (2-5 days)
Prerequisites
Previous experience with programming and working with circuits will be helpful for this project.
Material Availability
DIY Mini Drone Kit and Science Buddies Electronics Kit for Arduino available from our partner Home Science Tools. See the Materials section for details.
Cost
Average ($40 - $80)
Safety
No issues
Credits
Ben Finio, PhD, Science Buddies
Excel® is a registered trademark of Microsoft Corporation.

Objective

Program an Arduino to control the altitude of a simple homemade drone.

Introduction

Unmanned aerial vehicles (UAVs), commonly called drones, are aircraft that fly without a human pilot on board. Some drones are very large—as big as a small airplane. Other drones are much smaller, and are popular as toys, for recreational use, and for aerial photography. Quadcopters, which have four propellers, are a popular type of consumer drone (Figure 1).

 A quadcopter flying in the air. Image Credit: Wikimedia user Josh Sorenson / Public domain
Figure 1. A DJI Phantom, a popular type of consumer drone.

Most drones fly with some level of human control. For example, many consumer drones can be flown with either a controller that has two joysticks, similar to a video game controller (Figure 2), or via an app on a smartphone. The joysticks allow the operator to make the drone fly up and down, side to side, and make it turn.

 A handheld drone controller with two joysticks.  Image Credit: Ben Finio, Science Buddies / Science Buddies
Figure 2. A handheld drone controller.

However, keeping the drone level and preventing it from crashing can be difficult for the human operator. To accomplish this, the drone also has some autonomous control using an on-board computer and electronic sensors. These sensors measure physical information about the drone, like its angle of tilt or distance from the ground. Sometimes these sensors are inside the drone, and sometimes they may be visible on the drone's exterior, like a camera (Figure 3) or downward-facing sensors that measure reflected light or ultrasonic sound in order to measure the distance to the ground.

 A camera mounted on the bottom of a drone Image Credit: Ben Finio, Science Buddies / Science Buddies
Figure 3. A camera mounted on the bottom of a drone.

In order to keep the drone level or at a fixed distance above the ground, the onboard computer uses feedback control, also called closed-loop control. Feedback control takes measurements from the sensors (the "feedback") and uses it to adjust the speed of the drone's motors. For example, if the drone is too close to the ground, the controller can automatically speed up the motors to make the drone fly upward. If a gust of wind makes the drone tilt to one side, it can speed up the motors on one side of the drone to make it tilt back in the correct direction (Figure 4).

 One drone with motors on both sides exerting equal upward forces, so the drone flies level. Another drone with motors on one side exerting a bigger force than the other side, causing the drone to tilt.   Image Credit: Ben Finio, Science Buddies / Science Buddies
Figure 4. An example diagram showing how a drone can increase the speed of motors on one side and decrease the speed of motors on the other side in order to tilt in one direction.

There are many other examples of feedback control in your everyday life. The thermostat in a house is a common one. The thermostat contains a temperature sensor that measures the temperature of the air. When the temperature gets too cold in the winter, the thermostat will automatically turn the heat on until the house warms up. It will then turn the heat off until the house gets too cold again, and repeat. This is an example of simple on/off control.

Other types of control, like cruise control in a car, are more complicated. On/off control would not be good in a car; that would be like alternating between slamming on the gas and slamming on the brakes! Instead, the cruise control makes more gentle adjustments, as needed, to maintain the desired speed.

In this project, you can experiment with programming your drone to respond to different human inputs and electronic sensors. To simplify construction and programming of the drone, the drone will be constrained to move vertically on two guide poles. This way, you can focus on just controlling the drone's altitude, without worrying about tilt or side-to-side motion. Can you design an intuitive handheld controller for your drone? What about making the drone automatically respond to disturbances or follow a pre-programmed path? The sky is the limit!

Terms and Concepts

Questions

Bibliography

Materials and Equipment Buy Kit

Recommended Project Supplies

Get the right supplies — selected and tested to work with this project. Arduino not included.

View Kit

Disclaimer: Science Buddies participates in affiliate programs with Home Science Tools, Amazon.com, Carolina Biological, and Jameco Electronics. Proceeds from the affiliate programs help support Science Buddies, a 501(c)(3) public charity, and keep our resources free for everyone. Our top priority is student learning. If you have any comments (positive or negative) related to purchases you've made for science projects from recommendations on our site, please let us know. Write to us at scibuddy@sciencebuddies.org.

Experimental Procedure

Note: If you have never used an Arduino before, please see our How to Use an Arduino page and go through at least the first three tutorials before you attempt the procedure for this project.
Note: if you purchased the Mini Drone Kit from Home Science Tools, some of these steps (like stripping the wires and drilling holes in a wood base) are already done for you.

Build Your Drone

  1. Watch the following video and read the directions in the Build a Simple Drone and Test How Much It Can Lift project to build your drone. You should use two guide poles for your drone instead of one (as shown in the video). This will prevent the wires from getting twisted around the pole.

Connect the Arduino

  1. Orient the breadboard so it is facing you with the writing upright. Then connect all of the following, as shown in Figure 5 (click for a bigger version of the diagram). If you know how to read a circuit schematic, you can use that instead (Figure 6).
    1. Arduino 5V pin to breadboard positive bus.
    2. Arduino GND pin to breadboard ground bus.
    3. Breadboard left positive bus to breadboard right positive bus.
    4. Breadboard left ground bus to breadboard right ground bus.
    5. Ultrasonic sensor GND pin to breadboard ground bus (use male-female jumper wires to connect to the sensor pins).
    6. Ultrasonic sensor 5V pin to breadboard positive bus.
    7. Ultrasonic sensor Echo pin to Arduino digital pin 7.
    8. Ultrasonic sensor Trig pin to Arduino digital pin 8.
    9. MOSFET in holes F8, F9, and F10, with the large metal tab facing to the left.
    10. Hole J8 to ground bus.
    11. Hole G10 to Arduino digital pin 10.
    12. Potentiometer in holes F16, F17, F18.
    13. Hole J16 to positive bus.
    14. Hole J17 to Arduino analog input A0.
    15. Hole J18 to ground bus.
    16. Push button straddling the middle gap of the breadboard, with pins in holes E23, E25, F23, and F25.
    17. Hole A23 to Arduino digital pin 3.
    18. 10 kΩ resistor from hole J23 to positive bus.
    19. Hole J25 to ground bus.
    20. Drone positive wire to J1. The drone's wires are too flexible to push into the breadboard on their own. Twist or crimp them to a short piece of jumper wire to make the connection.
    21. Drone negative wire to J9.
    22. 4xAA battery pack negative (black) wire to ground bus.
    23. 4xAA battery pack positive (red) wire to F1. Important: Do not connect the battery pack's positive wire to the breadboard's positive bus! This will create a short circuit between the Arduino's 5 V power and the battery pack's 6 V power.

    Breadboard diagram for Arduino drone altitude control circuitImage Credit: Ben Finio, Science Buddies / Science Buddies
    Figure 5. Breadboard diagram for Arduino drone control circuit.

    Circuit schematic for Arduino drone altitude control circuitImage Credit: Ben Finio, Science Buddies / Science Buddies
    Figure 6. Circuit schematic for Arduino drone control circuit.
  2. Upload the code to your Arduino.
    1. Download drone_altitude_control_code.ino to your computer.
    2. Temporarily disconnect one of the drone's wires from the breadboard. This will prevent the drone from accidentally taking off when you power up your Arduino (this can happen depending on the last program that ran on the Arduino).
    3. Connect the Arduino to your computer with the USB cable.
    4. Open drone_altitude_control_code.ino in the Arduino IDE.
    5. Press the "Upload" button to send the code to your Arduino.
  3. Test your drone.
    1. Make sure the drone is threaded onto the guide poles.
    2. Place the ultrasonic sensor directly under the drone, facing up (Figure 7).
    3. Re-connect the drone's wire to the breadboard.
    4. Press the push button once to make the drone lift off.
    5. Adjust the potentiometer to change the drone's height.
    6. Gently tap the drone up or down with your finger or a pencil (watch out for the propellers!). What happens?
    7. Press the push button again to make the drone land. You can re-press the button to make it lift off again.
    Mini drone hovering on guide poles next to Arduino and control circuitImage Credit: Ben Finio, Science Buddies / Science Buddies
    Figure 7. Experimental setup, with the drone on guide poles and ultrasonic sensor placed under the drone facing upward.

Using Your Drone for a Science or Engineering Project

To use your drone for a science or engineering fair project, it is not sufficient to simply present what you have built so far based on the Science Buddies instructions and example code. You will need to conduct your own experiment (for a science project) or design/program something new (for an engineering project). Before you begin either type of project, you should carefully read through the comments in the example code and make sure you understand how it works. Here are a few suggestions for a project:

  • How does the drone respond to disturbances of different amounts? For example, try holding the drone at fixed distances from the target height (1 cm, 2 cm, 3 cm...) and then releasing it.
  • The example code uses a proportional controller. It increases (or decreases) the motor speed by an amount proportional to the difference between the target height and actual height. What happens if you change the code to use basic on/off control instead (i.e. either turning the motors on full speed or turning them completely off, nothing in between)? How does the drone's behavior compare to the proportional controller?
  • What is the effect of changing the gain (the variable K in the code) of the proportional controller?
  • Can you program a proportional-integral-derivative (PID) controller instead of a basic proportional controller?
  • Can you program the drone to follow a pre-programmed path? For example, continuously flying up and down in an oscillating (sinusoidal) pattern? What about quickly flying to different fixed heights and hovering for a few seconds before moving to the next height? How can you get the drone to closely follow the path with minimal error?
  • Can you design and build a handheld controller for your drone? What if you use an analog joystick, just like the type found in video game controllers and many commercial drone controllers, instead of a potentiometer?

In any of the above projects, there are several ways you can collect data about your drone's movement. The easiest way is to copy data from the Arduino serial monitor into a spreadsheet program so you can graph the data*. This will allow you to plot the drone's position vs. time as you change variables or use different control methods. However, you can also film your drone and analyze its motion using a program like Tracker. You could even compare the two different methods and turn that into a project of its own!

* Copying data from the Arduino serial monitor can be a bit tricky due to an apparent bug. If you press CTRL+A then CTRL+C to select and copy all the data in the serial monitor window, it does not work. Instead, when you are done collecting data, unplug the USB cable to disconnect the Arduino from the computer and stop printing to the serial monitor. Then, select all of the data in the serial monitor except for the first line. Do this by clicking at the beginning of the second line, scrolling all the way to the bottom, holding SHIFT, then clicking at the end of the last line. Then press CTRL+C to copy the data, and you can paste it into another program like Notepad or Excel®. You may need to use the Text to Columns feature in Excel, or the equivalent in another spreadsheet program, to get the data into separate columns.

Troubleshooting

For troubleshooting tips, please read our FAQ: How to Control a DIY Mini Drone with an Arduino™.

icon scientific method

Ask an Expert

Do you have specific questions about your science project? Our team of volunteer scientists can help. Our Experts won't do the work for you, but they will make suggestions, offer guidance, and help you troubleshoot.

Global Connections

The United Nations Sustainable Development Goals (UNSDGs) are a blueprint to achieve a better and more sustainable future for all.

This project explores topics key to Industry, Innovation and Infrastructure: Build resilient infrastructure, promote sustainable industrialization and foster innovation.

Variations

  • Instead of controlling up-and-down motion of your drone, can you build something that lets you control side-to-side tilt? For example, try mounting the drone on a vertical spring, or threading a dowel through a straw that is glued to the drone's frame horizontally. See this page for a list of other projects you can do with your drone.

Frequently Asked Questions (FAQ)

If you are having trouble with this project, please read the FAQ below. You may find the answer to your question.
Q: None of my propellers spin. What is wrong?
A:
  • Make sure your batteries are firmly inserted into the battery pack and facing the proper direction.
  • Make sure the battery pack is on.
  • Double-check all of your twisted wire connections. Loose connections can prevent the motors from spinning.
Q: At least one motor is spinning, but some motors are not spinning. Why not?
A: If at least one motor is spinning, then you know your batteries are inserted properly and the battery pack is working. Double-check the twisted wire connections to each individual motor and tighten them as needed.
Q: One of my propellers is spinning the wrong way. How do I fix it?
A: To reverse the direction a propeller spins, reverse the connections for the motor's two wires. This will make current flow through the motor in the opposite direction, causing it to spin the other way.
Q: The propellers all spin but my drone does not lift off. What can I do?
A: If your drone does not lift off, there are several things you need to check:
  • Make sure that you can easily slide the drone up and down the dowels by hand. If you let go of the drone after lifting it, it should fall back to the bottom. If the drone gets stuck:
    • Make sure the wooden dowels are parallel and the spacing between them is even. If the dowels are crooked, this will cause the drone to get stuck.
    • Make sure the two straws that act as guide for the drone are parallel and aligned with the dowels. If the straws are crooked, this can cause the drone to get stuck even if the dowels are parallel.
  • Make sure that all four propellers are properly mounted and spinning in the right direction. If you turn the drone on and hold your hand under each propeller, you should feel air blowing down on your hand. If you hold your hand over a propeller and you feel air blowing up, then you either a) have the wires for that motor reversed or b) mixed up the clockwise and counter-clockwise propellers. Revisit the procedure to make sure you have all four motors wired correctly with the correct propeller mounted on each motor.
  • Do not use excessive amounts of glue or tape when building your drone. If the drone is too heavy, it will not lift off, even if everything else is built correctly.
  • Make sure the wires from the battery pack are free and not getting snagged on anything.
  • Make sure the motors are all pointed straight up. This will give your drone maximum lift. If the motors are tilted at an angle, the drone will not have as much lift.
Q: My drone was working for a while, and now it stopped. What happened?
A:
  • Just like any other battery-operated device, your drone's batteries will wear out eventually. If your drone seems sluggish or is no longer lifting off, replace the batteries.
  • Check if the drone has become damaged from repeated use or if your wooden dowels have become misaligned.

Careers

If you like this project, you might enjoy exploring these related careers:

Career Profile
Have you watched "The Transformers" cartoon series or seen the "Transformers" movies? Both shows are about how good and evil robots fight each other and the humans who get in the middle. Many TV shows and movies show robots and humans interacting with each other. While this is, at present, fantasy, in real life robots play a helpful role. Robots do jobs that can be dangerous for humans. For example, some robots defuse landmines in war-stricken countries; others work in harsh environments like… Read more
Career Profile
Humans have always longed to fly and to make other things fly, both through the air and into outer space—aerospace engineers are the people that make those dreams come true. They design, build, and test vehicles like airplanes, helicopters, balloons, rockets, missiles, satellites, and spacecraft. Read more
Career Profile
Mechanical engineers are part of your everyday life, designing the spoon you used to eat your breakfast, your breakfast's packaging, the flip-top cap on your toothpaste tube, the zipper on your jacket, the car, bike, or bus you took to school, the chair you sat in, the door handle you grasped and the hinges it opened on, and the ballpoint pen you used to take your test. Virtually every object that you see around you has passed through the hands of a mechanical engineer. Consequently, their… Read more
Career Profile
Just as a potter forms clay, or a steel worker molds molten steel, electrical and electronics engineers gather and shape electricity and use it to make products that transmit power or transmit information. Electrical and electronics engineers may specialize in one of the millions of products that make or use electricity, like cell phones, electric motors, microwaves, medical instruments, airline navigation system, or handheld games. Read more

Contact Us

If you have purchased a kit for this project from Science Buddies, we are pleased to answer any question not addressed by the FAQ above.

In your email, please follow these instructions:
  1. What is your Science Buddies kit order number?
  2. Please describe how you need help as thoroughly as possible:

    Examples

    Good Question I'm trying to do Experimental Procedure step #5, "Scrape the insulation from the wire. . ." How do I know when I've scraped enough?
    Good Question I'm at Experimental Procedure step #7, "Move the magnet back and forth . . ." and the LED is not lighting up.
    Bad Question I don't understand the instructions. Help!
    Good Question I am purchasing my materials. Can I substitute a 1N34 diode for the 1N25 diode called for in the material list?
    Bad Question Can I use a different part?

Contact Us

News Feed on This Topic

 
, ,

Cite This Page

General citation information is provided here. Be sure to check the formatting, including capitalization, for the method you are using and update your citation, as needed.

MLA Style

Finio, Ben. "How to Control a DIY Mini Drone with an Arduino™." Science Buddies, 6 Dec. 2023, https://www.sciencebuddies.org/science-fair-projects/project-ideas/Robotics_p038/robotics/drone-programming-arduino. Accessed 3 May 2024.

APA Style

Finio, B. (2023, December 6). How to Control a DIY Mini Drone with an Arduino™. Retrieved from https://www.sciencebuddies.org/science-fair-projects/project-ideas/Robotics_p038/robotics/drone-programming-arduino


Last edit date: 2023-12-06
Top
We use cookies and those of third party providers to deliver the best possible web experience and to compile statistics.
By continuing and using the site, including the landing page, you agree to our Privacy Policy and Terms of Use.
OK, got it
Free science fair projects.