Jump to main content

DIY Mini Drone: Arduino™ Altitude Control

1
2
3
4
5
37 reviews

Summary

Active Time
2-3 hours
Total Project Time
2-3 hours
Key Concepts
Circuits, forces, programming, feedback control
Credits
Ben Finio, PhD, Science Buddies

Introduction

How do drones automatically hover at a constant distance from the ground? Find out in this fun drone project as you build an altitude control circuit for a popsicle stick drone using an ultrasonic distance sensor and an Arduino™.

See this page for a complete list of our mini drone projects. You may wish to do the projects in order.

This activity is not recommended for use as a science fair project. Good science fair projects have a stronger focus on controlling variables, taking accurate measurements, and analyzing data. To find a science fair project that is just right for you, browse our library of over 1,200 Science Fair Project Ideas or use the Topic Selection Wizard to get a personalized project recommendation.

Materials

  • DIY Mini Drone Kit
  • Science Buddies Electronics Kit for Arduino
  • Piece of paper or cardstock
  • Scissors
  • Windows or Mac computer. Unfortunately, Arduino software does not currently work well with Chromebooks. Your computer will need:
    • Access to the Arduino IDE, either installed local version or web-based editor. Watch this video for a comparison of the two options.
    • USB port. The Science Buddies kit comes with a USB-A to B cable. The "B" end plugs into the Arduino and the "A" end plugs into your computer. You will need an adapter or different cable if your computer only has USB-C ports. Watch this video to learn about the different types of cables and adapters.

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.

Prep Work

  1. Follow the instructions in the DIY Mini Drone activity to build your drone.
  2. If you do not know how to use a breadboard, refer to our Breadboard Tutorial before you continue.
  3. If you have never used an Arduino before, refer to our How to Use an Arduino guide.

Instructions

Note: if at any point you have trouble getting your drone to work, see the drone project FAQ.
  1. After following the instructions in the DIY Mini Drone activity, your drone should look like this.

  2. Glue a second vertical piece of straw to the middle of your drone's frame, opposite the first piece.

  3. Cut out a small circle of paper, about 7 cm in diameter. Poke holes in it for the straws, and slide it onto the underside of your drone. This will provide a larger, flat surface for the sound waves from the ultrasonic sensor to bounce off of.

  4. Build a support for your drone with two dowels spaced apart so they fit through both straws. It is important to make sure the dowels are parallel or your drone will get stuck. Make sure the drone slides smoothly up and down the dowels. Optional: place a piece of soft foam at the base of the dowels. This will provide some padding if your drone falls.
    1. Alternatively, you can use two strings. Tape the strings to a shelf or the edge of a table, and let them hang down. Thread the drone onto the strings, and then make sure the strings are pulled taut (for example, by taping heavy weights to the ends, or by having a helper hold them).
  5. Orient the breadboard so it is facing you with the writing upright. Then connect all of the following, as shown in the breadboard diagram (click for a bigger version of the diagram). If you know how to read a circuit schematic, you can use that instead. Note that the circuit diagram and code are for the HC-SR04 ultrasonic distance sensor. If you have PING ultrasonic sensor instead, you should follow the instructions in our PING ultrasonic distance sensor tutorial to modify your circuit and code.
    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. HC-SR04 sensor GND pin to breadboard ground bus (use male-female jumper wires to connect to the sensor pins).
    6. HC-SR04 sensor 5V pin to breadboard positive bus.
    7. HC-SR04 sensor Trig pin to Arduino digital pin 8.
    8. HC-SR04 sensor Echo pin to Arduino digital pin 7.
    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.
  6. Upload the code to your Arduino.
    1. Download drone_altitude_control_code.ino to your computer. If you have some computer programming experience, you can look through the code and read the comments to understand how it works.
    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.
  7. 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.
    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.
    Think about:
    What happens if you change the value of the variable K, re-upload your Arduino code, and test again?
  8. Troubleshooting:
    1. If your drone's motors do not spin at all, double-check all of your breadboard wiring. A single misplaced wire can prevent the entire circuit from working.
    2. To confirm that your drone is working, temporarily connect its two wires directly to the two wires from the 4xAA battery pack.
    3. Make sure all your wires are connected to the correct Arduino pins. The code does not "know" which pins you have plugged the wires into. You need to plug wires into the pins that are used in the code.
    4. If your drone flies but behaves erratically, try adjusting the ultrasonic sensor to make sure it is aimed at the bottom of the drone. Use the Arduino IDE's serial monitor to help debug (Tools→Serial monitor). This will display the measured distance in centimeters. If this value does not seem reasonable (for example, it is always zero, or it is 100 cm and you know your drone is definitely not that far away), then you are probably not getting good readings from the sensor.
    5. If your drone drifts up or down slightly instead of hovering, try changing the value of the PWM_offset variable in your code. This variable is a number between 0–255. By default, it is set to 150. If your drone drifts downward, try increasing the number. If your drone drifts upward, try decreasing the number.

Cleanup

When you are done, power off your Arduino by disconnecting the USB cable, and disconnect the 4xAA battery pack from the circuit.

What Happened?

