fbpx

Interface Servo Motor With PIC

Description

Servo motor uses servo mechanism. It is a closed-loop mechanism that uses position feedback to control the precise angular position of the shaft.

  • Some special types of applications of the electrical motor where rotation of the motor is required for just at a certain angle not continuously for a long period of time.
  • The motor is required with some special arrangement which makes the motor to rotate at a certain angle for a given electrical input (signal).
  • Servo motors have three wires.
  • Two of them are red and black which is used to give power to the motor.
  • The third wire is used to provide a control signal for an angular position.
  • It uses Pulse Width Modulated(PWM) waves as control signals.
  • The angle of rotation is determined by the width of the pulse at the control pin.

Hardware Required

  • Servo Motor.
  • PIC16f877a MicroController.

Circuit

Virtual Circuit

Code

 void Delay(unsigned int ms);
 void Delay_servo(unsigned int us);
 void main()
 {
 TRISB=0X00;
 while(1)
 {
 PORTB=0X01;
 Delay_servo(50);
 PORTB=0X00;
 Delay(1000);
 PORTB=0X01;
 Delay_servo(82);
 PORTB=0X00;
 Delay(1000);
 PORTB=0X01;
 Delay_servo(110);
 PORTB=0X00;
 Delay(1000);
 }
 }
 void Delay(unsigned int ms)
 {
 unsigned long int us = ms*1000;
 while(us--)
 {
 
 }
 }
 void Delay_servo(unsigned int us)
 {
 while(us--)
 {
 
 }
 } 

Leave a Reply

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