Arduino UNO R4 - Potentiometer Servo Motor
This tutorial instructs you on how to control a servo motor with a potentiometer using Arduino Uno R4. This tutorial demonstrates how to adjust the servo motor's angle by rotating a potentiometer. You'll learn:
- How to connect potentiometer and servo motor to Arduino Uno R4.
- How to program Arduino Uno R4 to read value from the potentiometer, convert it to the angle value, and then control servo motor accordingly.
Hardware Preparation
Or you can buy the following sensor 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 .
Overview of Servo Motor and Potentiometer
Before moving forward, if you're not familiar with servo motors and potentiometers (their pinout, functioning, and programming), please refer to the tutorials below:
Wiring Diagram
- The wiring diagram between Arduino UNO R4, servo motor, and classic potentiometer

This image is created using Fritzing. Click to enlarge image
- The wiring diagram between Arduino UNO R4, servo motor, and potentiometer module

This image is created using Fritzing. Click to enlarge image
See The best way to supply power to the Arduino Uno R4 and other components.
How To Program
- Reads the value of the potentiometer (values range from 0 to 1023)
- Adjusts it to an angle (value between 0 and 180)
- Changes the position of the servo based on the angle.
Arduino UNO R4 Code
Detailed Instructions
Follow these instructions step by step:
- If this is your first time using the Arduino Uno R4 WiFi/Minima, refer to the tutorial on setting up the environment for Arduino Uno R4 WiFi/Minima in the Arduino IDE.
- Wire the components according to the provided diagram.
- Connect the Arduino Uno R4 board to your computer using a USB cable.
- Launch the Arduino IDE on your computer.
- Select the appropriate Arduino Uno R4 board (e.g., Arduino Uno R4 WiFi) and COM port.
- Copy and paste the above code into the Arduino IDE
- Click the Upload button in Arduino IDE to transfer the code to the Arduino UNO R4

- Open the Serial Monitor
- Turn the potentiometer
- Watch the servo motor rotate
- Check the result on the Serial Monitor
Code Explanation
Check the explanations given in the comments of the source code ⇒ written line by line!