Introduction: Servo Motor + Potentiometer + Arduino: Potentiometer-Controlled Servo
Hello World!
I'm Unicorn Clockworks, here with another project. Today, we will be controlling a servo motor's angle using a potentiometer knob, where the angle of the servo motor corresponds to the rotational displacement of the potentiometer with a linear correlation.
Step 1: Materials
- Arduino or Arduino-compatible microcontroller
- Servo Motor
- Potentiometer
- Jumper Wires
- [Optional] Breadboard
Step 2: Potentiometer Connections
1a
- Connect the Grey wire from the VCC pin of the potentiometer (pin 1) to the 3.3V pin on the Arduino.
- Connect the Green wire from the signal wire of the potentiometer (pin 2) to pin A0 on the Arduino.
- Connect the Purple wire from the ground wire of the potentiometer (pin 3) to the GND pin on the Arduino
Step 3: Servo Connections
2a
- Connect the Blue wire from the signal pin of the servo motor (orange-coloured wire) to pin 3 on the Arduino
- Connect the Red wire from the VCC pin of the servo motor (red-coloured wire) to the 5V pin on the Arduino
- Connect the Black wire from the ground pin of the servo motor (black-coloured wire) to the GND pin on the Arduino
Step 4: Code
//include the servo library
#include <Servo.h>
//create a servo object Servo servo1;
// declare the pins to which the servo and potentiometer is connected. const int servoPin = 3; const int pot = 0; int potValue;
void setup() { //associate servo1 to pin 9 on the Arduino 101 servo1.attach(servoPin);
}
void loop() { // put your main code here, to run repeatedly: potValue = analogRead (pot);
// linearly scale the value of the sevo output from the 0 to 1023 range of the potentiometer // to the angle limits by the servo which is 0 to 180 degrees potValue = map(potValue, 0, 1023, 0, 180);
// record the now-adjusted value of the potentiometer to the servo motor servo1.write(potValue);
}
Attachments
Step 5: It Works!
Turn the knob of the potentiometer and watch the servo motor move along with it.
Enjoy your build and have fun!
Unicorn ClockWorks Out!

Participated in the
Makerspace Contest 2017
Comments
5 years ago
I shared this with my class as they built the same project. Thanks for the help