Overview
In this tutorial, we will learn How to Control Multiple Servo Motors with Arduino. We will interface 4 servo Motors with Arduino and control its rotational movement using Pulse Width Modulation Signal. But before that let’s learn about the servo motor it’s working and also its applications.
What is a Servo Motor?
A servo motor is a rotary actuator or linear actuator that allows for precise control of angular or linear position, velocity, and acceleration. It consists of a suitable motor coupled to a sensor for position feedback. It also requires a relatively sophisticated controller, often a dedicated module designed specifically for use with servomotors.
Servomotors are not a specific class of motor although the term servomotor is often used to refer to a motor suitable for use in a closed-loop control system. There are many types of servo motors and their main feature is the ability to precisely control the position of their shaft.
Construction of Servo Motor
The Servo motor is DC motor which has 5 following parts:
Stator Winding: This wound on the stationary part of the motor. It is also known as field winding of the motor.
Rotor Winding: This wound on the rotating part of the motor. It is also known as an armature winding of the motor.
Bearing: This is of two types, i.e font bearing and back bearing which are used for the movement of the shaft.
Shaft: The armature winding is coupled on the iron rod is known as the shaft of the motor.
Encoder: It has the approximate sensor which determines the rotational speed of motor and revolution per minute of the motor.
Working of Servo Motor
The servo motor works on the phenomenon of the automatic closed-loop system. The controller is required for this closed-loop system. This controller is composed of a comparator and a feedback path. It has one output and two inputs. For producing an output signal, the comparator is used to compare the required reference signal and the output signal is sensed by the sensor.
The input signal for the motor is termed as a feedback signal. On the basis of the feedback signal, the motor starts working. Comparator signal is called a logic signal of the motor. The motor gets ON for the desired time when the logical difference is higher and the motor gets OFF for the desired time when the logical difference is lower. Thus, a comparator is used to decide the ON/OFF position.
Controlling of Servo Motor Using PWM Signal
The servo motors can be controlled by Pulse Width Modulation (PWM). These send electric signals of inconsistent width to the motor. The width pulse is varied in the range of 1 millisecond to 2 milliseconds and transfer this to the servo motors with repeating 50 times in a second. The width of the pulse controls the angular position of the rotating shaft. There are 3 terms that are used to control the servo motor:
|
1 2 3 |
1. Maximum Pulse 2. Minimum Pulse 3. Repetition Rate |
The servo moves with the pulse of 1 millisecond to turn motor towards 0˚ whereas a pulse of 2 milliseconds to turn motor towards 180˚. The servo turns to the 90˚ with the pulse of width 1.5 milliseconds.
When servo motor is commanded to move by applying pulses of appropriate width, the shaft moves to and holds the required position. If an external force is trying to change the position of the shaft, the motor resists changing. Pulses need to be repeated for the motor to hold the position.
How to Control Multiple Servo Motors with Arduino
Here, we are going to show you how to control Multiple Servo Motors with Arduino. Connecting multiple Servo Motors with Arduino seems to be easy. But if we connect all the Servos to Arduino supply, they won’t work correctly. This is due to the lack of enough current to drive all the motors. So you have to use a separate external power supply for the motors like Adapters (5v 2A) or 9v batteries.
We are using three SG-90 Servo Motor for a practical demonstration. Below is the circuit diagram.
Source Code/Program
Copy and upload this Source Code/Program for Controlling multiple servo motors with Arduino.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
#include <Servo.h> Servo servo1; Servo servo2; Servo servo3; int i = 0; void setup() { servo1.attach(3); servo2.attach(5); servo3.attach(6); } void loop() { for (i = 0; i < 180; i++) { servo1.write(i); servo2.write(i); servo3.write(i); delay(10); } for (i = 180; i > 0; i--) { servo1.write(i); servo2.write(i); servo3.write(i); delay(10); } } |
Code Explanation
Arduino has a library for Servo Motors and it handles all the PWM related things to rotate the servo.
So we are starting by defining the library for Servo motor.
Then we are initializing all the three servos as Servo1, Servo2, Servo3.
And then we set setting all the servo’s input pin with Arduino.
In the void loop() function, we are just rotating all the servo from 0 to 180 degree and then 180 to 0 degree. The delay used in the below code is used to increase or decrease the speed of the servo using the variable ‘i’.












1 Comment
What about 100 servos