You are on page 1of 7

4/9/2014

Interfacing Servo Motor with PIC Microcontroller - MikroC


Home
Projects
Tutorials

Contact Us

electroSome
MIKROC / PIC
MICROCONTROLLER
/ TUTORIALS

You Inspire..We Create..

21
COMMENTS

FOLLOW:


NEXT STORY

Using Internal EEPROM of PIC

Interfacing Servo Motor with


PIC Microcontroller

Microcontroller

PREVIOUS STORY

Samsung Galaxy Codes Reset, MAC


address, IMEI

BY LIGO GEORGE JUNE 17, 2012

SEARCH HERE

Servo Motor uses


error sensing
negative feedback
to control the

precise angular
position. Servos are
used for

Configuration Bits in MidRange PIC Microcontrollers

precise positioning
in robotic arms,
legs, RC

Getting Started with PL2303


USB to UART Converter

Aeroplanes, Helicopters etc. Please read the article Servo Motor


for more information about its working and construction.
Hobby Servo Motors have three wires, two of them (RED and

Flow Control in Python

BLACK) are used to given power and the third one is used to
give control signals. Servo can be easily be controlled using
microcontrollers using Pulse Width Modulated (PWM) signals
on the control wire. Here we are using a servo whose angular

AM Generation using
Simulink

rotation is limited to 0 180. We can control the exact angular


position by using a pulse, whose width varying from
1 millisecond to 2 millisecond on the control wire. The actual
behaviour of a particular motor depends upon its manufacture,

Generating PWM with PIC


Microcontroller using HiTech C

please refer the datasheet of the particular motor for that.


AM Generation using Matlab

Condenser Microphone

Using UART of PIC


Microcontroller Hi Tech C

http://electrosome.com/servo-motor-pic-microcontroller/

1/7

4/9/2014

Interfacing Servo Motor with PIC Microcontroller - MikroC


Interfacing LCD with PIC
Microcontroller Hi Tech C

Getting Started with Scilab


Beginners Tutorial

Pic Micro Controller


Pic Tutorials
Pic Programming
Controlling Angular Position of Servo Motor using Pulse Width Modulation

Circuit Diagram :

MOST VIEWED
Voltmeter and Ammeter using PIC
Microcontroller - 42,845 views
Interfacing Stepper Motor with PIC
Microcontroller - 39,713 views
USB PIC Programmer : PICKit2 - 35,619
views
Digital Clock using PIC Microcontroller and
DS1307 RTC - 35,441 views
Interfacing DC Motor with PIC
Microcontroller using L293D - 34,489 views

PWM DC Motor Control


Servo Motor Circuit
Pic Servo

SUBSCRIBE TO OUR MAILS


Email Address*

Name*
Interfacing Servo Motor with PIC Microcontroller

Note: VDD and VSS of the pic microcontroller is not shown in

* = required field

the circuit diagram. VDD should be connected to +5V and VSS to

Preferred Format

GND.
MikroC Programming:

HTML
Text

Subscribe

void main()
{
TRISB = 0; // PORTB as Ouput Port
do
{
//To Turn to 0 Degree
PORTB.F0 = 1;
Delay_us(1000);//1ms Delay
PORTB.F0 = 0;
Delay_ms(1000);
//To Turn to 90 Degree
PORTB.F0 = 1;
Delay_us(1500);
PORTB.F0 = 0;

http://electrosome.com/servo-motor-pic-microcontroller/

2/7

4/9/2014

Interfacing Servo Motor with PIC Microcontroller - MikroC


Delay_ms(1000);
//To Turn to 180 Degree
PORTB.F0 = 1;
Delay_us(2000);
PORTB.F0 = 0;
Delay_ms(1000);
}while(1);
}

Control wire of the Servo is connected to RB0 of the PIC


Microcontroller. Delay_ms() is used to make delay in
milliseconds during the program execution while Delay_us() is
used to make delay in microsecond during the program
execution.
You can download MikroC Code, Proteus files etc here..
Interfacing Servo Motor with PIC Microcontroller
Related Searches:

Printed Circuit Design


Like 2,284 people like this.

FM Frequency
Microchip PIC
Power Supply Voltage
Crystal Oscillator

electroSome
Follow

Wide Frequency
Range
8 Bit Microcontroller
Variable Frequency
Oscillator

+1

+ 326

Related Posts :

PIC Microcontrollers

About this Ad

Bit Microcontrollers

Interfacing
Servo Motor
with Atmega32
Microcontroller

Interfacing
Servo Motor
with 8051
using Keil C

Interfacing DC
Motor with PIC
Microcontroller

Servo Motor

Tags:

Microcontroller

PIC

Servo Motor

Interfacing
Stepper Motor
with PIC
Microcontroller

