Pan and Tilt Servo Project for Ardunio- Sweep Demo code

Pan and Tilt sweep demo

// by Glenn Mossy 11/4/2013Pan and Tilt Servo

Arduno Sketch Follows: 

//// Pan and Tilt sweeo demo

// by Glenn Mossy 11/4/2013

// Using Zitrades PT bracket.  http://amzn.com/B00CSCBSZY

// ZITRADES Brand New Original Aircraft FPV dedicated nylon Pan/Tilt/Zoom (20g without servos) Camera Platform Anti-Vibration Camera Mount for SG90 by ZITRADES

// Tested on Airtronics 94012Z, Blue= Signal Pin 9, Black= Gnd, Red = +5

// Tested on Analog Servo JR type, Brown=Gnd, Red=+5, yel= Signal pin 9. Needed to limit rotation for this one to 160.

// Tested on SG90 Blue Tower Pro 9g servo, Brown = Gnd, Org/Red=+5, Yel= signal pin9

include <Servo.h>

Servo panservo;  // create servo object to control a servo

Servo tiltservo;  // create servo object to control a servo

// a maximum of eight servo objects can be created

int pospan =88;    // variable to store the servo position for pan, 88 is mid position

int postilt =80;    // variable to store the servo position for tilt, 80 is mid position

void setup()

{

panservo.attach(9);  // attaches the servo on pin 9 to the servo object

tiltservo.attach(10);  // attaches the servo on pin 10 to the servo object

}

void loop()

{

//set the positions before the sweep

panservo.write(88);              // tell servo to go to position in variable ‘pos’

tiltservo.write(80);            // tell servo to go to position in variable ‘pos’

// panservo sweep

for(pospan = 25; pospan < 155; pospan += 1)  // goes from 22 degrees to 160 degrees

{                                  // in steps of 1 degree

panservo.write(pospan);              // tell servo to go to position in variable ‘pos’

delay(70);                       // waits 15ms for the servo to reach the position

}

for(pospan = 155; pospan>=25; pospan-=1)     // goes from 160 degrees to 22 degrees

{

panservo.write(pospan);              // tell servo to go to position in variable ‘pos’

delay(70);                       // waits 15ms for the servo to reach the position

}

//tiltservo sweep

for(postilt = 9; postilt < 169; postilt += 1)  // goes from 9 degrees to 169 degrees

{                                  // in steps of 1 degree

panservo.write(postilt);              // tell servo to go to position in variable ‘pos’

delay(50);                       // waits 15ms for the servo to reach the position

}

for(postilt = 169; postilt>=9; postilt-=1)     // goes from 169 degrees to 9 degrees

{

tiltservo.write(postilt);              // tell servo to go to position in variable ‘pos’

delay(50);                       // waits 15ms for the servo to reach the position

}

}

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s