text: Introduction: Arduino Servo Motors and then how to turn it to different positions.
  The first motor I ever connected to an Arduino, seven years ago, was a Servo motor. Nostalgic moment over, back to work!
  We will need the following things:
  - An Arduino board connected to a computer via USB
  - A servo motor
  - Jumper wires
  There are few big names in the servo motor world. Hitec and Futaba are the leading RC servo manufacturers. Good places to buy them are Servocity, Sparkfun, and Hobbyking.
  This instructable and many more can be found in my Arduino Development Cookbook available here. :D
  Step 1: How to Connect Them. Connect this to the Arduino GND.
  - Connect the power cable that in all standards should be red to 5V on the Arduino.
  - Connect the remaining line on the servo connector to a digital pin on the Arduino.
  Check the image for a view of the servo connected to the Arduino.
  Step 2: Code
  The following code will turn a servo motor to 0 degrees, wait 1 second, then turn it to 90, wait one more second, turn it to 180, and then go back.
  // Include the Servo library
  #include <Servo.h> // Declare the Servo pin int servoPin = 3; // Create a servo object Servo Servo1;); }
  If the servo motor is connected on another digital pin, simply change the value of servoPin to the value of the digital pin that has been used.
  Step 3: How It Works.
  Remember that using the Servo library automatically disables PWM functionality on PWM pins 9 and 10 on the Arduino UNO and similar boards.
  Code breakdown
  The code simply declares the servo object and then initializes the servo by using the servo.attach() function. We shouldn't forget to include the servo library. In the loop(), we set the servo to 0 degrees, wait, then set it to 90, and later to 180 degrees.
  Step 4: More Things About Servos
  Controlling servos is easy, and here are a few more tricks we can use:
  Controlling the exact pulse time
  Arduino has a built-in function servo.write(degrees) that simplifies the control of servos. However, not all servos respect the same timings for all positions. Usually, 1 millisecond means 0 degrees, 1.5 milliseconds mean 90 degrees, and, of course, 2 milliseconds mean 180 degrees. Some servos have smaller or larger ranges.
  For better control, we can use the servo.writeMicroseconds(us) function, which takes the exact number of microseconds as a parameter. Remember, 1 millisecond equals 1,000 microseconds.
  More servos
  In order to use more than one servo, we need to declare multiple servo objects, attach different pins to each one, and address each servo individually. First, we need to declare the servo objects—as many as we need:
  // Create servo objects Servo Servo1, Servo2, Servo3;
  Then we need to attach each object to one servo motor. Remember, every servo motor uses an individual pin:
  Servo1.attach(servoPin1); Servo2.attach(servoPin2); Servo3.attach(servoPin3);
  In the end, we just have to address each servo object individually:
  Servo1.write(0); // Set Servo 1 to 0 degrees Servo2.write(90); // Set Servo 2 to 90 degrees
  Connection-wise, the grounds from the servos go to GND on the Arduino, the servo power to 5V or VIN (depending on the power input), and in the end, each signal line has to be connected to a different digital pin. Contrary to popular belief, servos don't need to be controlled by PWM pins—any digital pin will work.
  Continuous rotation servos
  There is a special breed of servos labelled as continuous rotation servos. While a normal servo goes to a specific position depending on the input signal, a continuous rotation servo either rotates clockwise or counter-clockwise at a speed proportional to the signal. For example, the Servo1.write(0) function will make the servomotor spin counter-clockwise at full speed. The Servo1.write(90) function will stop the motor and Servo1.write(180) will turn the motor clockwise at full speed.
  There are multiple uses for such servos; however, they are really slow. If you are building a microwave and need a motor to turn the food, this is your choice. But be careful, microwaves are dangerous!
  Step 5: Check Out More
  Yolo Pigeon made it!
  Recommendations
  We have a be nice policy.
  Please be positive and constructive.
  Tips
  Questions
  does the servo move 90 degs or does it go to the position 90 degs
  23 Comments
  for the same above code,my servo is rotating from 0 to 180 but it's not rotating back to 0, tries going beyond 180 making humming sound and keeps on doing that for ever.however if i try changing the code like starting from 180 to 0,still it rotates from 180 to 0 and doesn't come back from 0 to 180.so, can anyone help me out to solve this problem..!! ??
  Here's what I did to sweep from 0 to 130 (you can use 180....130 worked better with my servo) and back-and-forth....
  // Include the Servo library
  #include <Servo.h>
  // Declare the Servo pin
  int servoPin = 6;
  // Create a servo object
  Servo Servo1;
  int angle = 0;
  int inc = 2;
  void setup() {
  // put your setup code here, to run once:
  // We need to attach the servo to the used pin number
  Servo1.attach(servoPin);
  }
  void loop() {
  // put your main code here, to run repeatedly:
  // Make servo go to 0 degrees
  if (angle == 0) {
  inc = 2;
  }
  if (angle == 130) {
  inc = -2;
  }
  Servo1.write(angle);
  angle = angle + inc;
  delay(20);
  what is the model number of the servo motor?
  i will try this method but doesn't work any other way to work servo
  Sound and easy to understand, I'm new in Arduino. Thank you sir.
  can i control the speed of the servo if yes how ??
  In his library he writes a degree to the servo and it moves there. Set up a loop that increases the degree by say... 1 every time it loops and put a delay in the loop. When you get to the position you want get out of the loop. That will get you to move in degrees per second (you can also use the millis instruction so you can do other things and not actually stop the microcontroller. The millis instruction is more complex but basically you are taking a free running clock time with millis and comparing it to the last time you got the millis instruction. This allows the controller to continue executing main and does not just stop and sit on a delay not operating the rest of the code... are you confused yet?)
  One note, the on-board regulator is only good for up to 3 large servos, before you are drawing too much, that the Arduino mpu itself, begins to brown-out/reset. Then, you'll want to supply the servos externally, say with a 7805 regulator, which can still be fed from the main supply (parallel to the voltage going to the barrel socket. Highly advise against drawing through the VIn pin on the arduino, as this is still a thin trace that could burn/break)
  One odd thing, despite the in-IDE example saying you can only assign 8 servo devices, ALL digital pins, 0 through 13, can be used (without serial I/O), but kinda pushing the limits.
  Hello,
  i want to run 48 servo motors with arduino mega. but i am getting lot of issue with power. kindly suggest me better way of power distribution.
  i think you need more power but i dont know how you do that, sorry