Hi everyone,
This is my first time posting here. I'm working on a project where I have to build a pan/tilt mechanism for a camera. I decided to use a couple of servos and a pan-tilt bracket to get it done, so I purchased two standard Hitec Servos (continuous rotation), and an Arduino Uno R3. Whenever I try to test the servo according to the example code supplied by Arduino, that is supposed to cause the servo to sweep back and forth, the response is always a continuous 360 degree rotation by the servos. I cannot get it to behave as the code seems to indicate it should. The code is shown below:
// Sweep
// by BARRAGAN <http://barraganstudio.com>
// This example code is in the public domain.
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
Any help would be most appreciated. I'm worried I may have the wrong type of servos or controller - I'm a relative amateur when it comes to controlling servos, though I do have some experience with C and C++, mostly for academic purposes. Thanks in advance!
Kareem