servo is not behaving

Hi, I am working on a robotic arm, but the servos seem to be acting weirdly, they keep sweeping when I give them commands via a potentiometer.

I am using a clone Arduino Uno.
I expected the servos to run smoothly when I turned the potentiometers

here is my code:

#include <Servo.h>

Servo base;
Servo elbow;
Servo wrist;
Servo hand;
Servo claw;

int basepot = A1;
int elbowpot = A4;
int wristpot = A2;
int handpot = A5;
int clawpot = A3;

int valbase;
int valelbow;
int valwrist;
int valhand;
int valclaw;

void setup(){
base.attach(3);
elbow.attach(5);
wrist.attach(6);
hand.attach(10);
claw.attach(9);
}

void loop(){
valbase = analogRead(basepot);
valbase = map(valbase,0,1023,0,180);
base.write(valbase);
delay(10);

valelbow = analogRead(elbowpot);
valelbow = map(valelbow,0,1023,0,180);
elbow.write(valelbow);
delay(10);

valwrist = analogRead(wristpot);
valwrist = map(valwrist,0,1023,0,180);
wrist.write(valwrist);
delay(10);

valhand = analogRead(handpot);
valhand = map(valhand,0,1023,0,180);
hand.write(valhand);
delay(10);

valclaw = analogRead(clawpot);
valclaw = map(valclaw,0,1023,0,180);
claw.write(valclaw);
delay(10);
}
[code/]

Several suggestions:

  • Go read the 'How to use this forum - please read.' post
  • Note how it goes over using code tags when posting code
  • go back and edit your original post to use those code tags
  • consider using CTRL-T to autoformat your code. Improves readability.
  • Post a wiring diagram. A picture of a hand drawn diagram is find so long as it identifies relevant detail.

Edit 1: Poorly behaving servos are often the result of power problems or ground problems. The wiring diagram will help us identify those and offers suggestions if they are present. Edit 2: I do not like the use of delay() unless it is needed for some real world event like serial initialization. What are you expecting from your use of delay()?

i have wired the servos to 8, 1.5 volt batteries. But the issue is still there.

Did you miss the part about posting a schematic? Did you miss the part about adding code tags to your original post? Folks around here don't like being ignored. It will cause the help you need to dry up really fast.

Also give us specs on the servos please.

First thing I'd do is disconnect all servos but one.

Then I'd write some known constants out to it to see that it behaves as I would expect:

base.write(0);
delay(1000);
base.write(90);
delay(1000);
base.write(180);
delay(1000);

Next thing, is I'd print valbase to see if the value is reasonable.

If the value is reasonable but it jitters, then I'd add a software low-pass filter.

Then I'd add some stuff to only write to the servo if the value has changed since the last time I wrote it out.

Then I'd add some stuff to only write to the servo if the value has changed and if it's at least (say) 100 ms since I last wrote a value out.

vinceherman: Also give us specs on the servos please.

I bought my servo off amazon, but they dont give any specs or datasheet

Budget 1 Ampere per servo, and power the servos separately from the Arduino.

SlimyCheese: I bought my servo off amazon, but they dont give any specs or datasheet

Does it have a brand name? Model information?

Are you working on a wiring diagram like we asked for in reply #1 and again in reply #3?

We really are trying to help you but we need information from you.

Sorry for the late reply, Here is my wiring diagram you asked for,

SlimyCheese:
i have wired the servos to 8, 1.5 volt batteries. But the issue is still there.

Your servos are connected to the arduino 5V pin. Your arduino cant handle that much. Try disconnecting all but one, like someone already said, and see if it works. If so, then its a power problem.

johnfg: Your servos are connected to the arduino 5V pin. Your arduino cant handle that much. Try disconnecting all but one, like someone already said, and see if it works. If so, then its a power problem.

My servos are not wired to the arduino, I have 8, 1.5 volt batterys externaly powering the servos. Only the potentiometers are wired to arduino.

Have tried what PaulMurrayCbr said? It could be many things.

If you have the link of the servo you bought, it would be nice. Maybe there is some information there.

Do these things and then tell us if it works or not.

In the schematic it looked like the servos were connected to the arduino. Make sure all the wiring is correct, especially with the batteries.

Edit: In the schematic you didnt include the batteries. Use a voltimeter and make sure they supply the correct voltage (dont use a amperemeter or you'll create a short circuit).

Is it just me? I cannot see the attachment in reply 9.

SlimyCheese, you have not told us which servos you have.

vinceherman:
Is it just me? I cannot see the attachment in reply 9.

SlimyCheese, you have not told us which servos you have.

I have put a attachment in reply 9. here it is again.

Awesome. I can see the image on that one. No idea why I could not on reply 9. Still no info from you on the brand and model of your servos. The pic shows you powering the servos from a 9v transistor battery. These are mostly useless for powering anything other than a transistor radio. You can expect a large voltage drop once you try to pull the amount of current 5 servos are going to draw. You had mentioned earlier that you had 8 1.5v batteries. My math says that is 12v.

What servos do you have. How are you powering them? 8 1.5v batteries? What kind of batteries? Do you have the ground from the arduino connected to the ground from the servos? (hint, the pic does not show this)

I have written code to move the servo, no servos move now

#include <Servo.h>

Servo TestServo;

void setup() {
  // put your setup code here, to run once:
TestServo.attach(3);
}

void loop() {
  // put your main code here, to run repeatedly:
TestServo.write(0);
delay(1000);
TestServo.write(10);
delay(1000);
TestServo.write(20);
delay(1000);
TestServo.write(30);
delay(1000);
TestServo.write(90);
delay(1000);
TestServo.write(120);
delay(1000);
TestServo.write(180);
}

You have been asked multiple times for information that only you know. You have been VERY unwilling to provide answers.

What servos do you have. How are you powering them? 8 1.5v batteries? What kind of batteries? Do you have the ground from the arduino connected to the ground from the servos? (hint, the pic does not show this)

SlimyCheese: I have written code to move the servo, no servos move now

Sorry to hear that. Maybe the servos you won't tell us about don't work with the batteries that you won't tell us about or the connections are wrong because that code is fine.

I suppose you do realise that you have to load the code into the Arduino, just writing it isn't enough?

Steve

Here is the link to the amazon product https://www.amazon.com/gp/product/B007R9TS3C/ref=oh_aui_detailpage_o00_s00?ie=UTF8&psc=1

vinceherman: You have been asked multiple times for information that only you know. You have been VERY unwilling to provide answers.

What servos do you have. How are you powering them? 8 1.5v batteries? What kind of batteries? Do you have the ground from the arduino connected to the ground from the servos? (hint, the pic does not show this)

sorry about not providing information, I have dont use the forum very often.

no, the Arduino does not have a common ground with the servos,I am powering the servos with 8 1.5 volt energizer nonrechargable batteries.