Servo Motor Control
Anand RamaswamiShare
Welcome Back, Maker!
So far you have made LEDs glow, buzzers beep, motors spin, and sensors react to the world around them.
But there is one kind of movement we have not properly controlled yet:
position.
A DC motor spins continuously. That is great for wheels and fans.
But what if you want something to move to an exact angle and stop there?
What if you want:
- a robot arm to lift to a certain position
- a smart door to open halfway
- a pointer to move to 90°
- a small gate to open and close neatly
That is exactly what a servo motor is made for.
In this blog, you will learn what a servo motor is, how it works, and how to control its angle using Arduino.
What Is a Servo Motor?
A servo motor is a special type of motor that can move to a specific angle instead of spinning freely all the time.
A normal DC motor does this:
- power ON → keeps spinning
- reverse power → spins the other way
A servo motor is different
You can tell it:
- go to 0°
- go to 90°
- go to 180°
and it moves to that position and holds it there.
That is why servo motors are used in projects where accurate movement matters.
Where Are Servo Motors Used?
Servo motors are everywhere in robotics and automation.
They are used in:
- robot arms
- automatic door locks
- camera pan mechanisms
- pick-and-place machines
- RC cars and airplanes
- moving pointers and indicators
The common idea is simple:
A servo is used when you want controlled angle movement, not continuous spinning.
What Is Inside a Servo Motor?
Inside a servo motor there are actually a few parts working together:
- a small DC motor
- a set of gears
- a position sensor
- a control circuit
The DC motor provides the movement.
The gears reduce speed and increase control.
The position sensor tells the servo what angle it is currently at.
The control circuit compares:
- where the servo is now
- where you want it to go
and keeps adjusting the motor until the servo reaches the correct position.
That is why a servo can move accurately and stop at the angle you choose.
Servo Motor Wires
A servo motor usually has 3 wires:
- VCC → power
- GND → ground
- Signal → control signal from Arduino
On the NanoMake Pro, the servo port is already available and mapped to D11.
So you do not need to figure out complex wiring.
You just connect the servo to the servo port and control it in code.
How Does a Servo Motor Work?
A servo motor does not use simple ON/OFF control like an LED.
It also does not use regular PWM for speed like a DC motor.
Instead, a servo uses control pulses.
The Arduino sends a repeating signal to the servo.
The width of that pulse tells the servo what angle to move to.
In simple terms:
- one pulse width means 0°
- another pulse width means 90°
- another pulse width means 180°
So the servo listens to the signal and moves to the matching position.
This is why the concept list for your board includes servo pulse timing as an important topic.
The Servo Library
To control a servo easily in Arduino, we use the Servo library.
This library handles the pulse timing for us, so we do not need to generate those pulses manually.
The commands we use are:
|
#include <Servo.h> |
This adds the Servo library to the program.
| Servo myServo; |
This creates a servo object.
| myServo.attach(11); |
This connects the servo object to pin 11.
| myServo.write(angle); |
This tells the servo to move to a specific angle.
Project 1: Rotate Servo to Fixed Angles
Let us start with the most basic servo project.
In this project, the servo will move to a few fixed positions:
- 0°
- 90°
- 180°
and then repeat.
Code:
|
#include <Servo.h> Servo myServo; void setup() { myServo.attach(11); // Servo connected to pin 11 } void loop() { myServo.write(0); // Move to 0 degrees delay(1000); myServo.write(90); // Move to 90 degrees delay(1000); myServo.write(180); // Move to 180 degrees delay(1000); } |
Explanation:
#include <Servo.h> loads the Servo library so Arduino can control the servo easily.
Servo myServo; creates a servo object named myServo.
myServo.attach(11); tells Arduino that the servo signal wire is connected to pin D11.
myServo.write(0); moves the servo to 0 degrees.
myServo.write(90); moves the servo to the center position, 90 degrees.
myServo.write(180); moves the servo to 180 degrees.
delay(1000); gives the servo enough time to reach each position before moving again.
Upload this code and watch the servo move step by step between the three angles.
This is the simplest way to understand position control.
Output:

Now let us make the servo respond to input.
Project 2: Control Servo Using Potentiometer
In this project, the potentiometer controls the servo angle directly.
Turn the knob left and the servo moves one way.
Turn the knob right and the servo moves the other way.
This makes the potentiometer act like a manual angle controller.
Code:
|
#include <Servo.h> Servo myServo; void setup() { myServo.attach(11); // Servo connected to pin 11 } void loop() { int potValue = analogRead(A6); // Read potentiometer int angle = map(potValue, 0, 1023, 0, 180); // Convert to servo angle myServo.write(angle); // Move servo delay(15); } |
Explanation:
analogRead(A6); reads the potentiometer value.
That value will be between 0 and 1023 depending on the knob position.
map(potValue, 0, 1023, 0, 180); converts the potentiometer range into a servo angle range.
Why do we need this?
Because:
- the potentiometer gives values from 0 to 1023
- the servo needs values from 0 to 180
So map() translates one range into the other.
myServo.write(angle); sends the new angle to the servo.
delay(15); gives the servo a tiny moment to move smoothly.
Now when you turn the knob, the servo follows your hand in real time.
That connection between your hand and the moving servo is what makes this project feel so satisfying.
Output:
So far, the servo has moved either to fixed positions or followed the knob directly.
But sometimes we want the servo to move smoothly on its own from one side to the other.
That leads us to a very common beginner servo pattern: the sweep motion.
Project 3: Servo Sweep Motion
In the first project, the servo jumped between fixed positions.
In this project, it moves smoothly from one side to the other and then comes back again.
This is called a sweep motion.
Code:
|
#include <Servo.h Servo myServo; void setup() { myServo.attach(11); } void loop() { for (int angle = 0; angle <= 180; angle++) { myServo.write(angle); delay(15); } for (int angle = 180; angle >= 0; angle--) { myServo.write(angle); delay(15); } } |
Explanation:
The first for loop starts at 0 and slowly increases the angle to 180.
Each time through the loop, the servo moves one step further.
The second for loop starts at 180 and slowly decreases back to 0.
This creates a left-to-right and right-to-left motion.
This kind of sweep is useful for:
- scanning systems
- moving sensor mounts
- decorative movement
- simple robotic arms
Output:

A smooth automatic sweep looks nice, but many real systems need the movement to happen only when a user presses a button.
So the next step is to combine digital input with servo control.
Project 4: Button-Based Servo Positions
Now let us combine digital input and servo control.
In this project, different buttons move the servo to fixed angles.
That means a button press can instantly choose a position.
Code:
|
#include <Servo.h> Servo myServo; void setup() { pinMode(2, INPUT); pinMode(3, INPUT); pinMode(8, INPUT); myServo.attach(11); } void loop() { if (digitalRead(2) == HIGH) { myServo.write(0); } if (digitalRead(3) == HIGH) { myServo.write(90); } if (digitalRead(8) == HIGH) { myServo.write(180); } } |
Explanation:
Each button is set as an input.
The program checks each button using digitalRead().
If Button 1 is pressed, the servo moves to 0°.
If Button 2 is pressed, the servo moves to 90°.
If Button 3 is pressed, the servo moves to 180°.
Output:

This is a simple but powerful idea:
a button press causes a physical mechanism to move to a chosen position.
That is the foundation of many automation systems.
Real-Life Examples of Servo Control
Servo motors are used in many real products and machines.
In a smart door lock, a servo rotates a latch to lock or unlock the door.
In a robot arm, servos move the joints to exact angles.
In RC airplanes, servos control the flaps and steering surfaces.
In camera systems, servos are used to pan and tilt the camera.
The common idea is always the same:
a servo lets you control where something moves.
Not just whether it moves.
What You Learned in This Blog
You started this blog with a new kind of motor.
Now look at what you understand.
You know what a servo motor is and how it is different from a DC motor.
You know that a servo is designed for position control.
You know that inside the servo there is a motor, gears, a position sensor, and a control circuit.
You know that the servo on the NanoMake Pro uses pin D11.
You know how to use the Servo library, including:
- attach()
- write()
You built projects that:
- move the servo to fixed angles
- control the servo with a potentiometer
- sweep the servo smoothly
- move the servo using buttons
This is one of the most important ideas in robotics:
not just making something move, but making it move to the right place.
That is real control.
Keep experimenting, keep building, and keep making.