Trust Rating

Tutorials

Not Yet Rated


electrosome.com

Comments

Community

Sort by Best

Login
Share

Favorite

Join the discussion


http://electrosome.com/servo-motor-pic-microcontroller/

3/7

4/9/2014

Interfacing Servo Motor with PIC Microcontroller - MikroC


EE103

a year ago

What would you do to make the servo go in reverse?


3

Reply Share

Ligo George

Mod

EE103 a year ago

Note that sevo will not rotate continuously... and its


position is determined by the pulse width..
3
edwin

Reply Share

7 months ago

In your program you have given like this,


PORTB.F0 = 1;
Delay_us(1000);//1ms Delay
PORTB.F0 = 0;
Delay_ms(1000);
but as per the diagram of the input pulses it should be like this
right?
PORTB.F0 = 1;
Delay_us(1000);//1ms Delay
PORTB.F0 = 0;
Delay_ms(20);
2

Reply Share

Ligo George

Mod

edwin 6 months ago

20ms is the minimum required time period...


Reply Share

edwin

Ligo George 6 months ago

so instead of 20 ms,1000 ms will work too???


Reply Share

edwin

edwin 6 months ago

can i have your mail id??? namalum


malayaliya:)
Reply Share

Ligo George

Mod
6 months ago

edwin

It should work.. try it in hardware.. It will


depend on the servo motor...
my mail id :
ligo_george@electrosome.com
Reply Share

Bassant M. Mohamed

a month ago

how to make a code for a servo using ADC in pic16f877a?


Reply Share

magnai

a month ago

Hello LIGO Gearge


I can control it in simulation Proteus. It is Ok.
But i can't control it in real time.
Tell me please where is wrong?
Code C is ok.
I have used quartz crystal 20Mhz.
I use servomotor (DF25MG made in china).
Reply Share

sarawrislammooon

a month ago

hi i use those codes for servo sg 91r servo but my motor does
not move it goes some 30-45 degree and stops what can i do
please help .........
Reply Share

neville

2 months ago

Hi, I want to use a mikroE 4x4 matrix keypad to input a specific


angle that the servo should go to. Do you know how I can code
the keypad and servo to do this in MikroC? Or a good tutorial
that could help? Thanks

http://electrosome.com/servo-motor-pic-microcontroller/

4/7

4/9/2014

Interfacing Servo Motor with PIC Microcontroller - MikroC

that could help? Thanks

Reply Share

roboblaze

4 months ago

What if i want to servo motor to turn 270 degrees? i mean first 0


degree...then 90 deg...then 180...then 270 degree?? coz my bot
requires complete circular rotation...need help!
Reply Share

Ligo George

Mod

roboblaze 4 months ago

The angle of the servo is directly propotional to the pulse


width... So provide a pulse width corresponding to 270
degree
Reply Share

Felipe Rezende Dejano

5 months ago

So...what is the values that i need to use to bring back to the


older position, for example, im using a servo to open and and
close a claw, so i need to run the motor for a side and after run
againt to another size....how can i do this? whats the values that
i need to put? Thanks!
Reply Share

Ligo George

Mod
5 months ago

Felipe Rezende Dejano

Servo's position is determined by the pulse width..


if 1ms its position will be at 0 degree..
if 1.5 its position will be at 90 degree...
2
adpeian

Reply Share
6 months ago

why is that the signal of the servo is connected to the interrupt


port of the microcontroller not the ccp port?
Reply Share

Ligo George

Mod

adpeian 6 months ago

As indicated above, you need a frequency of about 50Hz,


to control the servo motor.... thus you need to use a very
low clock frequency to produce that frequency using ccp
module...
Reply Share

Janelle Serrano Polinga

8 months ago

Hi!!! can you please give me a sample program for five degree
freedom robotic arm using servo motor? we are using mikroc in
16f84a as our pic and we are having a hard time solving it.
thanks! :D
Reply Share

Ligo George

Mod
8 months ago

Janelle Serrano Polinga

Simple vary the pulse width depending on the type of


servo you are using.. Pulse width of servos may vary for
different manufactures..
Reply Share

da

a year ago

maybe you have some microC code which can do the same
servo control via uart? (pic to pic communication)
Reply Share

Ligo George

Mod

da a year ago

Try this link http://www.electrosome.com/pic...

electroSome

http://electrosome.com/servo-motor-pic-microcontroller/

5/7

4/9/2014

http://electrosome.com/servo-motor-pic-microcontroller/

Interfacing Servo Motor with PIC Microcontroller - MikroC

6/7

4/9/2014

Interfacing Servo Motor with PIC Microcontroller - MikroC

0
Tw eet

42
Like

Share

http://electrosome.com/servo-motor-pic-microcontroller/

7/7

You might also like