Circuit diagrams

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.

Get Mastering Arduino now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.