fbpx

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.

Circuit

Code

 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
 
Servo_pin=23
GPIO.setup(Servo_pin, GPIO.OUT)
p = GPIO.PWM(Servo_pin, 50)
p.start(7.5)

try:
while True:
p.ChangeDutyCycle(7.5)      //turn towards 90 degree
time.sleep(1) 
p.ChangeDutyCycle(2.5)      // turn towards 0 degree
time.sleep(1) 
p.ChangeDutyCycle(12.5)    // turn towards 180 degree
time.sleep(1) 
p.stop()
GPIO.cleanup()

 

Leave a Reply

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