How to Use a Servo Motor - Arduino Tutorial

Introduction: How to Use a Servo Motor - Arduino Tutorial

About: Arduino Tutorials by Codebender.cc Team

In this tutorial you will learn how to use a single servo motor with Arduino. Servos can move to a position accurately, so they are ideal for embedded electronics applications.

Servos have integrated gears and a shaft that can be precisely controlled. Standard servos allow the shaft to be positioned at various angles, usually between 0 and 180 degrees. Continuous rotation servos allow the rotation of the shaft to be set to various speeds.

In this tutorial we will use a 'Micro Servo 9g'. This one is very small, but larger servos are used extensively in robotics to control mechanical arms, hands, etc. You could use it to make a (tiny) robot arm, aircraft control surface, or anywhere something needs to be moved to specific positions.

So, let's get started!

Step 1: What You Will Need

For this tutorial you will need:

  • Arduino uno
  • Micro servo 9g

Step 2: The Circuit

Servo motors have three wires: power, ground, and signal. The power wire is typically red, and should be connected to the 5V pin on the Arduino board. The ground wire is typically black or brown and should be connected to a ground pin on the Arduino board. The signal pin is typically yellow, orange or white and should be connected to a digital pin on the Arduino board.

The connections are pretty easy, see the image above with the breadboard circuit schematic.

Note

Servos draw considerable power, so if you need to drive a biger servo, you'll probably need to power it from a separate supply (not from 5V pin of Arduino). Be sure to connect the grounds of the Arduino and external power supply together!

Step 3: The Code

Here's the code, embedded using codebender!

We will use Sweep Arduino example, just press "Run on Arduino" button to program your Arduino board.

You can make your own modifications to the code by clicking the "Edit" button. For example, you can change the delay time and see how it changes the program.

Step 4: Well Done!

You have successfully completed one more "How to" tutorial and you learned how to use a servo motor with Arduino.

I hope you liked this, let me know in the comments!
There will be more of them, so make sure to click Follow button :)

Share

    Recommendations

    • Creative Misuse Contest

      Creative Misuse Contest
    • Water Contest

      Water Contest
    • Metalworking Contest

      Metalworking Contest

    Discussions