Controling of two servo motors :
 when we work on Servo ,in most of the cases a challenge comes 
with arduino that how to work on
two different servo motors  simultaneously in opposite direction rotations . I have used one  solution .now
available here .
in servo motor we use gears and DC motor . if we think in deep then dc
motor is capable to work on CW and CCW directions .   following are the steps which I have used .:
·        
from two servo choose any one and open it  from back side with the help of screw driver .
·        
change the motor wire with each other ( 1st  wire  will replace 2nd wire and 2nd will replace 1st )
·        
now change  the 1st and 3rd pin
connection  of servo potentiometer with
each other ,if you want to change it .

This is the direct solution
to operate both servos in opposite directions on single time .
interfacing with arduino :
make any one GPIO pin as output for arduino .
·        
let suppose we are taking pin no 4  .as motors output .
·         connect both servo signal pins on
pin no. 4  ,Vcc,ground   on 5v and ground 
Test Code :
you can use normal servo sweep example to check the output (from example
lib.).
Code:
#include 
Servo myservo;  
int pos = 0;    // variable to store
the servo position
void setup()
 {
  myservo.attach(4);  // attaches the servo on pin 9 to the servo
 }
void loop() {
  for (pos = 0; pos <= 90; pos +=
1)
 { 
myservo.write(pos);            
    delay(15);                    
  }
  for (pos = 90; pos >= 0; pos -=
1)
{     myservo.write(pos);                
 delay(15);      
          }
}
Video Link:
in given video speed of servos is different because both the servos are of different configuration.

You can use below code without swapping of wires .:-
ReplyDelete#include // Include servo library
Servo servoLeft; // Declare left servo signal
Servo servoRight; // Declare right servo signal
void setup() // Built in initialization block
{
servoLeft.attach(13); // Attach left signal to pin 13
servoRight.attach(12); // Attach right signal to pin 12
servoLeft.writeMicroseconds(1700); // 1.7 ms -> counterclockwise
servoRight.writeMicroseconds(1300); // 1.3 ms -> clockwise
}
void loop() // Main loop auto-repeats
{ // Empty, nothing needs repeating
}