Arduino Nano - Potentiometer Servo Motor
This tutorial instructs you how to use Arduino Nano to control the angle of a servo motor based on the input value from a potentiometer. In detail, we will learn:
- How to connect the potentiometer and servo motor to Arduino Nano
- How to program Arduino Nano to read the value from a potentiometer and control a servo motor accordingly.
Hardware Preparation
Or you can buy the following kits:
| 1 | × | DIYables Sensor Kit (30 sensors/displays) | |
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Buy Note: For controlling multiple servo motors, use the PCA9685 16 Channel PWM Servo Driver Module to save MCU pins and simplify wiring.
Overview of Servo Motor and Potentiometer
If you are unfamiliar with servo motors and potentiometers, including their pinouts, how they work, and how to program them, the following tutorials can help:
Wiring Diagram

This image is created using Fritzing. Click to enlarge image
See The best way to supply power to the Arduino Nano and other components.
How To Program
- Retrieves the value of the potentiometer, which is a number between 0 and 1023.
- Scale it to an angle in the range of 0 to 180.
- Control the servo to the specified angle.
Arduino Nano Code
Detailed Instructions
- Plug the USB cable into the Arduino Nano and PC.
- Launch the Arduino IDE and select the appropriate board and port.
- Open the code in the Arduino IDE.
- To send the code to the Arduino Nano, press the Upload button on the Arduino IDE.

- Open the Serial Monitor
- Turn the potentiometer
- Check out the servo motor's rotation
- Check the outcome on the Serial Monitor
Code Explanation
Check out the line-by-line explanation contained in the comments of the source code!