I am doing a project where six servos are connected to an arduino uno. All the servos work, and can be controlled individually.
But, when I try to activate all of them at once:
// ServoControl.ino //
#include <Servo.h>
Servo s1, s2, s3, s4, s5, s6, currentServo;
String inString = "";
void setup()
{
s1.attach(2);
s2.attach(3);
s3.attach(4);
s4.attach(5);
s5.attach(6);
s6.attach(7);
Serial.begin(9600);
}
void loop() {
while (Serial.available() > 0) {
int inChar = Serial.read();
// The letters a-f corresponds to servos 1-6.
switch (inChar){
case 'a':
currentServo = s1;
break;
case 'b':
currentServo = s2;
break;
case 'c':
currentServo = s3;
break;
case 'd':
currentServo = s4;
break;
case 'e':
currentServo = s5;
break;
case 'f':
currentServo = s6;
}
// Digits form a number 0-180.
if (isDigit(inChar)) {
inString += (char)inChar;
}
if (inChar == '\n') {
currentServo.write(inString.toInt());
inString = "";
}
}
}
The s2 servo stops working. All the other works perfectly, they receive input such as "a100" which sets the first servo to 100, etc. Any input that starts with b, like "b150" does nothing.
Five of the servos are Hitec HS-422 servos and the last one is a TowerPro MG995. It's the TowerPro that stops reacting when they're all connected.
Each servo is connected to a PWM pin, and then there is also connection to the 5V and Gnd, as in the image below:
The external power source is connected to a wall outlet, 7.5V. But I don't even know if it's using that power source, or if it's powering through the USB connection to the computer?
No, it should power through the external power supply. But I can't figure out what's wrong and one theory I have is that there's a lack of power... Could that be a reason for one of the servos to not respond while the other five works? I'm running out of ideas.
You have the Arduino powered from an external supply it seems, but it's not clear how the servos are powered. Are they plugged into the Arduino 5V, I can't see on the pic. The Arduino can't supply enough current through that 5V supply.
Give us a decent diagram that actually shows the servo wires over their whole length from servo to their power.
You need to knock that 7.5V down to 5-6 and take it direct to the servos, like in my pic.
Whenever you have two of more identical things and one isn't working you
can swap them around to see if its the thing that's broken or whether the
fault belongs to the pin(s) that's controlling it
Jimbo: Ok, I will supply more details later (have to check the robot to be sure, and it's not here.)
MarkT: If you swap the pins around, it doesn't matter. It's still the same servo that doesn't move. But the servo itself works fine, if you run it in a program of its own, it performs as expected.
So the fault is not in the pin, and it's not in the servo. That's what's so confusing.
VicE:
Jimbo: Ok, I will supply more details later (have to check the robot to be sure, and it's not here.)
MarkT: If you swap the pins around, it doesn't matter. It's still the same servo that doesn't move. But the servo itself works fine, if you run it in a program of its own, it performs as expected.
So the fault is not in the pin, and it's not in the servo. That's what's so confusing.
That suggests the power is drooping and that servo drops out first, thus
rescuing the others from the same fate. It may be pulling more current due
to more friction (these things are cheaply made), thus it gets even less voltage.
More power or more electrolytic decouping on the servo power may make
a difference. If you can phase the servos so they don't all try and start moving
simultaneously that could reduce peak current demand.
I just wanted to post the resolution, for all you guys who read and tried to help. Thx.
It turned out the arduino ran all servos on the USB-connection and not on the external power supply. As I suspected, but everything was properly set up! Nothing wrong with the cables or the code.
So what was wrong? Take a look:
Yes, it's the cord that's connected to the arduino uno from the external power supply. And yes, it can be attached in two different ways. And no, I didn't know about this. And yes, it was attached the wrong way thus not supplying any power at all!
On the bright side, everything's working fine now.
And yes, it can be attached in two different ways. And no, I didn't know about this. And yes, it was attached the wrong way thus not supplying any power at all!
Yes, that's like the Radioshack Universal Power Supplies that allow you to plug the connector in either POLARITY. The diode on the
arduino Ext . Pwr Barreljack circuit prevented the negative voltage from damaging the 5V regulator.
I'm sure you'll measure the voltage first next time you use one of those.