Loading, please wait...

Servo Motor

Servo motor is an electrical device which is used to move or rotate objects. Servo motors have rotation angle that vary from 0 to 180 degree. It is not for continuous rotation like other motors.

It uses negative feedback to control motion of motor in a closed loop system which provide a better control over angular velocity.

 

 

 

Pin description:

  • VCC: To provide power to the sensor
  • GND: To provide GND to the sensor
  • Control Signal: To provide signal for motor control

Component needed:

  • Arduino Uno
  • Servo motor
  • Jumper wires

 Steps:

Step 1:

Connect servo motor to Arduino

Connection:

  • Connect VCC to 5V of Arduino
  • Connect GND to any GND pin of Arduino
  • Connect SIG pin to any PWM enabled pin (we will be using pin 9)

 



 

 

 

Step 2:

Upload the code

  • Download and include servo.h library in Arduino IDE
  • Copy and paste the code below into Arduino IDE
#include <Servo.h>

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

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 <= 180; pos += 1) { // goes from 0 degrees to 180 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 = 180; pos >= 0; pos -= 1) { // goes from 180 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
  }
}
  • Upload the code to Arduino

Conclusion:

The motor will go from 1 to 180 and then from 180 to 0 degree with a delay of 0.15 sec in between.