Potentiometer-controlled Servo
by TechMartian in Circuits > Arduino
3377 Views, 15 Favorites, 0 Comments
Potentiometer-controlled Servo
![2016-07-15 12.53.45.jpg](/proxy/?url=https://content.instructables.com/F0M/VHUQ/J58FPIIC/F0MVHUQJ58FPIIC.jpg&filename=2016-07-15 12.53.45.jpg)
The coupling application of the potentiometer and servo serves as an important use case in making applications that take advantage of the potentiometer as a rotary measurement of any input. For example, an animatronic helper hand for people with C-6 Quadruplegia or even muscular dystrophy could use the potentiometer as an input for the finger that they can control to aid movement of the other fingers by the use of the servo as a mechanical actuator. This is only one of the many possibilities of the coupling of these two useful electronic components.
Tools and Materials
![2016-07-15 12.31.13.jpg](/proxy/?url=https://content.instructables.com/FN4/RL1F/J58FPIII/FN4RL1FJ58FPIII.jpg&filename=2016-07-15 12.31.13.jpg)
- Arduino 101 or Arduino Uno
- Servo Motor
- Potentiometer
- Breadboard
- Jumper Wires
Circuitry
![Screen Shot 2017-07-17 at 11.22.38 PM.png](/proxy/?url=https://content.instructables.com/F86/NPD2/J58FPJSW/F86NPD2J58FPJSW.png&filename=Screen Shot 2017-07-17 at 11.22.38 PM.png)
![2016-07-15 12.54.22.jpg](/proxy/?url=https://content.instructables.com/F3K/76UQ/J58FPIIA/F3K76UQJ58FPIIA.jpg&filename=2016-07-15 12.54.22.jpg)
![2016-07-15 12.53.37.jpg](/proxy/?url=https://content.instructables.com/FV4/P8FV/J58FPIIE/FV4P8FVJ58FPIIE.jpg&filename=2016-07-15 12.53.37.jpg)
The Arduino will supply two different voltages as mandated by the servo and the potentiometer. That is, 3.3V for the potentiometer and 5V for the servo motor. Since these are the only two electronics that need to be power other is no need to use the power rails of the breadboard.
Wiring the servo to the Arduino
- Connect the red (or sometimes orange) wire of the servo to the 5V pin of the Arduino using red male-to-male jumper wire.
- Connect the black (or sometimes brown) wire of the servo to the GND pin of the Arduino using black male-to-male jumper wire
- Connect the white (sometimes yellow) wire of the servo to pin 9 of the Arduino using a similarly coloured wire.
Wiring the potentiometer to the Arduino
- Connect one of the outer leads of the potentiometer to 3.3V pin of the Arduino with a red jumper wire
- Connect the remaining outer lead of the potentiometer to the other GND pin of the Arduino not already connected to the servo with a black jumper wire
- Connect the middle pin of the potentiometer to the A0 analog pin of the Arduino
Code
![Screen Shot 2017-07-17 at 11.13.42 PM.png](/proxy/?url=https://content.instructables.com/FK4/O519/J58FPIC2/FK4O519J58FPIC2.png&filename=Screen Shot 2017-07-17 at 11.13.42 PM.png)
//include the servo library
#include
//create a servo object called servo1 Servo servo1;
// declare the pins to which the servo and potentiometer is connected. const int servoPin = 9; const int pot = 0;
void setup() { //attach servo1 to pin 9 on the Arduino 101 servo1.attach(9);
}
void loop() { // put your main code here, to run repeatedly: int 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);
}
Demo
![Controlling a Servo with Potentiometer](/proxy/?url=https://content.instructables.com/FSJ/ANFD/J58FPEYQ/FSJANFDJ58FPEYQ.jpg&filename=Controlling a Servo with Potentiometer)
Since the values of the minimum and maximum values of the potentiometer is mapped to the minimum and maximum values of the servo motor, this allows us to control the output of the servo to move linearly with respect the the rotary motion of the potentiometer.
In the demo, you will see that as I turn the knob of the potentiometer it controls the control horn of the servo to move in that specific angle.