Jump to main content

Drone Control with an Analog Joystick

Summary

Active Time
2-3 hours
Total Project Time
2-3 hours
Key Concepts
Circuits, programming, forces
Credits
Ben Finio, PhD, Science Buddies
Arduino is a registered trademark of Arduino LLC.

Introduction

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.

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
  • 2-axis analog joystick
  • 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

Before you do this project, you will need to do either the DIY Mini Drone: Arduino™ Altitude Control or Program Drone Steering with an Arduino® project. Once you have completed one of those projects, you can replace the control interface (either a potentiometer or push buttons, respectively) with your analog joystick, and upload new code to your Arduino to use the joystick for control.

Instructions

Note: if at any point you have trouble getting your drone to work, see the drone project FAQ.
Important: For both of the circuits below, remove any jumper wires connecting the breadboard's left and right power buses that you may have had in previous projects. We will use the left bus for +5V from the Arduino and the right bus for +6V from the battery pack. In previous projects we used both buses for +5V from the Arduino, and sent the +6V from the battery pack to a single row of the breadboard. It is important not to short-circuit the +5V and +6V supplies together.

Joystick for Altitude Control

If you did the DIY Mini Drone: Arduino™ Altitude Control project, follow these instructions to replace the potentiometer with the joystick for altitude control.
  1. Rebuild your circuit as shown in the diagram below (click for a bigger version of the breadboard layout or circuit diagram).
    1. Remove the potentiometer completely.
    2. You will need to move the button up on the breadboard to make room for the joystick.
    3. Connect the joystick's pins, as follows:
      1. L/R+ and U/D+ to 5V (breadboard positive bus)
      2. L/R to Arduino analog input A1
      3. U/D to Arduino analog input A0
      4. GND to breadboard ground bus
  2. Download drone_altitude_joystick.ino and upload it to your Arduino.
    Think about:
    What happens when you run the code and push the joystick up and down?
    Think about:
    Does anything happen if you push the joystick left to right?
  3. Try changing the scale variable in the code. This variable controls how quickly the analog voltage from the joystick changes the drone's target height. The smaller the number, the faster the drone will move.
    Think about:
    What happens when you change this number? Can you find a value that feels "just right" for controlling the drone with the joystick?

Joystick for Drone Steering

If you did the Program Drone Steering with an Arduino® project, follow these instructions to replace the buttons with the joystick for steering control.
  1. Rebuild your circuit as shown in the diagram below (click for a bigger version of the breadboard layout or circuit diagram).
    1. Remove all four push buttons from the breadboard.
    2. Connect the joystick's pins, as follows:
      1. L/R+ and U/D+ to 5V (breadboard left positive bus in the diagram below—the right bus is used for 6 V from the battery pack. Do not connect the two!).
      2. L/R to Arduino analog input A1.
      3. U/D to Arduino analog input A0.
      4. GND to breadboard ground bus.
  2. Download drone_steering_joystick.ino and upload it to your Arduino.
    Think about:
    What happens when you run the code and press the joystick up and down or side to side?
    Think about:
    Does anything happen if you move the joystick in a circle?
  3. There are several variables in the code that you can experiment with changing, but you need to be careful (explained in more detail in the next step). You will not break your drone, but you might see some strange or unexpected behavior depending on the values you enter for these variables.
    1. defaultSpeed sets the default speed for each motor when the joystick is in the neutral position.
    2. speedChange sets the maximum possible speed change for each motor.
    3. a is a multiplier that converts the analog joystick voltage to a speed change for each motor.
  4. Why do you need to be careful when changing these values? Because of something called overflow. The Arduino controls the motors' speed using a pulse-width modulation (PWM) signal via the analogWrite() function. For the Arduino UNO, analogWrite() only accepts values between 0 and 255. If you try to enter a value of 256, it will overflow and wrap back around to zero. Conversely, if you try to enter a value of -1, it will wrap back around to 255. This is why you need to be careful when changing the defaultSpeed, speedChange, and a variables. Depending on the values you enter, the code may calculate motor speed values (e.g. the variable motor1speed) that are outside the allowed 0–255 range. This will result in strange drone behavior, such as a motor spinning very slowly when you expect it to spin very fast, causing your drone to tilt in the wrong direction. You could get around this problem by adding IF statements to make sure the motor speeds stay within the allowed range, such as:

    if(motor1speed>255){motor1speed=255;}
    if(motor1speed<0){motor1speed=0;}

Cleanup

When you are done using your drone, disconnect the battery pack and unplug your Arduino.

What Happened?

If you did the altitude control project, then when the joystick is in its neutral position, the drone should automatically hover in place (thanks to the automatic feedback control from the Arduino and ultrasonic distance sensor). When you push the joystick up (or down), the drone will move up (or down) until you let go of the joystick. When you let go of the joystick, it will automatically hover in place at the new altitude. Pushing the joystick farther will make the drone move faster. Changing the scale variable will change how quickly the drone responds to the joystick input. If it responds too quickly, the joystick may feel too sensitive, and it will be hard to make small adjustments to the drone's height. Conversely, if it responds too slowly, then it may take a long time to move between positions, even when you push the joystick all the way up or down.

If you did the steering project, then when the joystick is in the neutral position, all four motors spin at the same speed, and the drone should fly level. When you tilt the joystick in any direction, it will proportionally increase the speed of some motors and decrease the speed of the opposite motors, causing the drone to tilt in the same direction you push the joystick. Changing some of the variables in the code can change the joystick's sensitivity, but as explained in the procedure, you may see strange behavior (the drone tilting in the wrong direction) if you change the variables too much.

Digging Deeper

In this activity, you used a single joystick to either control your drone's up-and-down motion or side-to-side tilt, while the drone was constrained (either by guide poles or springs) and could not move in other directions. Real drones are free-flying and free to move in three-dimensional space. A free-flying object has a total of six degrees of freedom, or ways that it can move. Three of these motions are translational (moving in a straight line): forward/backward, left/right, and up/down. Three are rotational (spinning): roll (tilting side to side), pitch (tilting forward and backward), and yaw (spinning left to right while remaining level).

Real drone controllers typically have two joysticks for you to use to control their motion. However, two joysticks only gives you four total directions to control, not six (up/down and left/right on the left joystick, and up/down and left/right on the right joystick). So how do you control a flying drone that has six degrees of freedom? Even though the drone has six degrees of freedom, they are not all independent. That means that some of them depend on each other. For example, when a drone rolls (tilts) to the right, it will also start moving to the right. This means that the drone's roll and left/right translation are coupled. The same applies to the drone's pitch and forward/backward motion. You cannot change one without changing the other. This means that you can steer the drone in 3D space with two joysticks instead of three.

icon scientific method

Ask an Expert

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

For Further Exploration

  • Can you build or 3D-print a handheld controller for your joystick instead of mounting it on a breadboard? You could also include some buttons, like the lift off/land button in the altitude control project.

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
28 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
38 reviews
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. 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
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
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
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

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
Pilots fly airplanes, helicopters, and other aircraft to accomplish a variety of tasks. While the primary job of most pilots is to fly people and cargo from place to place, 20 percent of all pilots have more specialized jobs, like dropping fire retardant, seeds, or pesticides from the air, or helping law enforcement rescue and transport accident victims, and capture criminals. Pilots enjoy working and helping people in the "third dimension." 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.