Controlling servo direction with arduino

So, I'm trying to control two servo motors for a robotic arm. I can't seem to figure out how to make two servos go opposite directions at the same time. This is needed as I have two servos facing opposite directions driving the same beam (If they're told to go the same direction, because they are facing opposite directions, they'll rotate opposite directions).

Currently I'm using this code to rotate them both:

for(pos = 0; pos < 180; pos += 1) 
  {                               
    myservo.write(pos);             
    delay(15);                     
  }

and then using the same code, only replacing the top part with

  for(pos = 180; pos>=1; pos-=1)

to return to the original position.

How do I make both servos go opposite directions though, so they can both be used to lift a beam at the same time?


sort by: active | newest | oldest
You need to do the program as a subroutine.

Drive one side with Position, call the subroutine.
Drive the other side with (180-Position), call the subroutine.

If you open the servo up, and reverse the connection to the motor AND reverse the connections of the end of the pot, the servo will be "reversed".

Reversing the supply will not work and might destroy the servo

Steve
jeff-o7 years ago
If they always go in opposite directions, and they always operate at the same time, then you can hook them both up to the same driver in opposite directions (ie. switch the positive and negative on one of them).  That way, you only need to control "one" servo.
lemonie jeff-o7 years ago
Give this man a "Best Answer"!

L
um is that a best answer? i didn't think you could just switch the positive and negative wires on a servo....

how about this: 

www.tigoe.net/pcomp/code/category/arduinowiring/31
You can switch the wires, there's a motor inside them. That's about as much as I know though.

L
this guy reversed the connections on the inside, and switched the connections to the pot... 

 

all i am doing is using opposite angles with the arduino servo controls and it works fine


0xCyrusx0 (author) 7 years ago
Forgot to mention I already tried this. Servos with power wires reversed shuts down my arduino, or I would have already done this.

Anyone here know how to do this?
gmxx 0xCyrusx07 years ago
 can you post your .pde file?