0% found this document useful (0 votes)
244 views5 pages

How To Servo Motor Control Using Microcontroller PIC16F877A

This document describes how to control a servo motor using a PIC16F877A microcontroller. It explains that servo motors can be positioned by sending PWM signals of varying pulse widths. A pulse width of 1500μs positions the motor to the center, less than 1500μs moves it left, and greater than 1500μs moves it right. The circuit uses three buttons to rotate the motor to -90, 0, and +90 degrees by changing the PWM signal sent to the motor. The PIC microcontroller code uses functions to move the motor in each direction and continuously checks the button states in a loop to call the appropriate function.

Uploaded by

RamKumar
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
0% found this document useful (0 votes)
244 views5 pages

How To Servo Motor Control Using Microcontroller PIC16F877A

This document describes how to control a servo motor using a PIC16F877A microcontroller. It explains that servo motors can be positioned by sending PWM signals of varying pulse widths. A pulse width of 1500μs positions the motor to the center, less than 1500μs moves it left, and greater than 1500μs moves it right. The circuit uses three buttons to rotate the motor to -90, 0, and +90 degrees by changing the PWM signal sent to the motor. The PIC microcontroller code uses functions to move the motor in each direction and continuously checks the button states in a loop to call the appropriate function.

Uploaded by

RamKumar
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/ 5

Home

AdvertiseHere

AboutUs

ContactUs

CircuitsGallery

Electronic Circuits and projects, DIY circuit diagrams, Robotics & Microcontroller Projects..!

Adsby Google

ACServoMotor

PIC16F877A

CircuitDiagram

ServoMotorControlusingMicrocontrollerPIC16F877A
Yaseen/March9,2014

Switches
Microswitch,waterproofswitchChinamanufacturer&exporterGotoswitchchina.com

Servomotorsarewidelyusedinroboticsandindustriesformotioncontrol.TheycanbecontrolledbyPWMsignals
wheretherequiredangleofrotationcanbelocatedbyaparticularPWMsignal.SoInthisarticlewellseeindetail
onPWMservocontrolandhowservomotorcontrolusingpic16f877aispossible.Servomotorshavean
outputshaftwhichisconnectedtoanarmandthemechanicalconnectionsareattachedwiththisarm,whichcan
rotateamaximumof180degree.Ithasthreeconnectionwires:Vpositive,Vnegativeandcontrolsignal.Signalis
normallyconnectedwithmicrocontrollerstofeedPWMsignalasrequired.Thepositionofservoarmisdetermined
byPWMsignal:
1500sforservoneutralposition.
Ifthesignalislessthan1500sthenthearmmovesbacktoaparticularangle(anticlockwise).
Ifthesignalvalueisgreaterthan1500sthenthearmmoveclockwisetoaparticularangledependingon
thesignalvalue.
Read:
HowtogeneratePWMusingPICmicrocontroller?
PWMDCmotorspeedcontrollerusingPIC16F877A
PWMof1000Swillmovethearmtozeropositionwhichistheminimumpositionand2000Swillmovethearm
tomaximum.ServomotorhasinbuiltcontrolcircuittoconvertthePWMsignaltothepositionvalue,ithasa
movablepotentiometerwhichisusedtolocatethepositionbybalancingmechanism.

Servomotorcontrolcircuit

ComponentsRequired
1.PIC16F877A
2.Crystal20MHz
3.Capacitor(33pfx2)
4.Resistor(10Kx3)
5.Servomotor
6.Pushbuttonsx3

