Arduino : How to Control Servo Motor With Arduino

40,857

123

6

About: Arduino, Raspberry Pi, esp8266, Tutorials, Projects

Intro: Arduino : How to Control Servo Motor With Arduino

This instructable is the written version of my "Arduino : How To Control Servo Motor with Arduino" YouTube video that I've uploaded recently. I strongly recommend you to check it out.

Visit YouTube Channel

Step 1: Tutorial

Servo motors are great devices that can turn to a specified position.

Usually, they have a servo arm that can turn 180 degrees. Using the Arduino, we can tell a servo to go to a specified position and it will go there. As simple as that!

Servo motors were first used in the Remote Control (RC) world, usually to control the steering of RC cars or the flaps on a RC plane. With time, they found their uses in robotics, automation, and of course, the Arduino world.

Here we will see how to connect a servo motor and then how to turn it to different positions.

Step 2: Hardware Required

Hardware Required :

  • Arduino
  • Servo Motor
  • Jumper Cables
  • Battery & Buckle

Step 3: Connections

Following are the steps to connect a servo motor to the Arduino:

  1. The servo motor has a female connector with three pins. The darkest or even black one is usually the ground.
  2. Connect this to the Arduino GND. Connect the power cable that in all standards should be red to 5V on the Arduino.
  3. Connect the remaining line on the servo connector to a digital pin on the Arduino.

*** I recommend! You not connect directly the servo motor to arduino. I suggest you use external power to the servo.

SG90 Mini RC servo motors can be used. This can damage the Arduino MG996 instant high torque. MG996 Stall Torque: 9.4kg / cm (4.8V) - 11 kg / cm (6.0V) and Operating voltage: 4.8 ~ 6.6v. I wanted to tell in this tutorial; connections, code generation and motor control. So I did not give more details about the engine.

Step 4: Programming

1) Make sure you include Servo.h library

2) Define Servo name

3) Define Servo signal input pin (PWM)


Get Code :

Step 5: If I Was Helpful

First of all, I would like to thank you for reading this guide ! I hope it helps you.

If you want to support me, you can subscribe my channel and watch my videos.

Visit My YouTube Channel

Share

    Recommendations

    • Optics Contest

      Optics Contest
    • Plastics Contest

      Plastics Contest
    • Electronics Tips & Tricks Challenge

      Electronics Tips & Tricks Challenge

    6 Discussions

    0
    None
    MohammadT43

    5 months ago

    hi.thanks for this amazing tutorial.i was wondering what program do u use to make the picture in step4???

    0
    None
    SoorajV4

    Question 7 months ago on Step 3

    let me know, can i connect 9v duracell battery to mg996r

    0
    None
    FelicianoTech

    1 year ago

    Hi, I'm currently working on a project which requires me to control two servos via a push button. My goal is to create a circuit and program where the two servos move a set degrees after the buttons for each servo are pushed once, and when pushed a second time, rotate back to their original position. I'm very new to Arduino and was wondering if you could help me in my effort to complete this project thank you for your time and have a great day.

    0
    None
    robertbu

    2 years ago

    For testing this servo (MG996R) or for developing code with no load on the servo, this setup will work fine. But under load there is a danger of overloading the voltage regulator on the Arduino. When stalled, the MG996R can draw up to 2.5A. For many Arduino boards, there is a limit of around 800mA drawn from the regulator. If there is any chance of the servo stalling or even being under high-torque, provide an separate power source for the servo.

    2 replies
    0
    None
    MertArduinorobertbu

    Reply 2 years ago

    Absolutely right. Maybe SG90 Mini RC servo motor can be used. But MG996 can damage the Arduino instant high torque.

    MG996 Stall Torque: 9.4kg / cm (4.8V) - 11 kg / cm (6.0V) and Operating voltage: 4.8 ~ 6.6v.

    I wanted to tell in this tutorial; connections, code generation and motor control. So I did not give more details about the engine.

    0
    None
    robertbuMertArduino

    Reply 2 years ago

    As you say a SG90 should be safe...as long as there is only one and not a lot of other things drawing current. The highest stall current I've seen for the SG90 (at 5v) is 0.75A, and most specs are closer to 0.6A.