Servo Operations

Hello, I am a new guy to the forum. I need some help with my code. I am trying to run 5 servo motors and need to move them using kinematics. I am currently testing their movement. i wrote a simple program as below but its not working as it should.

Setup: using a separate power supply with common ground to arduino for running the motors. as i turn on the arduino, the motors start moving randomly. i had the mechanism the way i wanted with the motor angles as needed but the motor starts moving randomly. any help is appreciated.

include <Servo.h>

Servo thumb;
Servo index;
Servo middle;
Servo ring;
Servo pinky;
Servo wrist;
Servo elbow;
Servo armrot;
Servo shoulderrot;
Servo handlift;
int count = 0;
// pos = Thumb, index, midf, ringf, pinky, wrist, elbow, arm_rot, shoulder_rot, hand_lift

int posopen[] = {170, 25, 30, 30, 30, 15, 135, 120, 160, 55};
int posclose[] = {85, 125, 135, 105, 110, 180, 45, 70, 30, 10};
//int pinArray[] = {2, 3, 4, 5, 10, 11};
//int pos = 90;
//int count = 0;

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
thumb.attach(2);
index.attach(3);
middle.attach(4);
ring.attach(5);
pinky.attach(6);
wrist.attach(7);
elbow.attach(8);
armrot.attach(9);
shoulderrot.attach(10);
handlift.attach(11);
delay(10000);
thumb.write(posopen[0]);
index.write(posopen[1]);
middle.write(posopen[2]);
ring.write(posopen[3]);
pinky.write(posopen[4]);
wrist.write(posopen[5]);
armrot.write(posclose[7]);
shoulderrot.write(posclose[8]);
handlift.write(posclose[9]);
delay(10000);
}

void loop() {
// put your main code here, to run repeatedly:
thumb.write(posclose[0]);
index.write(posclose[1]);
middle.write(posclose[2]);
ring.write(posclose[3]);
pinky.write(posclose[4]);
wrist.write(posclose[5]);
elbow.write(posclose[6]);
delay(2000);
armrot.write(posclose[7]);
delay(10000);
shoulderrot.write(posclose[8]);
delay(10000);
handlift.write(posclose[9]);
delay(10000);

thumb.write(posopen[0]);
index.write(posopen[1]);
middle.write(posopen[2]);
ring.write(posopen[3]);
pinky.write(posopen[4]);
wrist.write(posopen[5]);
delay(2000);
elbow.write(posopen[6]);
delay(10000);
armrot.write(posopen[7]);
delay(10000);
shoulderrot.write(posopen[8]);
delay(10000);
handlift.write(posopen[9]);
delay(10000);

}

In the Arduino IDE, use Ctrl T or CMD T to format your code then copy the complete sketch.

Use the </> icon from the ‘reply menu’ to attach the copied sketch.


Show us a good schematic of your circuit.
Show us a good image of your ‘actual’ wiring.
Give links to components.

You know it's possible to have arrays of Servo objects?

How are the servos powered?
All with solid ground connections?

Please remember to use code tags when posting code

Hello Thanks. for the answers. I have a Power rail coming from the main PSU its 6 AMP. I have the ground of arduino mega and the PSU connected together. Max I can pull from PSU is 3 AMPS because, i blew the fuse. Sorry for the code tags, I did not know but i hope i have rectified the mistake. The motors are high torque HS805B, thats why the delay of 10 seconds in between. i tested the motors separately using example codes form the ide, it does not jump but with this software it jumps around randomely specially the high torque motors. elbow, armrot, shoulderrot and handlift are high torque and hand lift motor starts moving as i turn on the arduino.

Yes Shanon I know. but this is for just testing purposes. so a rag tag software.

# include <Servo.h>
Servo thumb;
Servo index;
Servo middle;
Servo ring;
Servo pinky;
Servo wrist;
Servo elbow;
Servo armrot;
Servo shoulderrot;
Servo handlift;
int count = 0;
// pos =          Thumb, index, midf, ringf, pinky, wrist, elbow, arm_rot, shoulder_rot, hand_lift

int posopen[] =   {170,   25,    30,   30,    30,    15,    135,    120,    160,         55};
int posclose[] =  {85,   125,   135,  105,   110,   180,    45,      70,     30,         10};
//int pinArray[] = {2, 3, 4, 5, 10, 11};
//int pos = 90;
//int count = 0;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  thumb.attach(2);
  index.attach(3);
  middle.attach(4);
  ring.attach(5);
  pinky.attach(6);
  wrist.attach(7);
  elbow.attach(8);
  armrot.attach(9);
  shoulderrot.attach(10);
  handlift.attach(11);
  delay(10000);
  thumb.write(posopen[0]);
  index.write(posopen[1]);
  middle.write(posopen[2]);
  ring.write(posopen[3]);
  pinky.write(posopen[4]);
  wrist.write(posopen[5]);
  armrot.write(posclose[7]);
  shoulderrot.write(posclose[8]);
  handlift.write(posclose[9]);
  delay(10000);
}

void loop() {
  // put your main code here, to run repeatedly:
  thumb.write(posclose[0]);
  index.write(posclose[1]);
  middle.write(posclose[2]);
  ring.write(posclose[3]);
  pinky.write(posclose[4]);
  wrist.write(posclose[5]);
  elbow.write(posclose[6]);
  delay(2000);
  armrot.write(posclose[7]);
  delay(10000);
  shoulderrot.write(posclose[8]);
  delay(10000);
  handlift.write(posclose[9]);
  delay(10000);

  thumb.write(posopen[0]);
  index.write(posopen[1]);
  middle.write(posopen[2]);
  ring.write(posopen[3]);
  pinky.write(posopen[4]);
  wrist.write(posopen[5]);
  delay(2000);
  elbow.write(posopen[6]);
  delay(10000);
  armrot.write(posopen[7]);
  delay(1000

It sounds like your power supply is inadequate.

well i ran individual motors and they work perfectly with the example code sweep. no problem but with this particular code, it goes bonkers.

Indeed, it sounds like your PSU can manage a single servo, but not six. Maybe try two.

Or 9 or 10

1 Like

i am running 1 servo at a time. plus today i increased the psu ratings by using a battery. now it can handle 12 Amps. plenty of current. but still its the same proble. i checked the circuits there is no short or any signal leakage also grounding resistors across signal to pull it down to zero when no signal. but still same issue. this issue is only for hand_lift motor

Servo issues are almost always power related, especially jitter like this.

You may have enough power at the source, but perhaps your wiring isn't up to passing that much current. Is there a breadboard involved?

You are attaching 10 servos within a span of a few milli seconds, how much current is required from your power supply for 10 servos to jump from wherever they are to the default 90° at the same time?

Also you would do well to do the initial positioning write()s to the servos in setup() BEFORE doing the attach()s. The saves them jumping to the default 90 and then instantly having to move to the position you actually wanted.

BTW 12A is not a lot for 10 servos with a stall current of up to 6A each.

Steve

no i have a circuit with thick traces. that is not the issue. i made a program on python using pyfirmata, worked like a dream... no problem whatso ever. but with arduino its screwing up. now i am a 100% sure, its the code...

So time to scrap the

?

this seems like a solution. but i have a question that how can i activate motors before attaching the motors to their designated pins.

no i need arduino to do the low level work. i am planning to solve all my kinematic and computervision in python and sending an array for servos. btw how can i send an array via serial. i found pyfirmata. but is there any other way..

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.