i started a projekt with a servomotor to move 0 - 50 degrees and backward ( loop )
Code:
#include <Servo.h>
Servo myservo; // create servo object to control a servo
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 <= 50; pos += 1) { // goes from 0 degrees to 50 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 = 50; pos >= 0; pos -= 1) { // goes from 50 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
}
}
}
You shouldn't supply the servo from the arduino.
The voltageregulator on the arduino can deliver a maximum of 500 mA. Even a small servo pulls more current at least under load and then your arduino will do a reset or the voltage-regulator gets overheated and destroyed.
I'm a friend of self-initated learning.
I will help you if you have made a frist own attempt with googling.
do three different google-searches with three different keyword-combinations.