When you run the Arduino code, the ultrasonic distance sensor sends out quick bursts of ultrasonic sound. It measures how long it takes these bursts to reflect back to the sensor, and uses this information to calculate the distance between the sensor and the drone (this is the same concept used by animals like bats for echolocation!). At the same time, the Arduino reads the voltage from the potentiometer, and converts this voltage to a desired height in centimeters. The code compares the drone's actual height to the desired height. If the actual height is too low, it increases the speed of the motors, making the drone fly up. If the actual height is too high, it decreases the speed of the motors, making the drone fly down. This allows the drone to automatically return to the desired height when you bump it up or down.

Changing the value of the variable K in the code changes the strength of the drone's reaction to disturbances. If the value is too low, the drone will move back toward the desired position very slowly. If the value is too high, the drone might move too fast and shoot past the desired position, then over-correct and fall past it again. Finding a value that is "just right" helps the drone quickly return to its desired position without bouncing around too much.

Digging Deeper

The code in this project uses feedback control, also called closed-loop control. Many systems that you encounter every day use feedback control. For example, the thermostat in your house automatically controls the heating or cooling to keep the inside of the house close to a set temperature.

Your circuit uses readings from the ultrasonic sensor to provide measurements, or feedback, about the drone's position to the Arduino. The Arduino subtracts this measured distance from the target distance to compute an error. It then increases or decreases the motors' speed by an amount that is proportional to the error, making the drone move up or down toward the target position, and reducing the error. This is called a proportional controller. The amount multiplied by the error is called the controller's gain, which is the variable K in the code. As you may have discovered, changing the value of K will affect how the drone responds to disturbances.

You can learn about how the parts of the circuit, like the push button, potentiometer, and ultrasonic sensor, interact with the Arduino by reading the comments in the code.

icon scientific method

Ask an Expert

Curious about the science? Post your question for our scientists.

For Further Exploration

  • Write code to make your drone follow a pre-programmed path, for example, automatically oscillating up and down between two different heights.
  • Add more buttons to your circuit and use them to make the drone automatically fly to different pre-programmed heights.
  • Change the value of the ramp_time variable in the code. What value gives the smoothest takeoffs and landings?
  • For advanced students:
    • Proportional controllers can be subject to a steady-state offset error. Can you determine this offset error between the target and measured distances? Does changing the controller gain K affect the error?
    • Can you modify the code to use a proportional-integral-derivative (PID) controller? Can you tune the controller's gains to get the best response from the drone? Meaning, can you make the drone return to the target height as quickly as possible after a disturbance, without overshooting the position or oscillating?
    • What is the bandwidth of the physical drone system? In other words, how quickly can you make the drone move up and down? If you program the Arduino to make the drone oscillate up and down 10 times per second by a height of 20 cm, is that physically possible?

Activities

STEM Activity
1
2
3
4
5
127 reviews
Quadcopters, also called drones, are a fun and popular toy. Explore the world of drones as you build your own mini drone using popsicle sticks in this fun activity. See this page for a complete list of our mini drone projects. You may wish to do the projects in order. Read more
STEM Activity
1
2
3
4
5
27 reviews
How do you make a drone fly up and down? In this activity, you will build a simple circuit to control the altitude of a popsicle stick drone. See this page for a complete list of our mini drone projects. You may wish to do the projects in order. Read more
STEM Activity
1
2
3
4
5
6 reviews
How do drones automatically balance themselves when you let go of the controls? Find out in this project as you build and program an experimental setup to make a drone automatically control its tilt angle about a single axis. See this page for a complete list of our mini drone projects. You may wish to do the projects in order. Read more
STEM Activity
1
2
3
4
5
6 reviews
Make your mini popsicle stick drone lift off in this activity! You will build a dual-joystick controller to steer your drone so you can fly it manually. How well can you fly without any help from automatic controls? See this page for a complete list of our mini drone projects. You may wish to do the projects in order. Read more
STEM Activity
1
2
3
4
5
8 reviews
How do you steer a drone using a controller with a joystick? Find out in this activity as you program an Arduino to interface with an analog joystick, similar to those found in most video game controllers. You can use the joystick to make a mini popsicle stick drone tilt side to side or move up and down. See this page for a complete list of our mini drone projects. You may wish to do the projects in order. Read more
STEM Activity
1
2
3
4
5
4 reviews
Most modern smartphones and video game controllers have a built-in accelerometer used for motion control. In this project you will program an Arduino® to use an accelerometer to control the steering of a miniature popsicle stick drone. See this page for a complete list of our mini drone projects. You may wish to do the projects in order. Read more
STEM Activity
1
2
3
4
5
8 reviews
How do quadcopters (drones with four propellers) steer? Find out in this fun project as you program an Arduino to steer a mini popsicle stick drone! See this page for a complete list of our mini drone projects. You may wish to do the projects in order. Read more

Careers

Career Profile
Are you interested in developing cool video game software for computers? Would you like to learn how to make software run faster and more reliably on different kinds of computers and operating systems? Do you like to apply your computer science skills to solve problems? If so, then you might be interested in the career of a computer software engineer. Read more
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
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
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.