Servo with 180 Degree freedom (Arduino Sample Code)

$13.99
Be the first to leave a review
SKU RB_15G_C31
Weight 0.01 LBS
Stock
Wishlist

Create Wishlist

Servo has three wires: Brown, Red and Orange.  
Brown is GND, Red is VCC, and should be connected to +5V, Orange is the control signal, which is PWM signal.
 
Note: Don't power your servo from USB port as USB port cannot provide enough current.
 
 
Arduino Sample Code:
 
 

int servopin=7;//Define servo PWM control as digital 7
int myangle;//define variable angle
int pulsewidth;//define variable pulse width
int val;
void servopulse(int servopin,int myangle)//define a pulse function

{
  pulsewidth=(myangle*11)+500;//translate angle to a pulse width value between 500-2480
  digitalWrite(servopin,HIGH);//pull the interface signal level to high
  delayMicroseconds(pulsewidth);//delay in microseconds
  digitalWrite(servopin,LOW);//pull the interface signal level to low
  delay(20-pulsewidth/1000);
}
void setup()
{
  pinMode(servopin,OUTPUT);//set the interface pin as output
  Serial.begin(9600);//
  Serial.println("servu=o_seral_simple ready" ) ;
}
 void loop()//translate the number 0-9 to angle between 0 degree to 180 degree, and let LED blink the same times
 {
   val=Serial.read();//

  if(val>Ɔ'&&val<=Ə')
  {
    val=val-Ɔ';//
    val=val*(180/9);//translate number to angle
    Serial.print("moving servo to ");
    Serial.print(val,DEC);
    Serial.println();
    for(int i=0;i<=50;i++)//wait enough time so that the servo can rotate to the specified angle
     {
        servopulse(servopin,val);//call the pulse function
      }
   }

}