Hello and welcome to this short video that will show you the easiest way to control a small servo using a Raspberry Pi and the GpioZero Python library.
Cheap, small servos can often be found by searching for "9g" or "SG90" and are made by various companies.
The spec tends to be similar and they work well with the default values of GpioZero.
Servos use a number of different colour codes for their 3 wires.
Mine uses Red for Power, Orange for Data and Brown for ground.
You can connect power to Pin 2 for 5V, ground to Pin 9 and data to Pin 11 which is GPIO17.
You could use other GPIO pins, just remember to update the GPIO number in your python code.
Here is example Python script 1. It creates a servo object called "myservo" and then calls the min, mid and max functions to rotate the servo arm.
There is a 1 second delay between each movement.
In example script 2 the "myservo" object is created with modified pulse-width values. This extends the total range of movement.
I increased the correction factor from 0 in steps of 0.05 to find the best value for my servo.
Example script 3 uses the "value" function to set the servo position. A "for" loop increments this value from -1 to +1 in 20 steps with another "for" loop doing the same but in reverse.
There are more details in the video description with links to the example scripts that you can download directly to your Pi.
A link to my website will take you to a page with even more detail.
Thank you for watching and don't forget to "Like" and "Subscribe"!
