two servos

Remember the way we connected a servo to the Arduino, there is a super quick way to turn that into two servo’s and have them run together.

The way to do this is to set up the servo’s as you would and upload this code:

#include <Servo.h>

Servo servoLeft; // Define left servo
Servo servoRight; // Define right servo

int angle = 0; // servo position in degrees
void setup() {
servoLeft.attach(10); // Set left servo to digital pin 10
servoRight.attach(9); // Set right servo to digital pin 9
servoLeft.write(angle);
servoRight.write(angle);
}

void loop() { // Loop through motion tests

forward();
delay (1500); // Example: move forward

reverse();
delay (1500); // Example: move forward

}
// Motion routines for forward, reverse, turns, and stop
void forward() {
servoLeft.write(180);
servoRight.write(0);
}

void reverse() {
servoLeft.write(0);
servoRight.write(180);
}

 

Whats good with this setup is you can insert a push button into the circuit and control the servo’s whenever you push the button. ¬†When setting this up you have to have the power go through the push button into one servo and then into the other.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>