profbit
Posts: 45
Joined: Fri May 05, 2017 4:34 am

servo motor as lock

Sun Jan 21, 2018 4:35 am

Hi i have a problem with my servo motor. I’ve already googled but still doesn’t work. All I want to do is rotate my servo for 90 degrees clockwise and another code to rotate it 90 degrees counterclockwise. My gpio pin is at 36. thanks for the help

User avatar
B.Goode
Posts: 9270
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: servo motor as lock

Sun Jan 21, 2018 7:42 am

The gpiozero Python library module has built-in support for common hobbyist servos.

http://gpiozero.readthedocs.io/en/stabl ... ervo#servo

pcmanbob
Posts: 7943
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: servo motor as lock

Sun Jan 21, 2018 12:34 pm

This is a simple python program I wrote for some one that drives a servo from one end of its travel to the other and back again .

Code: Select all

import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(36, GPIO.OUT)
p = GPIO.PWM(36, 100)
p.start(5)
time.sleep(2)

for angle in range (25, 180):

    duty = float(angle) / 10 + 2.5
    print duty

    p.ChangeDutyCycle(duty)
    time.sleep(0.015)
    
for angle in range (180, 25, -1):

    duty = float(angle) / 10 + 2.5
    print duty

    p.ChangeDutyCycle(duty)
    time.sleep(0.015)
from this you should be able to workout how to make you servo do what you want.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Return to “Beginners”