Introduction: Controlling 3 Servo Motors With 3 Potentiometers and an Arduino

Hi there. This is my first instructable, so I hope you will be patient with me if I make any mistakes setting it up.It is written for beginners like myself, so the more advanced among you can skip a lot of this and just get to wiring it up.

The goal I set myself was to be able to control the robot shown in this web site:

http://bocabearingsworkshop.blogspot.co.id/2015/08...

I needed to be able to control 3 different servo motors by altering the position of 3 potentiometers. There are lots of people out there doing things like this, but I couldn't find an exact match for everything I needed, so I decided to post up this instructable to bring everything I learned together in one place so that anyone else who wanted to do something like this could get it up and running quickly. This instructable is really a summary of other peoples excellent work and effort.

Before I list out the individual steps involved in this, I want to give a quick explanation of how everything works.

The potentiometers send an analog signal to the Arduino. The sketch on the Arduino (more on this later) then converts the analog input from the potentiometer into a digital output and sends this output to the servo motor which then moves left or right by the appropriate amount.

The potentiometers are powered from the Arduino's 5v line, while the servos get their power from the battery pack.

Important note: It is VERY important to ground the Arduino into the battery pack/servos to avoid nasty things from happening, but I will talk about this in more detail as we go along.

Step 1: Preparing Your Components

You need three 10k potentiometers with legs that can fit into a breadboard.

I found them here:

https://www.adafruit.com/products/562

Next are the servo motors. I used the smallest ones as the load they would move would be very small and they were cheap.

https://www.adafruit.com/products/169

Next you need a 4 AA battery pack:

https://www.adafruit.com/products/830

A breadboard to connect everything up:

https://www.adafruit.com/products/239

An Arduino Uno R3 (at least this is what I used):

https://www.adafruit.com/products/50

A usb cable to connect the Arduino to a pc and power it:

https://www.adafruit.com/products/62

The Arduino IDE software to upload the program that will control the servos:

https://www.arduino.cc/en/Main/Software

Some male/male jumper cables and some jumper wire to make the connections

https://www.adafruit.com/products/1956

Breakaway header pins which will be used to connect your motors to the breadboard. I like these ones because you don't have to adjust the plastic divider to get them to fit in a breadboard.

https://www.adafruit.com/products/400


Step 2: Prepare Your Breadboard

A lot of bread boards are split into 2 sections along the power rails at the top and bottom(which caused me a bit of head scratching when I first started using them.) By using 4 small pieces of wire you can bridge across the gap to make sure your power goes all the way across the breadboard. I finally bought one which was connected all the way across but just in case you have this problem, this is how you solve it.

Step 3: Wiring Up One Potentiometer 1

This diagram shows what the 3 pins on the potentiometer are for.


Step 4: Wiring Up the Potentiometer 2

Take 3 of the male male cables and push them into the breadboard as shown in the diagram

Step 5: Wiring Up the Potentiometer 3

Now push the pins of the potentiometer into the breadboard as shown in the diagram

Step 6: Wiring Up the Potentiometer 4

Now repeat this process 2 more times and we will now be ready to connect the signal cables to the Ardiuno

Step 7: Wiring Up the Potentiometer Final Step

Now we take the yellow signal cables and plug them into the Arduino board. Look carefully at the Arduino and you will see a part of the board called Analog In. We will be plugging our cables into A0, A1 and A2 as shown in the diagram.

For the moment that's us finished with the pots, now to get the motors set up.

Step 8: Wiring Up the Motors 1

As with the potentiometers we are going to do the same thing three times so I will talk you through how to set up one in detail and all you have to do is repeat the process.

Cable colours on motors are tricky as they vary from one motor to another. In my diagram

black is ground (-)

Red is power (+)

Yellow is signal(s)

Take a pair of long nosed pliers and break off a strip of 3 header pins and insert them into the female connector on the servo motor. Connect the servo to the breadboard as shown in the diagram. Once you have done that, we will need to connect the motors to the bottom power rails, so take two male male cables and insert them into the breadboard as shown.

Repeat this process two more times and we will then be ready to connect the motors to the arduino

Step 9: Wiring Up the Motors 2

Now we have connected the motors to the bread board it is time to connect the signal cable to the Arduino, for this you will need 3 male male jumper cables.

Plug them into the breadboard and then into the Arduino at these locations:

~9

~10

~11

These are on the right hand side of the Arduino as orientated in my diagram. This is where the digital signal from the Arduino is sent to the servo to tell it how to turn.

Once this is done we are ready to hook up the power and get it working

Step 10: Adding Power

At this point we want to connect the Arduino 5v power and ground to the top rail which will give power to the potentiometers, and then we will connect our battery pack to the bottom rails to power the servos.

If we do this however it will mean the Arduino ground plane and the servo ground plane will not be connected to each other and this could potentially result in big problems. Unplug the Arduino from the USB cable, make sure the battery pack is not connected to the bread board and connect two male male jumper cables as shown in the diagram, one to the 5v in the Arduino, the other to the ground in the Arduino.

