100% found this document useful (1 vote)
819 views10 pages

Interfacing Servo Motor With PIC Microcontroller - MPLAB XC8

This document discusses interfacing a servo motor with a PIC microcontroller using MPLAB XC8. It explains that servo motors use position feedback to control angular position. The circuit diagram shows connecting the power, ground, and control signal wires of a servo motor to a PIC microcontroller. The MPLAB XC8 code provided pulses the control signal at different widths to rotate the servo motor to 0, 90, and 180 degrees. The code can be downloaded to run the servo motor interfacing project.

Uploaded by

rajmohan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
819 views10 pages

Interfacing Servo Motor With PIC Microcontroller - MPLAB XC8

This document discusses interfacing a servo motor with a PIC microcontroller using MPLAB XC8. It explains that servo motors use position feedback to control angular position. The circuit diagram shows connecting the power, ground, and control signal wires of a servo motor to a PIC microcontroller. The MPLAB XC8 code provided pulses the control signal at different widths to rotate the servo motor to 0, 90, and 180 degrees. The code can be downloaded to run the servo motor interfacing project.

Uploaded by

rajmohan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

11/12/2014

24
AUG

Interfacing Servo Motor with PIC Microcontroller - MPLAB XC8

Interfacing Servo Motor with PIC Microcontroller MPLAB


