How to Control Servo Motor Arduino Tutorial

by DIY GUY Chris in Circuits > Arduino

1130 Views, 6 Favorites, 0 Comments

How to Control Servo Motor Arduino Tutorial

Diapositive8.jpg
Arduino tutorial: How to use servo motor

Hey guys! welcome to my new tutorial, I Hope you already enjoyed my previous instructable "Large stepper motor control". Today' I'm posting thsi informative tutorial to teach you the basics of any servomotor control, I already posted a video about controlling speed and direction of DC motors and stepper motors and today we will get started with the servos and this way we are done with most of the important actuators that a maker can use.

During the making of this tutorial, we tried to make sure that this instructable will be the best guide for you in order to enjoy learning the basics of servomotors controlling because learning the working process of the electronics actuators is so important for projects development. So we hope that this instructable contains the needed documents.

What you will learn from this instructable:

  1. Define the servomotors Uses and Needs.
  2. Take a look inside the servomotor hood.
  3. Understand the servomotor mechanism.
  4. Learn the electrical control part.
  5. Make the appropriate wiring diagram with an Arduino board.
  6. Test your first servomotor control program.

Lear What Are the "servo Motors"!

Diapositive4.PNG
IMG_20200705_171212.jpg
IMG_20200705_170711.jpg
IMG_20200705_170828.jpg
IMG_20200705_170852.jpg

Servo motors has been around for a long time and are utilized in many applications. They are small in size but pack a big punch and are very energy-efficient, which makes them superior choice for many applications.

Unlike the stepper and DC motors the servo circuitry is built right inside the motor unit and has a positionable shaft, which usually is fitted with a gear. The motor is controlled with an electric signal which determines the amount of movements of the shaft.

So from here we define that in order to understand how the servo works we need to take a look under the hood. Inside the servo (check the above photos), there is a pretty simple set-up:

  • Small DC motor
  • Potentiometer
  • Control circuit.

The motor is attached by gears to the control wheel.

As the motor rotates, the potentiometer's resistance changes, so the control circuit can precisely regulate how much movement there is and in which direction.

So when the shaft of the motor is at the desired position, power supplied to the motor is stopped.

How the Servomotor Works

Diapositive5.PNG
Diapositive6.PNG

Servos are controlled by sending an electrical pulse of variable width, or pulse width modulation (PWM) through the control wire.

Yes, it reminds me the PWM pins of the Arduino!

A servo motor can usually only turn 90° in either direction for a total of 180° movements regarding the frequency and the pulse width received through its control wire.

The servo motor expects to see a pulse every 20 milliseconds (ms) and the length of the pulse will determine how far the motor turns. For example, a 1.5ms pulse will make the motor turn to the 90° position. Shorter than 1.5ms moves it in the counter clockwise direction toward the 0° position, and any longer than 1.5ms will turn the servo in a clockwise direction toward the 180° position.

The Circuit Diagram (how to Wire a Servo)

IMG_20200705_180022.jpg
IMG_20200705_174643.jpg
Schematic_SERVO motor control_2020-07-12_10-25-33.png

I’m using in this tutorial a Carson servo used for racing cars due to its high torque and metal gears, like all servos it has three wires, one wire for the control signal and two wires for power supply which is 6V DC but for testing the movements it is ok the run with 5V DC.

I’m using also an Arduino Nano board which has already PWM pins for signal control.

In order to control to servo movements I will use a potentiometer attached to an analog input of my Arduino and the servo shaft will be exactly as same as the potentiometer rotation.

I moved to EasyEDA to prepare the circuit diagram, it is a pretty simple setup since all what we need is a servo motor powered by an external DC 5V power supply and controlled by an Arduino Nano through the analog signals received from a potentiometer.

Codes and Tests

code.JPG
IMG_20200705_174854.jpg
IMG_20200705_174629.jpg

About the control program, in this tutorial we will use an Arduino Library which is the servo library allowing the creation of a servo instance where you need to set the output control pin for the servo and in this example we are using PWM pin 9, then we are reading the analog signals from the potentiometer through the analogRead function from the analog input A0

In order to control the servo we need to use the write function from the servo object which get a value from 0 to 180 so we convert the analog value which is from 0 to 1024 (size of the ADC) to a value from 0 to 180 using the map fuction. Then we drop the converted value in the write function.

Following this tutorial you are now able to control and test your servo motors and you can develop these knowledge to control more servo in an advanced mechanism like robotic Arms.

That's it for this tutorial.

It was BEE MB from MEGA DAS see you next time.