Servo Motor Interfacing
A servo motor uses servo mechanism, which is a closed loop mechanism that uses position feedback to control the precise angular position of the shaft.Servo Motors are preferred in angular motion applications such as robotic arm. Moreover controlling of servo motors are very simple and easy.
Overview
All you need for this Arduino Tutorial is an Servo Motor for angular motion, Jumper Wire to Servo Motor and an Arduino Board for controlling servo. You can watch the following video or read the written tutorial below.
About Servo Motor
A servomotor is a closed-loop servomechanism that uses position feedback to control its motion and final position. The input to its control is a signal (either analogue or digital) representing the position commanded for the output shaft.

Components needed for this Arduino Project
- Arduino Uno/nano
- Jumper Wire
- SG90 Micro Servo Motor
Circuit Schematics

Building Connection
- Connect the positive pin of Servo Motor with 5v pin of Arduino board.
- Connect the negative pin of Servo Motor with GND (Ground) of Arduino board.
- Connect the Signal pin of Servo Motor with pin no. 3 in Arduino board.
Interpretation of Code
1 ) To actuate Servo Motor it takes only a few lines of code. The first thing we have to do is include the library file for servo motor in our Arduino IDE thereafter we call the library in our code and Define the Servo name as global variable as written below.
#include <Servo.h>
Servo myservo;
2) The second thing we need to do is configure as an output signal pin connected to Servo Motor. We do this with a call to the in servo.attach() function, inside of the sketch’s setup() function:
void setup() {
myservo.attach(3); // attaches the servo on pin 3 to the servo Signal
}
3) Finally, we have to actuate the Servo Motor at a particular angle in the sketch’s loop(). We can do this with single calls to the myservo.write(x) function, where x is a variable through which we control the servo motor shaft angle, the Servo Motor shaft would turn at some angle too quickly for us to see, so we call to delay() function to give time interval between two lines of code. The delay function works with MILLISECONDS, so we pass it 1000 to pause for a second.
void loop() {
// sets the servo position value Between 0 to 180 Degree
myservo.write(0);
delay(1000);
myservo.write(90);
delay(1000);
myservo.write(130);
delay(1000);
myservo.write(160);
delay(1000);
myservo.write(180);
delay(1000);
}
Source Code
#include <Servo.h>
Servo myservo; // create servo object to control a servo
void setup() {
myservo.attach(3); // attaches the servo on pin 3 to the servo signal
}
void loop() {
// set the servo position value Between 0 to 180 Degree
myservo.write(0);
delay(1000);
myservo.write(90);
delay(1000);
myservo.write(130);
delay(1000);
myservo.write(160);
delay(1000);
myservo.write(180);
delay(1000);
}