Servo Motor Basics, Working principle & interfacing with Arduino

Introduction

Servo Motor
Servo Motor

 

  • Servo motor is an electrical device which can be used to rotate objects (like robotic arm) precisely.
  • Servo motor consists of DC motor with error sensing negative feedback mechanism. This allows precise control over angular velocity and position of motor. In some cases, AC motors are used.
  • It is a closed loop system where it uses negative feedback to control motion and final position of the shaft.
  • It is not used for continuous rotation like conventional AC/DC motors.
  • It has rotation angle that varies from 0° to 180°.
Servo Motor Mechanism

 

As shown in above figure Servo motor has three pins for its operation as,

  • +VCC (RED)

            -  Connect +VCC supply to this pin. For SG90 Micro Servo it is 4.8 V (~5V).

  • Ground (BROWN)

            -  Connect Ground to this pin.

  • Control Signal (ORANGE)

            -  Connect PWM of 20ms (50 Hz) period to this pin.

 

Servo Motor Working Principle of Operation

  • It consists of dc motor, gear assembly and feedback control circuitry. PWM signal is used to control the servo motor. It is applied on control signal pin.
  • Servo feedback control circuitry contains comparator which compares the control signal (PWM) and potentiometer reference signal to generate error signal which is later amplified and given to the DC motor.
  • DC motor shaft is connected to potentiometer shaft (knob) through gear assembly. So rotating DC motor rotates potentiometer, which in term changes potentiometer reference signal given to the comparator.
  • At some position of shaft, both potentiometer signal and control signal strength match, which produces zero error signal output. Hence rotation continues till comparator output error signal becomes zero and DC motor stops.

Servo Working

Servo motor position is controlled by pulse width modulation (PWM) signal. The width of the control signal pulse is used to vary shaft position of servo motor. We can vary SG90 Micro servo motor angular rotation in between 0° to 180° angle with PWM signal as shown in below figure.

Servo Motor PWM duty cycle

Above figure shows angular rotation of servo shaft. It uses PWM of 50Hz frequency with TON variation from 1ms to 2ms. The servo motor rotates 90° in either direction from its middle position i.e. it gives control over 180° of its rotation.

At ~1ms (5% duty cycle) we get shaft position at -90° of its rotation.

At 1.5ms (7.5% duty cycle) we get shaft position at 0° (neutral) of its rotation.

At ~2ms (10% duty cycle) we get shaft position at +90° of its rotation.

 

Connection Diagram of Servo Motor with Arduino

Interfacing Servo Motor With Arduino UNO
Interfacing Servo Motor With Arduino UNO

 

Code For Servo Position Control Using Potentiometer and Arduino

/*
 Controlling a servo position using a potentiometer (variable resistor)
 by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>

 modified on 8 Nov 2013
 by Scott Fitzgerald
 http://www.arduino.cc/en/Tutorial/Knob
*/

#include <Servo.h>

Servo myservo;  /* create servo object to control a servo */

int potpin = 1;  /* analog pin used to connect the potentiometer */
int val;    /*  variable to read the value from the analog pin */

void setup() {
  Serial.begin(9600);
  myservo.attach(9);  /* attaches the servo on pin 9 to the servo object */
}

void loop() {
  val = analogRead(potpin);            /* reads the value of the potentiometer (value between 0 and 1023) */
  Serial.print("Analog Value : ");
  Serial.print(val);
  Serial.print("\n");
  val = map(val, 0, 1023, 0, 180);     /* scale it to use it with the servo (value between 0 and 180) */
  Serial.print("Mapped Value : ");
  Serial.print(val);
  Serial.print("\n\n");
  myservo.write(val);                  /* sets the servo position according to the scaled value */
  delay(1000);                         /* waits for the servo to get there */
}

 

At the output control the servo motor position using a potentiometer

To know more about Servo Motor using Arduino refer to this link

 

Examples of Servo Motor interfacing

  1. Servo Motor Interfacing with ATmega16
  2. Servo Motor Interfacing with PIC18F4550
  3. Servo Motor Interfacing with Arduino
  4. Servo Motor Interfacing with 8051
  5. Servo Motor Interfacing with TI Launchpad
  6. Servo Motor Interfacing with LPC2148
  7. Servo Motor Interfacing with ESP32

Components Used

Servo Motor MG995
Servo Motor MG995
1
Ad