10816Views8Replies

Author Options:

Controlling servo direction with arduino Answered

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?

8 Replies

user
steveastroukBest Answer (author)2010-12-19

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

Select as Best AnswerUndo Best Answer

user
jeff-o (author)2010-01-14

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.

Select as Best AnswerUndo Best Answer

user
lemonie (author)jeff-o2010-01-14

Give this man a "Best Answer"!

L

Select as Best AnswerUndo Best Answer

user
echovoice (author)lemonie2010-02-10

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

Select as Best AnswerUndo Best Answer

user
lemonie (author)echovoice2010-02-10

You can switch the wires, there's a motor inside them. That's about as much as I know though.

L

Select as Best AnswerUndo Best Answer

user
echovoice (author)lemonie2010-02-11

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


Select as Best AnswerUndo Best Answer

user
0xCyrusx0 (author)2010-01-14

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?

Select as Best AnswerUndo Best Answer

user
gmxx (author)0xCyrusx02010-01-15

 can you post your .pde file? 

Select as Best AnswerUndo Best Answer