After learning Arduino basics (like blinking an LED), the next step is usually controlling movement. A servo motor is the simplest and most common way to start down this path — from a robotic arm to a small car's steering.
What is a servo motor, and how is it different from a regular DC motor?
Unlike a DC motor, which just spins, a servo motor can move to a precise, specific angle (typically between zero and 180 degrees) and hold it there — exactly the control needed for precise robotic arm movement or steering.
Step 1: Connecting the servo motor
A servo motor has three wires: positive power (usually red), negative/ground (usually brown or black), and signal (usually orange or yellow). Connect the power and ground wires to the Arduino's 5V and GND pins, and the signal wire to one of the digital pins (e.g., pin 9).
Step 2: Installing the Servo library
The Servo library comes pre-installed with the Arduino IDE — no separate download needed. Just add #include <Servo.h> at the top of your code.
Step 3: Writing your first code
With three simple commands — defining a Servo object, attaching it to a pin with attach(), and setting an angle with write() — you can move the servo to any angle you want. For example, myServo.write(90); moves the servo to the 90-degree (middle) position.
Step 4: Smooth, continuous movement
For smooth movement (instead of jumping instantly to the target angle), use a for loop that increases the angle degree by degree, with a short delay() between each step, instead of a single write() call.
Step 5: Combining it with an input
For a more realistic project, connect the servo to a potentiometer (or another sensor) so the servo's angle changes proportionally to the value read from the input — this is exactly the core concept behind robotic remote control.
Summary
A servo motor is the first real step toward controlled movement in robotics. In my in-person workshops, this concept is taught right before building the first complete project, like a line-following robot.
Blog
Working with Servo Motors in Arduino
Related Articles
Prefer hands-on, in-person learning?
You can learn this same material in person, with real hands-on labs, at Amniat Technical & Vocational Institute in Shiraz.
Visit Amniat Academy in Shiraz