Areas of Science Robotics
Aerodynamics & Hydrodynamics
Difficulty
Time Required Short (2-5 days)
Prerequisites Previous experience with programming and working with circuits will be helpful for this project.
Material Availability Circuit parts require. See Materials section for details.
Cost Average ($40 - $80)
Safety No issues

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!

Objective

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

Share your story with Science Buddies!

I did this project Yes, I Did This Project! Please log in (or create a free account) to let us know how things went.

Credits

Ben Finio, PhD, Science Buddies
Excel® is a registered trademark of Microsoft Corporation.

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, 1 Apr. 2021, https://www.sciencebuddies.org/science-fair-projects/project-ideas/Robotics_p038/robotics/drone-programming-arduino. Accessed 23 Apr. 2021.

APA Style

Finio, B. (2021, April 1). 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: 2021-04-01

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.
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.
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
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.
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

  • Unmanned aerial vehicles (UAVs)
  • Drone
  • Quadcopter
  • Sensor
  • Feedback control
  • Closed-loop control

Questions

  • What is a drone?
  • What are some uses for drones?
  • How do drones fly and steer? How are they controlled?
  • What types of electronic sensors could be useful for controlling a drone?

Bibliography

News Feed on This Topic

 
, ,

Materials and Equipment

The Build a Simple Drone and Test How Much It Can Lift project includes materials and instructions to build a basic drone with no Arduino control. In addition to the materials in that project, to add Arduino control you will need:

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

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. PING sensor GND pin to breadboard ground bus (use male-female jumper wires to connect to the PING sensor pins).
    6. PING sensor 5V pin to breadboard positive bus.
    7. PING sensor SIG pin to Arduino digital pin 7.
    8. MOSFET in holes F8, F9, and F10, with the large metal tab facing to the left.
    9. Hole J8 to ground bus.
    10. Hole G10 to Arduino digital pin 10.
    11. Potentiometer in holes F16, F17, F18.
    12. Hole J16 to positive bus.
    13. Hole J17 to Arduino analog input A0.
    14. Hole J18 to ground bus.
    15. Push button straddling the middle gap of the breadboard, with pins in holes E23, E25, F23, and F25.
    16. Hole A23 to Arduino digital pin 3.
    17. 10 kΩ resistor from hole J23 to positive bus.
    18. Hole J25 to ground bus.
    19. 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.
    20. Drone negative wire to J9.
    21. 4xAA battery pack negative (black) wire to ground bus.
    22. 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 circuit
    Figure 5. Breadboard diagram for Arduino drone control circuit.

    Circuit schematic for Arduino drone altitude control circuit
    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 circuit
    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.

.

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

Log in to add favorite
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
Log in to add favorite
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
Log in to add favorite
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
Log in to add favorite
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


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.

Share your story with Science Buddies!

I did this project Yes, I Did This Project! Please log in (or create a free account) to let us know how things went.

Ask an Expert

The Ask an Expert Forum is intended to be a place where students can go to find answers to science questions that they have been unable to find using other resources. If you have specific questions about your science fair project or science fair, 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.

Ask an Expert

Related Links

News Feed on This Topic

 
, ,

Looking for more science fun?

Try one of our science activities for quick, anytime science explorations. The perfect thing to liven up a rainy day, school vacation, or moment of boredom.

Find an Activity
Free science fair projects.