Skip to content

Instantly share code, notes, and snippets.

@chilin0525
Created May 15, 2021 10:47
Show Gist options
  • Save chilin0525/3bf675a2bff07ba50e8769255157bc80 to your computer and use it in GitHub Desktop.
Save chilin0525/3bf675a2bff07ba50e8769255157bc80 to your computer and use it in GitHub Desktop.
sg90
import RPi.GPIO as GPIO
import time
servoPIN = 2
GPIO.setmode(GPIO.BCM)
GPIO.setup(servoPIN, GPIO.OUT)
pwm = GPIO.PWM(servoPIN, 50) # GPIO 17 for PWM with 50Hz
pwm.start(0) # Initialization
try:
pwm.ChangeDutyCycle(5) # left -90 deg position
time.sleep(1)
pwm.ChangeDutyCycle(7.5) # neutral position
time.sleep(1)
pwm.ChangeDutyCycle(10) # right +90 deg position
time.sleep(1)
except KeyboardInterrupt:
p.stop()
GPIO.cleanup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment