A servo allows precise control of the angular position of its shaft. Standard servos accept 4.6 to 6 volts.
|Positive power lead
|Negative power lead
This needs to be a
pulse width modulation (PWM) square wave. The square wave needs to be 50 herts (so a pulse of every 0.2 seconds) The angle of the servo is controlled by the length of the positive pulse (duty cycle) The longer the pulse/period of the wave/duty cycle the larger the angle the servo will turn to and try hold itself at.
These values vary by servo but for the small cheap SG-90’s the degrees can be calculated as:
2% duty cycle = 0 degrees
Translating this to python code using the RPi.GPIO library
import RPi.GPIO as GPIO