Author
Prathamesh Barik, CircuitDigest
Controlling a Servo
Motor with Arduino
A servo motor is used to
rotate objects at specific
angles.
It’s widely used in robotics,
automation, and hobby
projects.
This tutorial explains how to
connect and control a servo
motor using Arduino.
Components
Needed
Arduino UNO – The controller
to send angle signals.
Servo Motor (e.g., SG90) –
Rotates to specified angles.
Power Source (USB or external
5V)
Jumper Wires – For
connections
How the Code Works
Method 1: Servo Sweep Code
Rotates servo from 0° to
180° and back in a loop.
Great for testing motor
range.
Uses myservo.write(pos) to
move the servo.
How the Code Works
Method 2: Servo Knob Code (With
Potentiometer)
Control servo angle using a
potentiometer.
Reads analog input → converts
to angle (0°–180°).
Code uses:
analogRead(A0) to read pot
value
map() to scale input
servoMotor.write(angle) to
move servo
Where It’s Used
Common uses:
Robotic arms
Smart locks
Camera positioning systems
Remote-controlled cars
Working
Demonstration
Here’s how the project
output looks like, you can
see that in our servo
Arduino setup the servo
motors is being controlled
using the potentiometer.
For a more in-depth tutorial,
check out this article:
https://circuitdigest.com/microcontroll
er-projects/interface-servo-motor-with-
arduino
www.circuitdigest.com
Robotics Projects|Arduino Projects|Raspberry Pi Projects| ESP32
Projects | AI Projects | IoT Projects
Human Following Robot
Using Arduino and
Ultrasonic Sensor
Build your own Mars Rover
Robot using Arduino
Line Follower Robot using
Arduino UNO: How to
Projects using DIY Arduino Bluetooth Car
Build (Step-by-Step
Guide)
L298N Motor Driver Controlled by Mobile
Application
These projects explore different ways DIY Self Balancing Robot
to use the L298N motor driver for using Arduino
controlling motors in robotics and
automation