The following diagram shows how to connect the servo motor with the Arduino:
In this project, we will use the potentiometer to control the position of the servo motor. Notice that the potentiometer uses the 5V power source from the Arduino while the servo motor uses 6V (4 × 1.5V) from the batteries; however, the two power sources share a common ground. Now let's look at the code to control the servo motor.