Jump to main content

PID Controller Tuning for a Drone

5 reviews


Areas of Science
Time Required
Short (2-5 days)
Ben Finio, PhD, Science Buddies
DIY Mini Drone Part 3: Arduino Altitude Control
*Note: For this science project you will need to develop your own experimental procedure. Use the information in the summary tab as a starting place. If you would like to discuss your ideas or need help troubleshooting, use the Ask An Expert forum. Our Experts won't do the work for you, but they will make suggestions and offer guidance if you come to them with specific questions.

If you want a Project Idea with full instructions, please pick one without an asterisk (*) at the end of the title.


Note: to do this project you will need the DIY Mini Drone Kit. An Arduino must be purchased separately. The Elegoo UNO Super Starter Kit contains the additional parts you will need, including an ultrasonic sensor.

The program in the DIY Mini Drone: Arduino™ Altitude Control project uses a proportional controller to control the drone's altitude. A potentiometer is connected to one of the Arduino's analog inputs. The potentiometer sends an adjustable voltage to the Arduino, and the code converts this voltage to a target height. An ultrasonic distance sensor measures the actual height, and the code subtracts this from the target height to compute an error. It then increases or decreases the motors' speed by an amount that is proportional to this error, in order to move the drone back toward the target height and decrease the error. The factor multiplied by the error is called the controller's "gain." In this case, the control signal is a pulse-width modulation (PWM) signal sent to the motors using the Arduino analogWrite() function. Since the PWM signal must be a non-zero value to make the drone hover at a fixed height, the control signal also includes a bias term, and is calculated using this equation:

Equation 1:

While proportional controllers are very simple, they have one major limitation. They are subject to a steady-state offset error, meaning the drone will never actually reach the exact target height. While you can decrease the offset error by increasing the controller's gain, this can have undesired side effects like rapid, jerky motion of the drone, and you can never eliminate the error entirely with a purely proportional controller.

You can solve this problem by using a proportional-integral (PI) or proportional-integral-derivative (PID) controller. As the names imply, these controllers also change the motor speed by amounts that are proportional to the integral and/or derivative of the error. A PID controller has three gains: KP, KI, and KD. The control signal is calculated with the equation (note that technically a PI controller is just a PID controller where KD=0):

Equation 2:

The process of selecting the gain values for Equation 2 is called "tuning" the controller. A properly tuned controller will give the drone a response that is "just right," meaning that it will quickly return to the target height (this is called the "rise time"), without too much overshoot, oscillation (the "settling time"), or steady-state error. A poorly tuned controller can result in undesired or erratic drone behavior, like moving very slowly toward the target height, or rapidly shooting past it, then over-correcting and shooting past it again, etc.

Can you design a PID controller for your drone that results in optimal behavior? You may need to do some of your own research about PID controllers to get started. The Bibliography contains several references that may be useful. Refer to DIY Mini Drone: Arduino™ Altitude Control for instructions to build your drone. The circuit diagram is reproduced in Figures 1 and 2, and you can download working code for a proportional controller here. Note that the circuit diagram and code are for the PING ultrasonic distance sensor. If you have an HC-SR04 ultrasonic sensor instead, you should follow the instructions in our HC-SR04 ultrasonic distance sensor tutorial to modify your circuit and code. (Click these links for a bigger version of the diagram and the circuit schematic.)

Breadboard diagram for Arduino drone altitude control circuit
Figure 1. Breadboard diagram for Arduino drone controller.

Circuit schematic for Arduino drone altitude control circuit
Figure 2. Circuit schematic for Arduino drone controller.


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.

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


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:


    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. "PID Controller Tuning for a Drone." Science Buddies, 25 Mar. 2023, https://www.sciencebuddies.org/science-fair-projects/project-ideas/Robotics_p036/robotics/drone-pid-controller. Accessed 28 May 2023.

APA Style

Finio, B. (2023, March 25). PID Controller Tuning for a Drone. Retrieved from https://www.sciencebuddies.org/science-fair-projects/project-ideas/Robotics_p036/robotics/drone-pid-controller

Last edit date: 2023-03-25
Free science fair projects.