How To Servo Motor Control Using Microcontroller PIC16F877A
How To Servo Motor Control Using Microcontroller PIC16F877A
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