Then take a male male jumper cable and connect the ground from the top rail to the ground on the bottom rail as shown on the right hand side of the breadboard. This now ties in the Arduino ground to the battery ground which we will attach next.

Finally add the battery pack to the breadboard and we have finished the physical setup and will move onto programming the Arduino.

Step 11: Programming the Ardiuno

For anyone not familiar with loading up sketches to the Arduino I suggest taking the time to go through the tutorials here before continuing.

https://www.arduino.cc/en/Tutorial/HomePage

To review the connections in my setup

The potentiometers are plugged into A0, A1 and A2

The servos are plugged into ~9, ~10 and ~11

We will need these numbers when we write the code to get the Arduino working with our setup. Below is the code I used to get the Arduino working. It is not my code, I hacked out the parts I didn't need from someone else's code, unfortunately I can't remember where i found it so can't give credit to the person who wrote it. If you recognise it please let me know and I will put a link here to the person's project.

#include <Servo.h>

Servo myservo3;

Servo myservo5;

Servo myservo6;


int potpin = 0;
int potpin2 = 1;

int potpin3 = 2;

int val = 0;
int val2 = 0;

int val3 = 0;

void setup()
{

myservo3.attach(9);
myservo5.attach(10);

myservo6.attach(11);

}

void loop()
{

val = analogRead(potpin);
val = map(val, 3, 1023, 0, 176);

myservo3.write(val);

delay(25);

val2 = analogRead(potpin2);
val2 = map(val2, 3, 1023, 0, 176);

myservo5.write(val2);

delay(25);

val3 = analogRead(potpin3);
val3 = map(val3, 3, 1023, 0, 175);

myservo6.write(val3);

delay(25);

}

Paste this into a blank sketch, save it and upload it to your Arduino and you should now be able to control your servos with your potentiometers and be able to get on with your project!

Comments

author
Jos%C3%A9G285 made it!(author)2016-12-08

thanks for sharing. I have two questions:

1) why is it necessary/preferred to power the potentiometers with the arduino instead of with the battery pack?

2) is there a reason why you do not plug the servos' power and ground lines directly into the power rails of your breadboard?

author
break_it_fix_it made it!(author)2017-01-10

Hi there Jose, thanks for your questions.

1. I think that it would be OK to run the pots off the battery rail. I didn't do it for two reasons, the first reason was that I wanted to make sure my batteries would last as long as possible, and the second was I figured that there might be a bit of electrical noise that could make an issue with the signal (not sure on this though, just wanted to be on the safe side)

2. No real reason for this other than the fact that I use a 3 pin jack to connect my servos to the breadboard

author
NickS3 made it!(author)2017-01-10

this was awesome! I never get things to work the first time and this just fell together. i learned a lot. Thank you.

author
break_it_fix_it made it!(author)2017-01-10

My pleasure Nick, thanks for the positive feedback.

author
BlueDJ made it!(author)2016-10-16

when ever i plug in my servos in they ether don't work or start moving back and fourth randomly.

author
break_it_fix_it made it!(author)2016-10-18

I had this problem when I was trying to use a 9v square battery to power the circuit, nearly drove me daft until I changed it out for 4 AA batteries.

author
sylzys made it!(author)2016-09-02

Great, thanks!

Could you elaborate more on why it's mandatory to link Arduino and servos grounds together?

Thanks

author
break_it_fix_it made it!(author)2016-09-12

It's mostly for voltage stability and of course safety. If you don't link the ground you will notice the circuit behaving weirdly at odd times.

author
sylzys made it!(author)2016-09-12

Makes sens, thanks :)

author
NathanielA made it!(author)2016-08-28

Great tutorial. Is there any way I could operate the 3 servo motors wirelessly, maintaining the majority of your design? Thanks.

author
kishorearjith made it!(author)2016-05-04

hi sir i am just studying 8th standard. can any one help for servo motor blades. please reply

author
mustafahamza8 made it!(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 :) >>


author
mustafahamza8 made it!(author)2016-02-14

break_it_fix_itDiamondGuy99 thx very much the problem was in the servo bevusae it is continuous
i changed the servo and every thing work :)

author
break_it_fix_it made it!(author)2016-02-14

Awesome :) Thanks for building it!

author
DiamondGuy99 made it!(author)2016-02-10

I think you might have used a continuous rotation servo, Have you modded it for continuous rotation? I would go with the advice to try this setup with a different servo.

author
break_it_fix_it made it!(author)2016-02-05

That's unusual. Servo motors usually have a limited sweep of movement. Have you tried your setup with a different servo motor?

author
owatson made it!(author)2015-10-20

if you don't have an arduino you can use a servo tester for each servo.

author
tomatoskins made it!(author)2015-10-20

This is great! I love learning new ways to use an arduino!

About This Instructable

22,951views

281favorites

License:

More by break_it_fix_it:Simple 3 button controller for a 4 axis robot armCycle an RGB LED through the colour spectrum using a Raspberry Pi 2 and Scratch PWM based LED control using push buttons, Raspberry Pi 2 and Scratch
Add instructable to: