Go Down

Topic: servo is not behaving (Read 891 times) previous topic - next topic

SlimyCheese

Jun 19, 2017, 07:23 pm Last Edit: Jun 20, 2017, 03:01 am by SlimyCheese
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:

Code: [Select]

#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/]

vinceherman

#1
Jun 19, 2017, 07:59 pm Last Edit: Jun 20, 2017, 12:01 pm by vinceherman
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()?

SlimyCheese

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

Delta_G

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.
If at first you don't succeed, up - home - sudo - enter.

vinceherman

Also give us specs on the servos please.

PaulMurrayCbr

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:

Code: [Select]

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.

http://paulmurraycbr.github.io/ArduinoTheOOWay.html

SlimyCheese

Also give us specs on the servos please.
I bought my servo off amazon, but they dont give any specs or datasheet

jremington

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

vinceherman

#8
Jun 20, 2017, 05:57 pm Last Edit: Jun 20, 2017, 05:59 pm by vinceherman
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.

SlimyCheese

#9
Jun 21, 2017, 12:53 am Last Edit: Jun 21, 2017, 01:15 am by SlimyCheese Reason: fix image
Sorry for the late reply, Here is my wiring diagram you asked for,



johnfg

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.

SlimyCheese

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.

johnfg

#12
Jun 21, 2017, 01:17 am Last Edit: Jun 21, 2017, 01:27 am by johnfg Reason: Forgot something
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).

vinceherman

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

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

SlimyCheese

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.

Go Up