tonilopezmr / tonilopezmr.github.io

My web portfolio.
https://tonilopezmr-github-io.vercel.app
Other
4 stars 1 forks source link

Move servo motor #20

Open tonilopezmr opened 6 years ago

tonilopezmr commented 6 years ago

References

SG90 9 g Micro Servo documentation Video explanation

Code

This code move to neutral position (2.5) to 90º (6.25) if you want to move 180º then is (12.5).

import RPi.GPIO as GPIO
import time

GPIO_PIN = 8

GPIO.setmode(GPIO.BOARD)
GPIO.setup(GPIO_PIN, GPIO.OUT)

p = GPIO.PWM(GPIO_PIN, 50)
p.start(2.5)

p.ChangeDutyCycle(2.5)
time.sleep(1)
p.ChangeDutyCycle(7.25)
time.sleep(1)
p.ChangeDutyCycle(2.5)
time.sleep(1)

p.stop()
GPIO.cleanup()