Friday, 8 February 2019

Servo Motor with Raspberry Pi


Servo Motor:

There are some special types of application of electrical motor where rotation of the motor is required for just a certain angle not continuously for long period of time. For these applications, some special types of motor are required with some special arrangement which makes the motor to rotate a certain angle for a given electrical input (signal). For this purpose servo motor comes into picture.
This is normally a simple DC motor which is controlled for specific angular rotation with the help of additional servomechanism (a typical closed loop feedback control system).

Interfacing of Servo Motor with Raspberry Pi:

Here we will control servo motor from terminal. In this case we will use linear equation formula. In my servo motor I am getting full left at Duty Cycle 2 and full right at Duty Cycle 12. You can test your servo by giving the command
pwm.ChangeDutyCycle(Duty Cycle)
Now two points we get and that is (0,2) and (180,12)
So slope of the line will be
m=(y2-y1)/(x2-x1)=(12-2)/180-0)=10/180 = 1/18
Now using the point slope formula, equation of the line will be:
y-y1=m(x-x1)
y-2=1/18*(x-0)
y = 1/18*x + 2
This will become:
DutyCycle = 1/18* (DesiredAngle) + 2


Project Code:

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
servo = 11
GPIO.setup(servo, GPIO.OUT)
pwm=GPIO.PWM(servo, 50)
pwm.start(7)
for i in range(0,20):
        desiredPosition=input("Your new servo position? 0-180 ")
        DC=1./18.*(desiredPosition)+2
        pwm.ChangeDutyCycle(DC)
pwm.stop()
GPIO.cleanup()



0 comments:

Post a Comment

if you have any doubt please let me know