Question About two oposite Servo On Arduino Mega 2560

Hello Guys.

Im here just to hear if you guys have a solution for im about to tell.

So, first things first. Im developing a robot claw arm and im facing some troubles with the first joint linked to the base, cause there i got two servos to raise up his arm and i they are oppositely positioned, so when you servo is on 40 degree, the another one is on 140 degree. If i just put this code:

servo1.write(40);
servo2.write(140);
delay(2000);
servo1.write(140);
servo2.write(40);
delay(2000);
servo1.write(40);
servo2.write(140);

it works, but i need a slow and fluid movement cause i dont want to break one more servo because of too much strenght when getting back to the initial position.

So i'd like to ask you guys if you guys have anothe code that can tell me to a slow and fluid movemente for this two servos simultaneosly and oppositionally.

Thank you .

Drive one servo with angle "x" from 40 to 140, and drive the other with 180 - x.

I've already tryed to use this code, but didn't work. One servo keeps moving and the other one stay stopped.

I've already tryed to use this code,

I can't see any code.

First find (byte experiment) the wanted ranges of movement in terms of angles to write() calls
for each servo.

Lets say for example servo1 goes from 20 to 160 degrees, servo2 goes from 25 to 170 degrees
(variations in cheap servos aren't surprizing).

Then:

  for (int i = 20 ; i <= 160 ; i++) 
  {
    servo1.write (i) ;
    servo2.write (map (i, 20, 160, 170, 25)) ;
    delay (20) ;
  }

Will sweep servo1 from 20 to 160 while sweeping servo2 from 170 to 25....

I see...thank you MarkT i will try this another time but now im facin another problem that is power supply. As im using 5 servos, when i turn on all the 5 together, they dont have enough strenght to raise up the robot arm. I was using an atx pc power supply 500Watts, using the 5V wire only for the servos. Im feeding the arduino with another supply. What do you suggest to correct this problem ? thank you

Even if you allow 1 amp per servo, that's only 25 watts total, which shouldn't trouble your supply.
Is your supply wiring heavy enough?

What type of servos are they ? Please provide a link. How heavy is the arm and how is it constructed ?

I am using 4 servos like these: TowerPro MG995 Servo Specifications and Reviews
1 servo like this for the claw: TowerPro SG90 Servo Specifications and Reviews (but this one i dont have any problems, the problem is with the 4 ones.)

Im going to send you guys a picture of my project. Im using acrylic for the joints and claw and for the base, i used wood.

Like i said guys, when i was testing one servo raising up one joint it was perfect. when i put all the joints and servos together, they dont have enough power to raise up and stays vibrating.

How are the servos coupled to the arm and how large is the arm ?
I note that there appear to be no bearings used to reduce friction between the parts of the arm

I was using an atx pc power supply 500Watts, using the 5V wire only for the servos.

I assume that you have also connected the GND from the power supply to Arduino GND, or have you ?

Yes i did...i did a common point for the arduino and sevos. all the gnd's are connected to the prot-o-board. but im feeding the arduino with a different power supply. an ac/dc 9V router supply at the arduino Jack.

but im feeding the arduino with a different power supply.

Are you (still) expecting the Arduino to supply enough current to power the servos? If so, that is NOT going to happen. You need to power the servos independently.

im sending you the photos with the final structure of the project. And no, dont have any bearings its directly on the arm. Only have bearings on the base to move left and right.

Well...if its not obvious, i dont have the servos attached on these photos, just sent to understand better the final structure of the arm.

Using invisible servos, I see. Or, don't see.

PaulS:
Are you (still) expecting the Arduino to supply enough current to power the servos? If so, that is NOT going to happen. You need to power the servos independently.

i dont know if you have read the other replys. I said before that im feeding the servos with an atx pc power supply 500Watts, using the 5V output AND the arduino im feeding with a DIFFERENT power supply INDEPENDENTLY. Seriously, you are here to help or to criticize ? Im here to learn and im just asking you this cause we dont know everything.

I said before that im feeding the servos with an atx pc power supply 500Watts, using the 5V output AND the arduino im feeding with a DIFFERENT power supply INDEPENDENTLY.

Have you posted a schematic that I missed?

No i didnt, but i do told that i was feeding the servos with the atx. And some replys later, right before your reply i told that i was feeding the arduino with a different power supply. i thought that was enough, im sorry if its not.

But ok...nvm that i just want to solve this. Can you imagine what im doing wrong only with those informations ?

Can you imagine what im doing wrong only with those informations ?

Without even seeing what the servos are doing? No. If one servo by itself works properly, but activating more than one servo causes the one that was working perfectly to misbehave, then the power supply is not adequate.

ThatS what I though. I will try to reduce the weight of the arm by Makin some holes on the structure. And try to feed each servo with independently power supplies.

Can you please post a 'photo with the servos attached to the arm.