Hello. I'm using this code to control a 6-axis robot arm with 7 servos. I'm using the potentiometers to control the servos. However, the code just results in the arm jittering about, not responding to any of the potentiometers.
Don't be alarmed about the commented out stuff, just imagine they aren't commented out (I only commented them out to test, so just act like its not commented out - read the full code).
Can anyone fix this?
#include <Servo.h>
Servo servo1; // create servo object to control a servo
Servo servo2;
Servo servo3;
Servo servo4;
Servo servo5;
Servo servo6;
Servo servo7;
int potpin = A0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
int potpin2 = A1;
int val2;
int potpin3 = A2;
int val3;
int potpin4 = A3;
int val4;
int potpin5 = A4;
int val5;
int potpin6 = A5;
int val6;
void setup() {
servo1.attach(3); // attaches the servo on pin 9 to the servo object
servo2.attach(5);
servo3.attach(6);
servo4.attach(9);
servo5.attach(10);
servo6.attach(11);
servo7.attach(12);
}
void loop() {
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
servo1.write(val); // sets the servo position according to the scaled value
val2 = analogRead(potpin2); // reads the value of the potentiometer (value between 0 and 1023)
val2 = map(val2, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
servo2.write(val2); // sets the servo position according to the scaled value
servo3.write(val2);
val3 = analogRead(potpin3); // reads the value of the potentiometer (value between 0 and 1023)
val3 = map(val3, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
servo4.write(val3); // sets the servo position according to the scaled value
val4 = analogRead(potpin4); // reads the value of the potentiometer (value between 0 and 1023)
val4 = map(val4, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
servo5.write(val4); // sets the servo position according to the scaled value
val5 = analogRead(potpin5); // reads the value of the potentiometer (value between 0 and 1023)
val5 = map(val5, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
servo6.write(val5); // sets the servo position according to the scaled value
val6 = analogRead(potpin6); // reads the value of the potentiometer (value between 0 and 1023)
val6 = map(val6, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
servo7.write(val6); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
}
What do you mean by jitter around? They don't more at all or do they jitter when you don't control them?
Because I can't see anything wrong with the code. So if they don't move at all that leaves your hardware. You don't try to power the servo's all from the Arduino 5V are you?
And have you heart of arrays?
And have you heart of arrays?
And have you heart of arrays?
And have you heart of arrays?
And have you heart of arrays?
And have you heart of arrays?
(You'll get the joke when you have heart of them )
By jitter, I mean the arm just kind of moves around without any change to the potentiometers by the user.
I am using a 6v 4xAA battery pack to supply power to a breadboard rail. From this rail, the servos and the potentiometers are receiving power.
I think the problem might be originating from something with the delay, but I honestly have no idea tbh.
But if you move the potentiometers the arms move?
No, they arm just doesn't respond at all. It moves on its own.
Have you connected the GND of the batteries to the Arduino GND?
And also, 7 servo's for a couple of AA's can be a bit much. Try it with a single servo first.
The 4X AA pack has more than enough mAH to power all 7 servos. And yes, the grounds are connected.
Any other possibilities?
Just today I was messing around with a stepper motor, a4988 driver, and joystick. I was using one blown UNO for additional power and I was just getting noise and no control until I added a wire connecting the grounds, then it worked perfectly. I think septillion is right.
*I just seen you said the grounds are connected. Do you mean they are connected together, not two seperate grounds? I think thats what Septillion means. Kinda a noob myself so not 100% sure.
I have one wire from the pack to the breadboard, and then another wire from that ground breadboard lane to the Arduino. The grounds should be connected.
I think try more power options, because i think ive had a similar experience, I use a wallwart switchable supply for a test,
another thing is,, potentiometers are funny , because when you hook up 7 potentiometers, its literally 7 parallel resistors to ground. When i hooked up 3, i started to notice odd behavior, because changing one changes the others. Maybe theres more circuitry required to isolate the vcc to each potentiometer.. if you have an extra arduino, maybe you can program several pins to high constant, and the use that for the +5 source instead of the +5 pin. Did you try setting up a serial monitor of each val before map, to see of it reads appropriately when you turn the dials?? You might notice moving one changes the rest as well.
I am using a 6v 4xAA battery pack to supply power to a breadboard rail. From this rail, the servos and the potentiometers are receiving power.
That's going to put 7V on the wiper into an analog pin at one end of the travel.
The 4X AA pack has more than enough mAH to power all 7 servos.
mAh has nothing to do with it, that's capacity not current. You don't say what servos you have, but rule of thumb is 1A each, so are you really sure you can provide 7A if they all move at once? That's substantial.
wirenoob:
I have one wire from the pack to the breadboard, and then another wire from that ground breadboard lane to the Arduino. The grounds should be connected.
Check the blue and red printed lines along the breadboard that the rails aren't interrupted in the middle. Some are, some aren't. Is it possible you have grounds on either side of a break?
I bought a kit with a breadboard that doesn't LOOK like the power rails are broken, and there are a few breaks, I had to use a continuity check to discover it was at least 3 separate rails along the line.
manor_royal:
Check the blue and red printed lines along the breadboard that the rails aren't interrupted in the middle. Some are, some aren't. Is it possible you have grounds on either side of a break?
wirenoob:
The 4X AA pack has more than enough mAH to power all 7 servos. And yes, the grounds are connected.
You could also be less stubborn and just disconnect 6 servo's...
And indeed, 4 x Alkaline is to high for the pots. It's even pretty damn high for a servo as well. But connect the pots just to the 5V of the Arduino. What is the rating for the pots?
tsmspace:
Maybe theres more circuitry required to isolate the vcc to each potentiometer..
No, not really. If the pot has a high enough resistance (let's say 10k+) it should not be a problem. If they are and you still have cross talk, you're supply is a to big piece of crap...
Hi,
Its time...
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Not a fritzy picture,
If your servos are the joints of a robot arm, they will be under continuous load, this means the servo motors will be drawing continuous current.
Servos, even small ones can pull up to an AMP when under load.
Do you have a DMM, what is the voltage of your battery pack when the fault occurs?
Can you UNPLUG ALL but one servo, and see if you can control it.
Then check each servo the same way on its own.
Also a link to spec/data of the servo would help.
Thanks.. Tom...
I know it sounds a lot of things to do, but you are in fault finding mode now, and there are lots of things to go wrong.
(I know its my job..)
septillion:
You could also be less stubborn and just disconnect 6 servo's...
And indeed, 4 x Alkaline is to high for the pots. It's even pretty damn high for a servo as well. But connect the pots just to the 5V of the Arduino. What is the rating for the pots?
No, not really. If the pot has a high enough resistance (let's say 10k+) it should not be a problem. If they are and you still have cross talk, you're supply is a to big piece of crap...
It wasn't that I was being stubborn with that post, its just that the 4x AA is the only power supply I have atm, and I wasn't with my robot arm at the time, so I couldn't test.
Each pot has a 10k resistance rating.
TomGeorge:
Hi,
Its time...
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Not a fritzy picture,
If your servos are the joints of a robot arm, they will be under continuous load, this means the servo motors will be drawing continuous current.
Servos, even small ones can pull up to an AMP when under load.
Do you have a DMM, what is the voltage of your battery pack when the fault occurs?
Can you UNPLUG ALL but one servo, and see if you can control it.
Then check each servo the same way on its own.
Also a link to spec/data of the servo would help.
Thanks.. Tom...
I know it sounds a lot of things to do, but you are in fault finding mode now, and there are lots of things to go wrong.
(I know its my job..)
I will try to draw up a CAD drawing as soon as possible.
As for the servos, 5 are towerpro mg996rs, and 2 of them are towerpro sg90s (minis). Datasheet for the large ones can be found here: link. Sg90 here: link.
... and it says right there in that linked datasheet, that one of those large servos draws 2.5A at stall, way more than the usual rule of thumb of 1A.
So if you're trying to move them all together, and you may well be with no delay() between the moves, you're up in the region of 20A. (Edit: ok, 15, but still....)
wirenoob:
Each pot has a 10k resistance rating.
That's as may be, but if you put 7V across it and take the wiper to the +ve end, that's putting 7V on the wiper into your 5V analog pin.
manor_royal:
... and it says right there in that linked datasheet, that one of those large servos draws 2.5A at stall, way more than the usual rule of thumb of 1A.
So if you're trying to move them all together, and you may well be with no delay() between the moves, you're up in the region of 20A. (Edit: ok, 15, but still....)
This robot arm is a replica of one I found online. He used slightly different servos, but relatively the same draw. He was able to use 4x AA and it worked fine, so battery supply I don't think should be the problem.
Would I be able to post a video of the robot arm and my setup?