Servo Motor with an Arduino

In this tutorial, we will learn how to control a Servo Motor with an Arduino. Servo motor is an electrical device that can be used to rotate the objects (like a robotic arm) precisely. It is a rotary actuator or the linear actuator which allows precise control of angular or linear position, velocity, and acceleration.

Servo motor has a rotation angle that varies from 0° to 180°.

Read More about Servo Motor.

In this tutorial, we will cover –

  • Testing servo motor.
  • Servo Motor speed changing.
  • Control the Servo Motor speed by the potentiometer.
  • Position Control of Servo Motor Shaft by the potentiometer.
servo motor

Component List

Circuit Diagram For Servo Motor Arduino

servo motor circuit arduino

Pin Connections

Arduino UNOServo Motor
Vin 5vVcc (Red Wire)
GNDGND (Brown Wire)
D9Control (Orange Wire)

Code for Servo Motor with an Arduino

When the code starts running, the Servo motor rotates from 0° to 180° repeatedly with a pause of half-second from the start position and end position. The servo motor runs with his full speed.

Code for Changing the Servo Motor Speed

The below code is to drive the servo motor in slow motion. By changing the delay time in the “for” loop you can increase or decrease the servo motor speed.

Code for Control the speed of Servo Using Potentiometer

This code is for changing the speed of the servo motor using a potentiometer. By adjusting the potentiometer knob we will control the servo motor speed. The potentiometer will help in changing the delay time which is written in “for” loops in given code.

servo motor arduino connection

Code For Position Control of Servo Shaft

Here some more tutorials for you:

Scroll to Top