Working
HereIusethreeswitchestorotatethearmto90degree(minimumposition),zerodegreeand+90degree.
Armrotatesthesethreepositionsbypressingtheswitches.
Theapplicationofthisinarobotistoturnthefrontwheelbypressingthebuttonsontheremote,buthere
rotationis90degreesoyouhavetominimizethisbychangingthePWMsignal.
HerewehaveusedthemikroCcompiler.
PortBisusedtoconnectservomotorandcontrollingswitch,thecontrollingswitchesareconnectedto+5V
througha10K(calledpullup)resistor.
Thecontrolsignalofaservomotorisconnectedto7thbitofportandswitchesareconnectedto0th,1stand
2ndpinofPORTB.
Threesubfunctionsareusedtomovethearmleft,straightandrightfor90,0and+90rotation.
Inmainfunction,thereisaninfiniteloopwhichcontinuouslychecksthe0,1and2ndpinsofPORTB.

Ifanyswitchgetsanegativesignalwhenpressingthebuttonthentheprogramcontrolischangedtothesub
functionfortheparticularswitchanditreturnbacktotheinfiniteloop.

ServomotorPICProgram
[cclang=C]
voidleft()
voidright()
voidstright()
inti
voidleft()
{
for(i=0i<10i++)
{
PORTB.F7=1
Delay_us(500)//500usDelay
PORTB.F7=0
delay_ms(80)//800usdelay}}
voidright()
{
for(i=0i<10i++)
{
PORTB.F7=1
Delay_us(2500)//2500usDelay
PORTB.F7=0delay_ms(80)//800msdelay
}
}
voidstright()
{
for(i=0i<10i++)
{
PORTB.F7=1
Delay_us(1500)//1msDelay
PORTB.F7=0delay_ms(80)
}
}
voidmain()
{
TRISB=0B00001111//PORTBasOutputandInputPort
while(1)
{
if(portb.f0==0)
{
right()
}
elseif(portb.f2==0)
{
left()
}
elseif(portb.f1==0)
{
stright()
}
}
}
[/cc]

Switches

Switches
Microswitch,waterproof
switchChinamanufacturer
&exporter
switchchina.com

March9,2014inMikroC,PICMicrocontroller.

Relatedposts
DigitalVoltmeterUsingPICMicrocontroller16F877AandSevenSegmentsDisplay(030V)

HowSevenSegmentDisplayMultiplexingwithPICMicrocontrollerforElectronicSign

DCMotorInterfacingWithPICMicrocontrollerUsingL293MotorDriverIC

VoltageStabilizerCircuitDiagramACVoltagewithLowVoltageAlarm

HeartbeatMonitorProjectCircuitwithTachycardiaAlarm

4thoughtsonServoMotorControlusingMicrocontrollerPIC16F877A

aliyu March13,2014at9:21am
PlsIwantknowifUPS650vaisapuresomewaveandsecondlycanIuseUPS650vaasaninvertertoworkforabout12ours
Reply

aliyu March13,2014at9:35am
PlsifmyinverterisamodifysinewavewhatcanIaddinthecircuit2makeitpuresinewave.Ihaveamodifysinewaveinverter
andIwanttoconnectit2mystandingfanhowcanIdobecauseIhavetryitthetimeandithasdamagerthefaninnercoil,sopls
istheiranythingIcanconnectattheoutput2makeitclearatoutputorinput,plsIneedyoururgentandfavorablerejoinfromyou
yaseen.
Reply

joelpalope February15,2015at1:10pm
for(i=0i<10i++)
thiscodeiserrorinmikroC
whatisthealternativeforthiscode?
Reply

NsikanUdotung

NsikanUdotung February18,2016at9:55pm
Ilikethis
Reply

LeaveaReply
Youremailaddresswillnotbepublished.Requiredfieldsaremarked*
Comment

Name*

Email*

Website

PostComment

Notifymeoffollowupcommentsbyemail.
Notifymeofnewpostsbyemail.

NewCGProgramStore
CircuitsGalleryintroducing'TheNEWCGPROGRAMSTORE',fromwhereyoucanbuyembeddedprogramcodes.Programsare100%
tested&Outputguaranteed..

VisitCG_PROGRAM_STORE...!
WeacceptCredit/DebitCard,InternetBanking&DirectBanktransfer

You might also like