Servo Motor with an External Power



Servo, can be powered by another power source without Arduino power. Only thing important here is that all the GND are connected to each other.

Like this you can add as many servo motors as you want.


***Important! If you will use high voltage battery and you want give power to arduino with same power source, you need to put a 7805 voltage regulator in, and make a parallel circuit for that too.

Hardware Required :

Arduino or Genuino Board
Servo Motor
Battery for Servo (I used for my servo; four pcs (1.5V) batteries.)
Mini Breadboard
Wires

Recommended site to buy the required hardware:
https://www.banggood.com/?p=CS120478587752016125

Get the Code :
#include <Servo.h>

Servo name_servo;

int servo_position = 0;

void setup() {

  name_servo.attach (9);

}

void loop() {

  for (servo_position = 0; servo_position <=180; servo_position +=1){

    name_servo.write(servo_position);
    delay(10);
  }

  for (servo_position=180; servo_position >= 0; servo_position -=1){

    name_servo.write(servo_position);
    delay(10);
  }
}