Servo Motor

  • Some special types of applications of the electrical motor where rotation of the motor is required for just a certain angle not continuously for 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 motor uses a servo mechanism.
  • It is a closed-loop mechanism that uses position feedback to control the precise angular position of the shaft.
  • 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

  • Raspberry pi.
  • Servo motor.
  • Connecting wires.



 import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM) //BCM is broadcom which specifies the actual pin number considered by broadcom chip 
GPIO.setwarnings(False)  //Ignore warnings
GPIO.setup(Servo_pin, GPIO.OUT)
p = GPIO.PWM(Servo_pin, 50)

while True:
p.ChangeDutyCycle(7.5)      //turn towards 90 degree
p.ChangeDutyCycle(2.5)      // turn towards 0 degree
p.ChangeDutyCycle(12.5)    // turn towards 180 degree


Leave a Reply

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