Omar KhadimallyTrey GermanAli Soomar
Published

Controlling SERVO with POTENTIOMETER

Let's learn how to control a servo's position just by twisiting a potentiometer!

BeginnerProtip2,404
Controlling SERVO with POTENTIOMETER

Things used in this project

Hardware components

MSP-EXP432P401R SimpleLink MSP432 LaunchPad
Texas Instruments MSP-EXP432P401R SimpleLink MSP432 LaunchPad
×1
Servos (Tower Pro MG996R)
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×1

Story

Read more

Code

Coding for KNOB - Servo and Potentiometer

C/C++
Energia Coding
// Controlling a servo position using a potentiometer (variable resistor) 
// by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
// Modified for Energia/Stellaris Launchpad by Kevin Balke <fughilli@gmail.com>

#include <Servo.h> 
 
Servo myservo;  // create servo object to control a servo 
 
int potpin = 57;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin 
 
void setup() 
{ 
  myservo.attach(68);  // attaches the servo on Port F, pin 1 (Red LED pin) to the servo object 
} 
 
void loop() 
{ 
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 4095) 
  val = map(val, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180) 
  myservo.write(val);                  // sets the servo position according to the scaled value 
  delay(15);                           // waits for the servo to get there 

Credits

Omar Khadimally

Omar Khadimally

2 projects • 6 followers
Trey German

Trey German

10 projects • 33 followers
Freelance Engineer, hacker, sky junkie, programmer, designer. All projects are my own.
Ali Soomar

Ali Soomar

11 projects • 41 followers
Student at the University of Texas at Austin

Comments