connect@howdiyworld.com
|

Servo Motor

BLOCK DIAGRAM

Procedure

  1. Servo motor
  2. Connection
  3. Program
  4. Output

Procedure

Servo Motor

A servo motor is an electrical device which can push or rotate an object with great precision. If you want to rotate and object at some specific angles or distance, then you use servo motor. It is just made up of simple motor which run through servo mechanism.

Connection

  • Connect Servo Motor’s VCC to 2nd pin
  • Connect Servo Motor’s Ground (GND) to 6th pin
  • Connect Servo Motor’s PWM to 7th

Program

import RPi.GPIO as GPIO

import time

GPIO.setmode(GPIO.BOARD)

GPIO.setup(7, GPIO.OUT)

p = GPIO.PWM(7, 50)

def get_input(a):

if a=='0':

p.start(2.5)

p.ChangeDutyCycle(2.5) # turn towards 0 degree

time.sleep(1) # sleep 1 second

print(“0 deg")

if a=='90':

p.start(2.5)

p.ChangeDutyCycle(7.5) # turn towards 90 degree

time.sleep(1) # sleep 1 second

print(“90 deg")

if a=='180':

p.ChangeDutyCycle(12.5) # turn towards 180 degree

time.sleep(1) # sleep 1 second

print(“180 Deg")

p.stop()

GPIO.cleanup()

Output

Here if you press 45 Deg Button the Servo motor will rotate direction of 45 degree, if you press 90 Deg Button the Servo motor will rotate direction of 90 degree, if you press 180 Deg Button the Servo motor will rotate direction of 180 degree.

Social media & sharing icons powered by UltimatelySocial
Facebook
Twitter
YouTube
LinkedIn
Instagram