Using the Arduino Uno to control multiple Servos via potentiometers

Hello, I am trying to control 2 different projects (robotic arms) with multiple potentiometers that correlate to multiple servos. For example potentiometer 1 controls servo 1, and so on.

The problem I am encountering is that the servos will move wildly almost on their own.

Project 1 uses 4x servos, MG90s. This uses an Arduino Uno Rev 3

Project 2 uses 6x servos, 4x are HS-645MG, 1x is HS-225HG, and 1x HS-805BB. This uses an Arduino Uno Rev 3

For Project 1, I have tried using just the Arduino itself to power the servos as well as an external power supply. For the power coming from the Arduino, only 1 potentiometer is being turned at a time. When I hook up the external is when the arm behaves erratically. Yes there is a common ground attached.

I have been able to control a single potentiometer without issue (Project 5 in the starter kit as well as a 60Kg one)

Project 2 has to use the external power supply and behaves the same way as Project 1.

I have tried 2 variations of the code, both achieving the same results. Should I use something other than the Uno?

Thank you

#include <Servo.h>

Servo myServo0;
Servo myServo1;
Servo myServo2;
Servo myServo3;
Servo myServo4;
Servo myServo5;

int potPin0 = A0;
int potPin1 = A1;
int potPin2 = A2;
int potPin3 = A3;
int potPin4 = A4;
int potPin5 = A5;
int potVal0;
int potVal1;
int potVal2;
int potVal3;
int potVal4;
int potVal5;

void setup() {
myServo0.attach(3);
myServo1.attach(5);
myServo2.attach(6);
myServo3.attach(9);
myServo4.attach(10);
myServo5.attach(11);
}

void loop() {
potVal0 = analogRead(potPin0);
potVal0 = map(potVal0, 0, 1023, 0, 180);
myServo0.write(potVal0);
delay(15);

potVal1 = analogRead(potPin1);
potVal1 = map(potVal1, 0, 1023, 0, 180);
myServo1.write(potVal1);
delay(15);

potVal2 = analogRead(potPin2);
potVal2 = map(potVal2, 0, 1023, 0, 180);
myServo2.write(potVal2);
delay(15);

potVal3 = analogRead(potPin3);
potVal3 = map(potVal3, 0, 1023, 0, 180);
myServo3.write(potVal3);
delay(15);

potVal4 = analogRead(potPin4);
potVal4 = map(potVal4, 0, 1023, 0, 180);
myServo4.write(potVal4);
delay(15);

potVal5 = analogRead(potPin5);
potVal5 = map(potVal5, 0, 1023, 0, 180);
myServo5.write(potVal5);
delay(15);
}

Add some serial prints to look at the analog values both with and without using the external power supply. What voltage is the power supply? How is the Arduino being powered?

Welcome to the forum!

Please use code tags next time.

It sounds like the Arduino is not reading the pots and giving a floating input, causing the servos to go nuts.

Also, get rid of those delay() functions. You don't need them and it makes it hard to debug your program.

Also, a wiring diagram or picture of actual wiring would be helpful.

Arduinos should not power servos. Using the external the Arduino GND and external power supply GND must be connected to each other.
If this doesn't fix the error, please post schematics, not any Fritzing.

Power issue,

Power Issue.

Take an image of your project and post it so we can see what's going on with the project, wiring, breadboard , and the like.

Have you tested each of the 6 servos to make sure it can freely move from 0 to 180 degrees? If you have 6 assorted servos that ALL do 0 to 180, you should be playing the lotteries more.

Yes I only added 3 servos, but hopefully it should illustrate my setup

Yes, all servos have been tested and all 10 across both projects travel 0 to 180 degrees

You need to connect the servo power pin directly to the power supply. That breadboard will be damaged, toast, supplying all that current to the servos.

1 Like

Yes, I am aware not to use a breadboard. I left it in the schematic to show the connections that are being made

Could you post an image of your project?

Absolutely. This is the 6 servo setup. Yes I was using a breadboard to test but it will not be permanently used

Good. Just for telling, Fritzings are not accepted as schematics here. Lots of facts, details, are missing. Schematics are precise, exact but Fritzings are "something close to this, almost like this".

Looking for the reason for servos running wildly....
How many servos are connected?
Do all of them run wildly?
Have You tried having only one servo connected?

More suggestions.
Use Serial Monitor and Serial.print of the values read from the pot(s).

Thank you, I will give that a shot when I get back in tomorrow. I have gone home for the day

A breadboard simply cannot supply the current to the servos. Even for testing.

1 Like

Why so much code?
:open_mouth:

Ok, I really am that dumb. I re assembled everything, took the breadboard out of the equation, and used terminal blocks for the servos, left the potentiometers on the breadboard, and no problems. Thank you everyone for your help

For future reference, these are available in numbers for a little more than the cost of the pots on your board.