Jump to main content

DIY Mini Drone: Motion Control

Summary

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

Introduction

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.

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

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 Program Drone Steering with an Arduino® project to build your drone and the Arduino circuit.
  2. The accelerometer breakout board does not come with header pins attached, so you will need to solder them on yourself. Refer to the Science Buddies soldering tutorial if you do not know how to solder.

  3. Solder short pieces of solid-core jumper wire to the ends of five 1 m pieces of stranded wire. Wrap the exposed solder connections in electrical tape or, if available, use heat shrink tubing.

  4. Plug one end of each wire into the header pins on the accelerometer. You will plug the other ends into your Arduino in the next section.

Instructions

Note: if at any point you have trouble getting your drone to work, see the drone project FAQ.
  1. Modify your circuit as shown in the diagram below (click for a bigger version of the breadboard layout or circuit diagram).
    1. Remove the four pushbuttons and associated jumper wires.
    2. Connect the accelerometer breakout board to the Arduino as follows:
      1. VCC to Arduino 3V3.
      2. GND to Arduino GND.
      3. X to Arduino A0.
      4. Y to Arduino A1.
      5. Z to Arduino A2.

  2. Disconnect one of the battery pack's wires for now to prevent the drone's motors from spinning. Due to manufacturing variation, the voltages that different accelerometers produce in response to the same acceleration will not be exactly equal. You need to calibrate your accelerometer before you continue.
    1. Download motion_control.ino and upload it to your Arduino.
    2. Select Tools → Serial Monitor to open the Arduino's serial monitor. The serial monitor will print out values for a bunch of the variables in your code. For now, you only need to look at the voltages. They are listed in order: Vx, Vy, and Vz.
    3. Place the accelerometer perfectly flat on a level surface and record the values for Vx and Vy. Make sure the accelerometer is not moving when you record the values. It is okay if the values fluctuate slightly. Do your best to record an average value.
    4. Tilt the accelerometer 90 degrees so it stands vertically on any edge. Record the value for Vz.
    5. In the code, change the values of x_bias, y_bias, and z_bias to match the voltages you recorded. The datasheet for the ADXL335 says that these voltages should be between 1.35 and 1.65 V for the x and y axes, and between 1.2 and 1.8 V for the z axis.
    6. Save and re-upload your code.
    7. Rotate the accelerometer so it stands vertically on an edge parallel to the y axis. The pitch angle printed to the serial monitor should be approximately 90 degrees. If it is not, adjust the gain variable in the code, then re-upload and try again. According to the datasheet, the gain should have a value between 270 and 330 mV/g. Keep changing the gain until you get a value close to 90 degrees when the accelerometer is standing on its edge. Remember to re-upload your code each time you change the variable.
    8. When you have finished this process, your accelerometer is calibrated.
  3. Place the accelerometer flat on a level surface, then reconnect the battery pack to the breadboard. Your drone's motors should start spinning.
    Think about:
    What happens when you run the code and tilt the accelerometer side to side or front to back?
  4. Try changing the value of the variable a in small increments (for example, from 0.02 to 0.025 or 0.015). Re-upload your code.
    Think about:
    How does the drone's response to tilting the accelerometer change when you change the variable?

Cleanup

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

What Happened?

When you tilt the accelerometer, the Arduino calculates its angles of roll (side-to-side tilt) and pitch (front-to-back tilt). The code then adjusts the speeds of the motors to make the drone tilt in the same direction. This is the same concept used in the Program Drone Steering with an Arduino® and Drone Control with an Analog Joystick projects, but instead of using buttons or a joystick, your circuit uses the accelerometer as an input. Read the Digging Deeper section to learn more about how accelerometers work.

The variable a changes the drone's sensitivity to the accelerometer's tilt. Increasing the value of a will make the response more sensitive, meaning the drone will respond more quickly to smaller rotations of the accelerometer.

Digging Deeper

The accelerometer you used in this project is a three-axis accelerometer. This means it can detect acceleration in three perpendicular directions, labeled X, Y, and Z. If the accelerometer does not rotate at all (i.e. it stays level), then the accelerometer will detect motion in any of those three directions.

However, accelerometers have an interesting property: they also detect the direction of gravity. This means that if you hold an accelerometer still (do not move it side to side or up and down) and rotate it, it can tell which way is "up." For example, when the accelerometer board sits flat on a table, gravity points in the Z direction. If you tilt the accelerometer 90 degrees to one side, gravity will point in the X or Y direction depending on how you tilted it. If the accelerometer is partially tilted (e.g. 45 degrees), then there will be a component of gravity in more than one direction.

Your code uses this information to calculate the drone's roll and pitch angles. You can see the equations in the code, just below the comment "calculate roll and pitch in degrees." The equations are somewhat complicated and involve three-dimensional trigonometry, so do not worry if you do not understand them. You can read more about how accelerometers work and how they can detect gravity in this Accelerometer Technical Note. If you want to dive into the math behind how the roll and pitch angles are calculated, see the Additional Resources section.

icon scientific method

Ask an Expert

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

For Further Exploration

  • Try changing other variables in the code, like defaultSpeed or speedChange. What happens?

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

Project Guide

Project Resource
Accelerometer Technical Note - learn more about the physics behind how an accelerometer works Read more

Links

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.