Introduction: ARDUINO : Servo Angle Controlled by Potentiometer
This instructable shows how to control the angle of a servo motor using a potentiometer.
1) Arduino ( any kind will do)
2) Bread board
3) Male to Male jumper wires
4) Servo motor
5) Potentiometer ( 10k should work fine)
Step 1: Connecting the Potentiometer:
1) Connect the potentiometer to any three open rows on the breadboard.
2) Connect negative pin of the potentiometer to ground rail on the breadboard.
3) Connect positive pin of the potentiometer to power rail on breadboard.
4) Connect signal pin of the potentiometer to PIN0 on the Arduino.
Step 2: Connecting the Servo:
1) Insert three Male to Male Jumpers into the servo's Female hub.
2) Connect the positive wire (usually red) of the Servo motor to power rail on the breadboard.
3) Connect the negative wire (usually black or brown) of the servo motor to the ground rail on the breadboard.
4) Connect the Signal wire (usually yellow, white or orange) of the Servo motor to PIN2 on the Arduino.
Step 3: Connecting the Arduino:
1) Connect the 5vPIN of the arduino to the power rail on the breadboard.
2) Connect the GNDPIN of the arduino to the ground rail on the breadboard.
Step 4: BREADBOARD LAYOUT:
Step 5: ARDUINO CODE:
Servo myservo; // create servo object to control a servo
int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
myservo.attach(9); // attaches the servo on pin 9 to the servo object
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
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
Step 6: TEST IT... AND MAKE YOUR OWN PROJECTS WITH THIS CONCEPT.
We have a be nice policy.
Please be positive and constructive.