Arduino with Servo Motor

Introduction

In this module, we are going to discuss Arduino interfacing with the servo. It is an electric device used for precise control of angular rotation. It is used in various applications like a robotic arm. The rotation angle of the servo motor is controlled based on the PWM signal. By varying the width of the PWM signal, we can change the rotation angle and direction of the motor.

Inside of the servo motor

Servos consist of circuitry which receives the command and is responsible for their control at a particular angle. The entire circuit is placed inside the motor along with the motor gear. The servo motor is rotated based on the signal from the circuit and depending on the angle.
 
To understand the working of the servo motor the internal structure has to be analyzed. In the servo motor different parts are shown in the image below. The motor is attached accordingly by using the gear mechanics. The potentiometer’s resistance changes with the rotation of the motor. The rotation of the motor will depend on the PWM signal
 

 

The servo motor consists of VCC, GND, SIGNAL pins. Electrical pulses or signals are given through the signal wire, which determines the movement of the servo motor. Servo motors can rotate in 90 or 180 degrees. The rotor of the servo motor will move in the position based on the signal.
The servo motor speed is dependent on the angle. The motion of the motor is controlled based on the distance of the destination. This is called proportional control.

Connecting the servo with Arduino

  • The red wire in the servo is VCC pin connect it to 5v of Arduino
  • The brown wire is ground pin connect it to the ground of Arduino
  • Orange is a signal wire connected to  pin 10

Arduino program for servo

#include  <Servo.h> //including the servo library
Servo myservo;      //including a variable for servo named sg90
int servo_signal = 10;
void setup()
{
myservo.attach(servo_signal);  //Giving the command to arduino to control pin 10 for servo
}
void loop()
{
myservo.write(0); // moving the servo at 0 degree
delay(1000);
myservo.write(45); // moving the servo at 45 degree
delay(1000);
myservo.write(90); // moving the servo at 90 degree
delay(1000);    // wait for 1 second
myservo.write(135); // moving the servo at 135 degree
delay(1000);
myservo.write(180);   // moving the servo at 180 degrees
delay(1000);    // wait for 1 sec
}

Working of servo

When the commands are given in the Arduino, it sends signal information through the signal pin to the servo according to the signal it generates the respective resistance inside the servo by which, the servo can rotate and fix at desired angle .a signal from the shaft is taken through the potentiometer to analyze angle .this potentiometer feedback mechanism is used for the precise output of servo. Hence bye wishes it gains a high angular rotational accuracy.

Explanation of code

While working with Servo we have to include a new library in the code.it includes all the directories and functions required for the operation of the servo.
 
Firstly we have to give a name for our servo ( helps more if we use more than one servos in the project) [Servo myservo; ].where myservo is the name given to it.
 
Next, we have to declare a digital pin for signal, we are using pin number 10 in the code.
 
[myservo.attach(servo_signal);  ] here we use  servoname.attach(signalpin) command to declare which pin is connected to the signal wire of servo.
 
[myservo.write(angle)] is used to make the servo to rotate in the desired angle. Where angle is the attribution that we have to set according to our requirement.
 

Conclusion

 
Hence we have discussed the structure, working principle and code keywords that are used to operate the servo and this is the end of this tutorial arduino with servo motor.
Spread knowledge

Leave a Comment

Your email address will not be published. Required fields are marked *