Servo Motor

Interface Servo Motor With Arduino

Servo Motor

Servo motors is a  special type of motor which can not move 360 degrees, however, it can move 180 degrees. Furthermore, it can be used for making smart dustbin project,  smart door lock and  robotic arm.

In this project, you will learn  how to  interface Servo motor with Arduino.

Below servo moto pins their description are given

Servo Motor

GND pin is ground pin and you will connect it with ground pin of Arduino Microcontroller.

VCC pin is +Ve pin and you will connect it with 5V pin of Arduino Microcontroller.

Signal pin is output pin which you can connect with any PWM pin of Arduino, I will connect it with pin no. 9.

Servo Motor

Now Servo motor is connected with Arduino  GND, 5V and   at digital pin 9.

Now it is time to write the code, see the code below


Code to move Servo Knob from 0 to 90 degrees


#include<Servo.h>
Servo sr;
void setup()
{
sr.attach(9);
}
void loop()
{
sr.write(90);// Knob of servo moves 90 degrees
delay(5000);//
sr.write(0);// Knob of servo motor moves at 0 degree
delay(5000);//Wait for 5 seconds
}

#include<Servo.h> —> Includes servo library in the program.

Servo sr;—–> Declares sr as servo object.

sr.attach(9);—–> Output pin of  Servo motor will be attached at pin no. 9.

sr.write(90);—> Knob of servo moves 90 degrees.

delay(5000);—->Wait for 5 seconds.

sr.write(0);——–> Knob of servo motor moves at 0 degree


Code to move Servo Knob from 0 to 45 degrees


#include<Servo.h>
Servo sr;
void setup()
{
sr.attach(9);
}
void loop()
{
sr.write(45);// Knob of servo moves 90 degrees
delay(5000);//
sr.write(0);// Knob of servo motor moves at 0 degree
delay(5000);//Wait for 5 seconds
}

 


Code to move Servo Knob from 0 to 180 degrees


#include<Servo.h>
Servo sr;
void setup()
{
sr.attach(9);
}
void loop()
{
sr.write(180);// Knob of servo moves 90 degrees
delay(5000);//
sr.write(0);// Knob of servo motor moves at 0 degree
delay(5000);//Wait for 5 seconds
}

The whole output is described in the video, which is simulated and explained in intuitive way so that beginners can understand easily.

See the video

 

 

 

 

Leave a Comment

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

©Postnetwork-All rights reserved.