Servo Motor

The code for the servo motor.

 

#include <Servo.h>
Servo servoRight; // Define right servo

int angle = 0; // servo position in degrees
void setup() {

servoRight.attach(9); // Set right servo to digital pin 9

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() {

servoRight.write(0);
}

void reverse() {

servoRight.write(180);
}

Setting up a servo is extremely easy. The red cable is for power, black for ground and white for signal. An easy setup for servo’s is 5v into the breadboard, power and ground go into the relevant pins and signal will go into a digital output say pin 9.

 

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>