Skip to main content

Arduino board interfacing with servo motor

1.    Servo motor

    A servomotor is a rotary actuator or linear actuator that allows for precise control of angular or linear position, velocity and acceleration. It consists of a suitable motor coupled to a sensor for position feedback. It also requires a relatively sophisticated controller, often a dedicated module designed specifically for use with servomotors.
                         


Table of specifications: -

S. no
Type
Specification
1
Size
38 x 11.5 x 24mm (Include tabs) 28 x 12.7 x 27mm (Not include tabs)
2
weight
17 to 18 g
3
Speed
0.14sec/60degrees (4.8V) 0.12sec/60degrees (6.0V
4
Torque
2.5kgf-cm (4.8V) 3.0kgf-cm (6.0V)
5
Voltage
4.8V-6.0V
6
Connector type
JR type (Yellow: Signal, Red: VCC, Brown:GND)


2.    Arduino interfacing with Servo motor

 Here we will see how to connect a servo motor 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:
 1.      An Arduino board connected to a computer via USB
 2.      A servo motor
 3.      Jumper wires


Following are the steps to connect a servo motor to the Arduino:
1.  The servo motor has a female connector with three pins. The darkest or even black one     is usually the ground. Connect this to the Arduino GND.
2.  Connect the power cable that in all standards should be red to 5V on the Arduino.
3.  Connect the remaining line on the servo connector to a digital pin on the Arduino.

Note: - Any digital pin of arduino board can be used to run servo motor but initial don’t forget to add servo library.

download servo library from here:Servo master library


Arduino code for Servo motor: -


#include <Servo.h>  //Include the Servo library


int servoPin = 3;   // Declare the Servo pin

Servo Servo1;      // Create a servo object

void setup()
{
   Serial.begin(9600);
   Servo1.attach(servoPin); / /We need to attach the servo to the used pin number
}

void loop()
{
   
   Servo1.write(0);      / / Make servo go to 0 degrees
   Serial.println("Rotate the servo with 0 degree");
   delay(1000);
   
   Servo1.write(90);       // Make servo go to 90 degrees
   Serial.println("Rotate the servo with 90 degree");
   delay(1000);
   
   Servo1.write(180);       // Make servo go to 180 degrees
   Serial.println("Rotate the servo with 180 degree");
   delay(1000);

}


Please share and follow my blog for more Arduino projects.

Comments