XC8
B Y L I G O G E O RG E (HTTP : / / E L E CTRO S O ME . CO M/ A UTHO R/ L I J O P P A NS / ) / 2 CO MME NTS
(HTTP : / / E L E CTRO S O ME . CO M/ S E RV O -MO TO R-P I C-MP L A B -X C8 / # DI S Q US _ THRE A D)

Keep Your Cloud Private


All of Our Servers Are the Most Secure & Powerful. Chat to
Save!
Servo Motor is an ordinary geared dc motor
equipped with closed loop servo mechanism
which uses position feedback to control exact
angular position of the rotor. These are
commonly used in robotic arms, legs etc. Servo
Motors do not rotate continuously, their rotation
is limited to fixed angles. Usually these motors
have rotation limit from 90 to 180 and some
special have limits 360 or more.
Servo Motors usually have three wires. RED
and BLACK wires are used to provide power.

(http://electrosome.com/wpRequired voltage will depend upon the type of content/uploads/2012/06/Servo-Motor.gif)


servo you are using, so please refer the
specifications given by the manufacture. The

Servo Motor (http://electrosome.com/servo-motor/)

third wire is used to provide control signals to control exact angular position of the servo
motor. Its color varies for different manufactures such as YELLOW, BROWN, WHITE etc.
Servo Motor shaft can be moved to desired position by using Pulse Width Modulated (
http://www.electrosome.com/pwm-pulse-width-modulation/)

(PWM

http://www.electrosome.com/pwm-pulse-width-modulation/)) signals on the control wire.

http://electrosome.com/servo-motor-pic-mplab-xc8/

1/10

11/12/2014

Interfacing Servo Motor with PIC Microcontroller - MPLAB XC8

Unlike DC Motors, reversing the power supply polarity does not reverse the rotation instead
of it may damage the control circuitry.

Keep Your Cloud


Private
All of Our Servers Are the
Most Secure & Powerful.
Chat to Save!

Servo Motors can be easily interfaced with PIC Microcontroller. Here for demonstration we
are using PIC 16F877A and VIGOR VS-10A servo motor. The required pulse width of this
servo motor ranges from 800S to 2200S and rotation angle is greater than or equal to
170. Its operating voltage range is 4.8V to 6V.

(http://electrosome.com/wp-content/uploads/2012/06/Servo-Angular-RotationPulse-Width-Modulation1.jpg)
http://electrosome.com/servo-motor-pic-mplab-xc8/

2/10

11/12/2014

Interfacing Servo Motor with PIC Microcontroller - MPLAB XC8

Servo Angular Rotation Pulse Width Modulation ( http://electrosome.com/pwm-pulse-width-modulation/)

Circuit Diagram

(http://electrosome.com)
(http://electrosome.com/cart/)

(http://electrosome.com/wp-content/uploads/2014/08/Interfacing-Servo-Motor-with-PICMicrocontroller.jpg)
Interfacing Servo Motor with PIC Microcontroller (http://electrosome.com/servo-motor-pic-microcontroller/)

Tip : Use separate power supplies for PIC and Servo Motor OR use proper filtering
capacitors otherwise ripples produced by the Servo Motor may affect the working of PIC.

MPLAB XC8 Code


#define _XTAL_FREQ 8000000
#include <xc.h>
// BEGIN CONFIG
#pragma config FOSC = HS
#pragma config WDTE = OFF
http://electrosome.com/servo-motor-pic-mplab-xc8/

3/10

11/12/2014

#pragma config
#pragma config
#pragma config
#pragma config
#pragma config
#pragma config
//END CONFIG

Interfacing Servo Motor with PIC Microcontroller - MPLAB XC8

PWRTE = OFF
BOREN = ON
LVP = OFF
CPD = OFF
WRT = OFF
CP = OFF

void servoRotate0() //0 Degree


{
unsigned int i;
for(i=0;i<50;i++)
{
RB0 = 1;
__delay_us(800);
RB0 = 0;
__delay_us(19200);
}
}
void servoRotate90() //90 Degree
{
unsigned int i;
for(i=0;i<50;i++)
{
RB0 = 1;
__delay_us(1500);
RB0 = 0;
__delay_us(18500);
}
}
void servoRotate180() //180 Degree
{
unsigned int i;
for(i=0;i<50;i++)
{
RB0 = 1;
__delay_us(2200);
RB0 = 0;
__delay_us(17800);
}
}
void main()
{
TRISB = 0; // PORTB as Ouput Port
do
{
servoRotate0(); //0 Degree
http://electrosome.com/servo-motor-pic-mplab-xc8/

4/10

11/12/2014

Interfacing Servo Motor with PIC Microcontroller - MPLAB XC8

__delay_ms(2000);
servoRotate90(); //90 Degree
__delay_ms(2000);
servoRotate180(); //180 Degree
}while(1);
}

Hope you can understand the working of the above program. If you have any doubts just
comment below.

Download
You can download the entire project files here.
Servo Motor (http://electrosome.com/wp-content/uploads/2014/08/Servo-Motor.zip)

Want to See the Output ?

http://electrosome.com/servo-motor-pic-mplab-xc8/

5/10

11/12/2014

Interfacing Servo Motor with PIC Microcontroller - MPLAB XC8

Like 2,877 people like this. Be the first of your friends.

electroSome
Follow

+1

+ 470

CATE G O RI E S : MP L A B X C8 (HTTP : / / E L E CTRO S O ME . CO M/ CA TE G O RY / TUTO RI A L S / P I C-MI CRO CO NTRO L L E R/ MP L A B X C8 / ), P I C MI CRO CO NTRO L L E R (HTTP : / / E L E CTRO S O ME . CO M/ CA TE G O RY / TUTO RI A L S / P I C-MI CRO CO NTRO L L E R/ ),
TUTO RI A L S (HTTP : / / E L E CTRO S O ME . CO M/ CA TE G O RY / TUTO RI A L S / )
TAG S : MI CRO CO NTRO L L E R (HTTP : / / E L E CTRO S O ME . CO M/ TA G / MI CRO CO NTRO L L E R/ ), MP
B
L ALOVE

IT , SHARE IT

(HTTP : / / E L E CTRO S O ME . CO M/ TA G / MP L A B / ), MP L A B X C8 (HTTP : / / E L E CTRO S O ME . CO M/ TA G / MP L A B -X C8 / ), P I C


(HTTP : / / E L E CTRO S O ME . CO M/ TA G / P I C/ ), P RO TE US (HTTP : / / E L E CTRO S O ME . CO M/ TA G / P RO TE US / ), S E RV O MO TO R
(HTTP : / / E L E CTRO S O ME . CO M/ TA G / S E RV O -MO TO R/ ), TUTO RI A L S (HTTP : / / E L E CTRO S O ME . CO M/ TA G / TUTO RI A L S / )

http://electrosome.com/servo-motor-pic-mplab-xc8/

6/10

11/12/2014

Interfacing Servo Motor with PIC Microcontroller - MPLAB XC8

2 Comments

electroSome

Login

Share Favorite

Sort by Best

Join the discussion


Copper Masud

a month ago

MG996R
how can i drive this servo , pleasee ?? your code dont work with this one..

Reply Share

Ligo George

Mod

> Copper Masud a month ago

use pulse width according to that servo specifications.

Reply Share

WHAT'S THIS?

ALSO ON ELECTROSOME

Led Blinking using Raspberry Pi

Siren Generator using IC UM3561

2 comments 2 months ago

4 comments 3 months ago

Ligo George Our small youtube channel :

Ligo George Yes, it is fine..

https://www.youtube.com/user/l...

Wireless Transmitter and Receiver using


ASK RF Module

HT12E Encoder IC for Remote Control


Systems

23 comments a year ago

7 comments a year ago

Ligo George Above circuits are 100%

yousuff 1.what data corresponds to an

working... Make sure that you are using


correct oscillator resistors..

open circuit?,,i,e,when a data input pin is


not grounded,what data value does it
correspond to?2.how to calculate

Subscribe

Add Disqus to your site

Privacy

RECENT POSTS
USING PUSH BUTTON SWITCH WITH PIC MICROCONTROLLER CCS C
(HTTP://ELECTROSOME.COM/SWITCH-PIC-MICROCONTROLLER-CCS-C/)

USING UART OF PIC MICROCONTROLLER MPLAB XC8 (HTTP://ELECTROSOME.COM/UART-PICMICROCONTROLLER-MPLAB-XC8/)


http://electrosome.com/servo-motor-pic-mplab-xc8/

7/10

11/12/2014

Interfacing Servo Motor with PIC Microcontroller - MPLAB XC8

LED BLINKING USING RASPBERRY PI (HTTP://ELECTROSOME.COM/LEDBLINKING-RASPBERRY-PI/)

GETTING STARTED WITH PIC MICROCONTROLLER CCS C COMPILER


(HTTP://ELECTROSOME.COM/GETTING-STARTED-PIC-CCS-C/)

INTERFACING SERVO MOTOR WITH PIC MICROCONTROLLER MPLAB XC8


(HTTP://ELECTROSOME.COM/SERVO-MOTOR-PIC-MPLAB-XC8/)

INTERFACING LCD WITH PIC MICROCONTROLLER MPLAB XC8


(HTTP://ELECTROSOME.COM/LCD-PIC-MPLAB-XC8/)

INTERFACING HC-SR04 ULTRASONIC SENSOR WITH PIC MICROCONTROLLER


(HTTP://ELECTROSOME.COM/HC-SR04-ULTRASONIC-SENSOR-PIC/)

SIREN GENERATOR USING IC UM3561 (HTTP://ELECTROSOME.COM/SIRENGENERATOR-IC-UM3561/)

SUBSCRIBE
EMAIL

SUBMIT

http://electrosome.com/servo-motor-pic-mplab-xc8/

8/10

11/12/2014

Interfacing Servo Motor with PIC Microcontroller - MPLAB XC8

RECENT COMMENTS
Even if you are using 0.47 ohm resistor... it actual value may [..]

LIGO GEORGE (HTTP://WWW.ELECTROSOME.COM/)


on Voltmeter and Ammeter using PIC Microcontroller (http://electrosome.com/voltmeter-ammeterpic/#comment-3321)

You can connect TX to RX and RX to TX.. 3.3 and [..]

LIGO GEORGE (HTTP://WWW.ELECTROSOME.COM/)


on Getting Started with PL2303 USB to UART Converter (http://electrosome.com/pl2303-usb-to-uartconverter/#comment-3320)

Yes it can. .but the accuracy of A/D converter degrades as Vref [..]

LIGO GEORGE (HTTP://WWW.ELECTROSOME.COM/)


on Voltmeter and Ammeter using PIC Microcontroller (http://electrosome.com/voltmeter-ammeterpic/#comment-3319)

im sorry , i meant to say in series. I have used [..]

PREETHI SHIVANAND (MAILTO:[email protected])


on Voltmeter and Ammeter using PIC Microcontroller (http://electrosome.com/voltmeter-ammeterpic/#comment-3314)

I am new to pl2303. I want to interface this module to [..]

MOHAMMED SUHEL (MAILTO:[email protected])


on Getting Started with PL2303 USB to UART Converter (http://electrosome.com/pl2303-usb-to-uartconverter/#comment-3312)

http://electrosome.com/servo-motor-pic-mplab-xc8/

9/10

11/12/2014

Interfacing Servo Motor with PIC Microcontroller - MPLAB XC8

Hi, I want to build a multiple timer with 16F877a, ds1307, and [..]

NEYAMAT (MAILTO:[email protected])
on Interfacing Relay with PIC Microcontroller (http://electrosome.com/interfacing-relay-with-picmicrocontroller/#comment-3311)

Hi, what if, for example, my Vref+ is 20mV and my Vref- [..]

JIMMY NUTRON (MAILTO:[email protected])


on Voltmeter and Ammeter using PIC Microcontroller (http://electrosome.com/voltmeter-ammeterpic/#comment-3310)

Please post a tutorial on 50hz pure sinewave generator.

SUJITH THYCATTUSSERY (MAILTO:[email protected])


on Generating PWM with PIC Microcontroller using CCP Module (http://electrosome.com/pwm-picmicrocontroller/#comment-3309)

Terms and conditions (http://electrosome.com/terms-conditions/) / Privacy Policy (http://electrosome.com/privacy-policy/) /


Shipping Policy (http://electrosome.com/shipping-policy/) / Refund Policy (http://electrosome.com/refund-policy/) /
About Us (http://electrosome.com/about-us/)
electroSome - Discover... Develop... Deliver...

http://electrosome.com/servo-motor-pic-mplab-xc8/

10/10

You might also like