This is my first time working with servos so I dont know if I'm doing something wrong. I want to set the servo to a specific angle, like 90 or 0. But it just doesn't do anything.
I copied and pasted the servo sweep code from the Arduino website and it works fine:
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
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 >= 0; 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
}
}
However, if I simply want to set the arduino to a certain angle, it does not work:
#include <Servo.h>
Servo myservo;
int pos = 0;
void setup() {
myservo.attach(9);
myservo.write(90);
}
void loop() {
}
It doesnt matter what angle I input, it does not change. Can anyone see a problem? It is a problem with the servo?
Thanks for any help!