Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save iotguider/0ae0a0e746892df38c94cec3c2794b8d to your computer and use it in GitHub Desktop.
Save iotguider/0ae0a0e746892df38c94cec3c2794b8d to your computer and use it in GitHub Desktop.
Code for interfacing servo motor with Raspberry Pi
import RPi.GPIO as GPIO # calling for header file for GPIO’s of PI
import time # calling for time to provide delays in program
GPIO.setmode (GPIO.BCM) # programming the GPIO by BCM pin numbers.
GPIO.setup(17,GPIO.OUT) # initialize GPIO17 as an output
servo = GPIO.PWM(17,50) # GPIO17 as PWM output, with 50Hz frequency
servo.start(0) # generate PWM signal with 7.5% duty cycle
servo.ChangeDutyCycle(7.5) # change duty cycle for getting the servo position to 90º
time.sleep(1) # sleep for 1 second
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment