Arduino UNO R3 Compatible using CH340T
 

  10.00 JD                  Add to cart

Power HD Micro Servo HD-1900A 
 

   6.00 JD                   Add to cart

Power HD Standard Servo 6001HB
 

   13.00 JD                 Add to cart

Power HD Meduim-Torque Servo HD-9001MG
 

  16.00 JD                  Add to cart

  830-Point Breadboard
 

   6.00 JD                   Add to cart

Servo Motor Sweep

 Wanna control a servo motor using arduino You are in the right place, in this lesson you will know     how to weep back and forth automatically.

Servo motors usually have three wires. Red wire is 5V and GND will either be black or brown. The other lead is the control lead and this is usually orange or yellow. 

 

 

Circuit

note that we are using digital pin 9, also note that the capacitor (470 uf or greater) is not a must but use it if the sevo shows unwanted behaviour.

 

 Code 

After loading this code to your arduino you should find that the servo begins to turn first in one     direction and then back in the other.


#include<Servo.h>
 
int servoPin =9;

Servo servo;

int angle =0;// servo position in degrees

void setup()
{
servo.attach(servoPin);
}


void loop()
{
// scan from 0 to 180 degrees
for(angle =0; angle <180; angle++)
{
servo.write(angle);
delay(15);
}
// now scan back from 180 to 0 degrees
for(angle =180; angle >0; angle--)
{
servo.write(angle);
delay(15);
}
}