Introduction: ARDUINO : Servo Angle Controlled by Potentiometer

Picture of ARDUINO : Servo Angle Controlled by Potentiometer

This instructable shows how to control the angle of a servo motor using a potentiometer.

Part List:

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:

Picture of 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:

Picture of 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:

Picture of 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:

Picture of BREADBOARD LAYOUT:

Step 5: ARDUINO CODE:

Picture of ARDUINO CODE:
// Controlling a servo position using a potentiometer (variable resistor)


#include

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

void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}

void loop()
{
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.

Picture of TEST IT... AND MAKE YOUR OWN PROJECTS WITH THIS CONCEPT.

Comments

mustafahamza8 (author)2016-02-04

hey >>

can u help me ??
i made this project but the servo motor does not stopped when the potentiometer stopped ??

u can watch the video :) >>

Hellow, the small servo motor which you have happens to be a continuous rotating servo. Did you mod the servo yourself? And yea, the motor looses it's ability to feedback it's position to the arduino which results in you not having control over the motor.

Surya Krishnakumar (author)2017-06-04

Hellow Friends :D Could you please spare some time and checkout my new instructable ? https://www.instructables.com/id/Simple-LM386-Powe...

Thanks a lot for all your support and appreciations. :D

CodyW20 (author)2016-03-08

I made it but i can't upload pictures. i had to take the delay in the code out before the servo would work with the potentiometer.

Surya Krishnakumar (author)2015-04-30

I think i made the images larger.. Thank you people, hope it was instructable.

acheide (author)2015-04-29

This looks like an easy way to start with servos on an Arduino. The pictures may be a little small, but I like your effort.

Thanks.

tytower (author)2015-04-29

Your pictures are too small . Cant get them big enough

Syphy (author)2015-04-29

Wrong comment on line which attach the servo to the pin 2 of the arduino.

Don't want to be a troublemaker, but it can be puzzling for a person who is not aware of arduino programming.

JRV31 (author)2015-04-29

Can you make your pictures larger?